From 4888a4d5fc9a7de1eafb7241a42b67f216f6aee9 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 7 Nov 2020 17:07:47 +0100 Subject: [PATCH] I commit this only to revert easily to something that worked with VP8 --- stream/webrtc/ingest.go | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/stream/webrtc/ingest.go b/stream/webrtc/ingest.go index 480f707..4779ac5 100644 --- a/stream/webrtc/ingest.go +++ b/stream/webrtc/ingest.go @@ -5,7 +5,7 @@ import ( "bufio" "fmt" "github.com/pion/webrtc/v3/pkg/media" - "github.com/pion/webrtc/v3/pkg/media/h264reader" + "github.com/pion/webrtc/v3/pkg/media/ivfreader" "io" "log" "math/rand" @@ -34,8 +34,8 @@ func ingest(name string, q *messaging.Quality) { return } - f, _ := os.Open("CoffeeRun.h264") - h264, err := h264reader.NewReader(f) + f, _ := os.Open("output.ivf") + h264, _, err := ivfreader.NewWith(f) // Start ffmpag to convert videoInput to audio UDP ffmpeg, err := startFFmpeg(videoInput, firstPort) @@ -47,7 +47,7 @@ func ingest(name string, q *messaging.Quality) { // Receive video go func() { for { - nal, h264Err := h264.NextNAL() + nal, _, h264Err := h264.ParseNextFrame() if h264Err == io.EOF { fmt.Printf("All video frames parsed and sent") return @@ -58,25 +58,13 @@ func ingest(name string, q *messaging.Quality) { } time.Sleep(time.Millisecond * 33) - nal.Data = append([]byte{0x00, 0x00, 0x00, 0x01}, nal.Data...) - if videoTracks[name] == nil { videoTracks[name] = make([]*webrtc.Track, 0) } - var spsAndPpsCache []byte - if nal.UnitType == h264reader.NalUnitTypeSPS || nal.UnitType == h264reader.NalUnitTypePPS { - spsAndPpsCache = append(spsAndPpsCache, nal.Data...) - continue - } else if nal.UnitType == h264reader.NalUnitTypeCodedSliceIdr { - nal.Data = append(spsAndPpsCache, nal.Data...) - spsAndPpsCache = []byte{} - } - log.Println(nal.PictureOrderCount) - for _, videoTrack := range videoTracks[name] { - if h264Err = videoTrack.WriteSample(media.Sample{Data: nal.Data, Samples: 90000}); h264Err != nil { - panic(h264Err) + if ivfErr := videoTrack.WriteSample(media.Sample{Data: nal, Samples: 90000}); ivfErr != nil { + panic(ivfErr) } } }