From 9e7e1ec0b895132e5696f4cc4fb99ab7514d1c0d Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 27 Oct 2020 19:32:23 +0100 Subject: [PATCH] Stream with the H264 codec to have no CPU usage --- stream/webrtc/ingest.go | 12 ++++++------ stream/webrtc/webrtc.go | 2 +- stream/webrtc/webrtc_test.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/stream/webrtc/ingest.go b/stream/webrtc/ingest.go index 25d7c11..0c5ecd6 100644 --- a/stream/webrtc/ingest.go +++ b/stream/webrtc/ingest.go @@ -18,12 +18,12 @@ func ingest(name string, q *messaging.Quality) { q.Register(videoInput) // Open a UDP Listener for RTP Packets on port 5004 - videoListener, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5004}) + audioListener, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5004}) if err != nil { log.Printf("Faited to open UDP listener %s", err) return } - audioListener, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5005}) + videoListener, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5005}) if err != nil { log.Printf("Faited to open UDP listener %s", err) return @@ -117,11 +117,11 @@ func ingest(name string, q *messaging.Quality) { func startFFmpeg(in <-chan []byte) (ffmpeg *exec.Cmd, err error) { ffmpegArgs := []string{"-hide_banner", "-loglevel", "error", "-i", "pipe:0", - "-an", "-vcodec", "libvpx", "-crf", "10", "-cpu-used", "5", "-b:v", "6000k", "-maxrate", "8000k", "-bufsize", "12000k", // TODO Change bitrate when changing quality - "-qmin", "10", "-qmax", "42", "-threads", "4", "-deadline", "1", "-error-resilient", "1", - "-auto-alt-ref", "1", + // Audio + "-vn", "-c:a", "libopus", "-b:a", "160k", "-f", "rtp", "rtp://127.0.0.1:5004", - "-vn", "-acodec", "libopus", "-cpu-used", "5", "-deadline", "1", "-qmin", "10", "-qmax", "42", "-error-resilient", "1", "-auto-alt-ref", "1", + // Source + "-an", "-c:v", "copy", "-b:v", "3000k", "-maxrate", "5000k", "-bufsize", "5000k", "-f", "rtp", "rtp://127.0.0.1:5005"} ffmpeg = exec.Command("ffmpeg", ffmpegArgs...) diff --git a/stream/webrtc/webrtc.go b/stream/webrtc/webrtc.go index a101799..c4cb7f6 100644 --- a/stream/webrtc/webrtc.go +++ b/stream/webrtc/webrtc.go @@ -75,7 +75,7 @@ func newPeerHandler(name string, localSdpChan chan webrtc.SessionDescription, re } // Create video track - codec, payloadType := getPayloadType(mediaEngine, webrtc.RTPCodecTypeVideo, "VP8") + codec, payloadType := getPayloadType(mediaEngine, webrtc.RTPCodecTypeVideo, "H264") videoTrack, err := webrtc.NewTrack(payloadType, rand.Uint32(), "video", "pion", codec) if err != nil { log.Println("Failed to create new video track", err) diff --git a/stream/webrtc/webrtc_test.go b/stream/webrtc/webrtc_test.go index 0277bb3..c23cce6 100644 --- a/stream/webrtc/webrtc_test.go +++ b/stream/webrtc/webrtc_test.go @@ -26,7 +26,7 @@ func TestServe(t *testing.T) { peerConnection, _ := api.NewPeerConnection(webrtc.Configuration{}) // Create video track - codec, payloadType := getPayloadType(mediaEngine, webrtc.RTPCodecTypeVideo, "VP8") + codec, payloadType := getPayloadType(mediaEngine, webrtc.RTPCodecTypeVideo, "H264") videoTrack, err := webrtc.NewTrack(payloadType, rand.Uint32(), "video", "pion", codec) if err != nil { t.Error("Failed to create new video track", err)