From bdd67a5bd2d3fcf9b7b3d953c2cb721d4f8ee839 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 7 Nov 2020 21:45:18 +0100 Subject: [PATCH] Use input stream instead of sample video --- stream/webrtc/ingest.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/stream/webrtc/ingest.go b/stream/webrtc/ingest.go index cac1a78..b0f828f 100644 --- a/stream/webrtc/ingest.go +++ b/stream/webrtc/ingest.go @@ -4,19 +4,16 @@ package webrtc import ( "bufio" "fmt" - "io" - "log" - "math/rand" - "net" - "os" - "os/exec" - "time" - "github.com/pion/rtp" "github.com/pion/webrtc/v3" "github.com/pion/webrtc/v3/pkg/media" "github.com/pion/webrtc/v3/pkg/media/h264reader" "gitlab.crans.org/nounous/ghostream/messaging" + "io" + "log" + "math/rand" + "net" + "os/exec" ) func ingest(name string, q *messaging.Quality) { @@ -34,8 +31,11 @@ func ingest(name string, q *messaging.Quality) { return } - f, _ := os.Open("CoffeeRun.h264") - h264, err := h264reader.NewReader(f) + 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) @@ -46,7 +46,10 @@ func ingest(name string, q *messaging.Quality) { // Receive video go func() { + videoSocket, _ := videoListener.AcceptUnix() + h264, _ := h264reader.NewReader(videoSocket) var spsAndPpsCache []byte + for { nal, h264Err := h264.NextNAL() if h264Err == io.EOF { @@ -58,8 +61,6 @@ func ingest(name string, q *messaging.Quality) { break } - time.Sleep(time.Second / 60) - if videoTracks[name] == nil { videoTracks[name] = make([]*webrtc.Track, 0) } @@ -128,6 +129,9 @@ func ingest(name string, q *messaging.Quality) { func startFFmpeg(in <-chan []byte, listeningPort int) (ffmpeg *exec.Cmd, err error) { ffmpegArgs := []string{"-hide_banner", "-loglevel", "error", "-i", "pipe:0", + // Vidéo + "-an", "-c:v", "copy", + "-f", "h264", "unix:///tmp/video.socket", // Audio "-vn", "-c:a", "libopus", "-b:a", "96k", "-f", "rtp", fmt.Sprintf("rtp://127.0.0.1:%d", listeningPort)}