- package main
- import (
- "fmt"
- "io"
- "io/ioutil"
- "log"
- "os/exec"
- )
- func tsProducer(writer *io.PipeWriter) {
- //将本地的ts文件 写入 writer
- for i:=0; i<21;i++ {
- tsName := fmt.Sprintf("sofia.pts.mp4-%05d.ts", i)
- content, err := ioutil.ReadFile(tsName)
- log.Print("ts produce loop:", tsName)
- if err != nil {
- log.Fatal(err)
- }
-
- n , err:= writer.Write(content)
- if err != nil {
- log.Print("write to pipe failed:", err.Error())
- }
- log.Printf("write to pipe content len:%d, success\n", n)
- }
- }
- func main() {
- rp, wp := io.Pipe()
- go tsProducer(wp)
- for {
- log.Print("main loop")
- cmd := exec.Command("ffmpeg", "-re", "-i", "pipe:0", "-vcodec", "copy", "-acodec", "copy", "-f", "flv", "rtmp://127.0.0.1/live/pipe")
- cmd.Stdin = rp
-
- log.Print("cmd run")
- err := cmd.Run()
- log.Printf("Command finished with error: %v", err)
- }
- }
12-26 12:44