From cc40226111cf93d2533ba13598171ad105ef670a Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 7 Nov 2020 22:11:21 +0100 Subject: [PATCH] Use stdout instead of Unix socket --- stream/webrtc/ingest.go | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/stream/webrtc/ingest.go b/stream/webrtc/ingest.go index b0f828f..ff85f90 100644 --- a/stream/webrtc/ingest.go +++ b/stream/webrtc/ingest.go @@ -31,14 +31,8 @@ func ingest(name string, q *messaging.Quality) { return } - videoListener, err := net.ListenUnix("unix", &net.UnixAddr{Name: "/tmp/video.socket", Net: "unix"}) - if err != nil { - log.Printf("Faited to open UNIX socket %s", err) - return - } - // Start ffmpag to convert videoInput to audio UDP - ffmpeg, err := startFFmpeg(videoInput, firstPort) + ffmpeg, ffmpegOut, err := startFFmpeg(videoInput, firstPort) if err != nil { log.Printf("Error while starting ffmpeg: %s", err) return @@ -46,8 +40,7 @@ func ingest(name string, q *messaging.Quality) { // Receive video go func() { - videoSocket, _ := videoListener.AcceptUnix() - h264, _ := h264reader.NewReader(videoSocket) + h264, _ := h264reader.NewReader(*ffmpegOut) var spsAndPpsCache []byte for { @@ -127,11 +120,11 @@ func ingest(name string, q *messaging.Quality) { q.Unregister(videoInput) } -func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, err error) { +func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, stdout *io.ReadCloser, err error) { ffmpegArgs := []string{"-hide_banner", "-loglevel", "error", "-i", "pipe:0", // Vidéo - "-an", "-c:v", "copy", - "-f", "h264", "unix:///tmp/video.socket", + "-an", "-c:v", "copy", "-bsf", "h264_mp4toannexb", + "-f", "h264", "pipe:1", // Audio "-vn", "-c:a", "libopus", "-b:a", "96k", "-f", "rtp", fmt.Sprintf("rtp://127.0.0.1:%d", listeningPort)} @@ -140,7 +133,7 @@ func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, err err // Handle errors output errOutput, err := ffmpeg.StderrPipe() if err != nil { - return nil, err + return nil, nil, err } go func() { scanner := bufio.NewScanner(errOutput) @@ -152,7 +145,7 @@ func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, err err // Handle stream input input, err := ffmpeg.StdinPipe() if err != nil { - return nil, err + return nil, nil, err } go func() { for data := range in { @@ -165,7 +158,12 @@ func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, err err ffmpeg.Process.Kill() }() + output, err := ffmpeg.StdoutPipe() + if err != nil { + return nil, nil, err + } + // Start process err = ffmpeg.Start() - return ffmpeg, err + return ffmpeg, &output, err }