From 10860e4e48ad392dc4d4d66fa856dd49943ac94e Mon Sep 17 00:00:00 2001 From: saxon Date: Fri, 11 Jan 2019 17:20:56 +1030 Subject: [PATCH] lex: modified h264 lexer to consider nal type 6 packets, i.e. sei packets, which seem important fro repeating single frames --- rtmp/rtmp_test.go | 26 +++++++++++++------------- stream/lex/lex.go | 3 ++- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/rtmp/rtmp_test.go b/rtmp/rtmp_test.go index 01dad10f..094457ac 100644 --- a/rtmp/rtmp_test.go +++ b/rtmp/rtmp_test.go @@ -30,10 +30,10 @@ LICENSE package rtmp import ( + "bytes" "fmt" "io/ioutil" "os" - "path/filepath" "runtime" "testing" "time" @@ -171,24 +171,24 @@ func TestFromFrame(t *testing.T) { t.Errorf("Session.Open failed with error: %v", err) } - b, err := ioutil.ReadFile(filepath.Join(testDataDir, "AusOcean_logo_1080p.h264")) + // TODO: don't hard code this path + b, err := ioutil.ReadFile("/home/saxon/Desktop/singleframe.h264") if err != nil { t.Errorf("ReadFile failed with error: %v", err) } - // Pass RTMP session, true for audio, true for video, and 25 FPS - // ToDo: fix this. Although we can encode the file and YouTube - // doesn't complain, YouTube doesn't play it (even when we - // send 1 minute's worth). - flvEncoder := flv.NewEncoder(s, true, true, 25) - for i := 0; i < 25; i++ { - err := flvEncoder.Encode(b) - if err != nil { - t.Errorf("Encoding failed with error: %v", err) - } - time.Sleep(time.Millisecond / 25) // rate limit to 1/25s + const noOfFrames = 1000 + videoData := make([]byte, 0, noOfFrames*len(b)) + for i := 0; i < noOfFrames; i++ { + videoData = append(videoData, b...) } + const frameRate = 25 + flvEncoder := flv.NewEncoder(s, true, true, frameRate) + err = lex.H264(flvEncoder, bytes.NewReader(videoData), time.Second/time.Duration(frameRate)) + if err != nil { + t.Errorf("Lexing failed with error: %v", err) + } err = s.Close() if err != nil { t.Errorf("Session.Close failed with error: %v", err) diff --git a/stream/lex/lex.go b/stream/lex/lex.go index 115915c3..e48d72d1 100644 --- a/stream/lex/lex.go +++ b/stream/lex/lex.go @@ -120,9 +120,10 @@ outer: nonIdrPic = 1 idrPic = 5 paramSet = 8 + sei = 6 ) switch nalTyp := b & 0x1f; nalTyp { - case nonIdrPic, idrPic, paramSet: + case nonIdrPic, idrPic, paramSet, sei: writeOut = true } }