lex: modified h264 lexer to consider nal type 6 packets, i.e. sei packets, which seem important fro repeating single frames

This commit is contained in:
saxon 2019-01-11 17:20:56 +10:30
parent 28d23ad200
commit 10860e4e48
2 changed files with 15 additions and 14 deletions

View File

@ -30,10 +30,10 @@ LICENSE
package rtmp package rtmp
import ( import (
"bytes"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath"
"runtime" "runtime"
"testing" "testing"
"time" "time"
@ -171,24 +171,24 @@ func TestFromFrame(t *testing.T) {
t.Errorf("Session.Open failed with error: %v", err) 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 { if err != nil {
t.Errorf("ReadFile failed with error: %v", err) t.Errorf("ReadFile failed with error: %v", err)
} }
// Pass RTMP session, true for audio, true for video, and 25 FPS const noOfFrames = 1000
// ToDo: fix this. Although we can encode the file and YouTube videoData := make([]byte, 0, noOfFrames*len(b))
// doesn't complain, YouTube doesn't play it (even when we for i := 0; i < noOfFrames; i++ {
// send 1 minute's worth). videoData = append(videoData, b...)
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 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() err = s.Close()
if err != nil { if err != nil {
t.Errorf("Session.Close failed with error: %v", err) t.Errorf("Session.Close failed with error: %v", err)

View File

@ -120,9 +120,10 @@ outer:
nonIdrPic = 1 nonIdrPic = 1
idrPic = 5 idrPic = 5
paramSet = 8 paramSet = 8
sei = 6
) )
switch nalTyp := b & 0x1f; nalTyp { switch nalTyp := b & 0x1f; nalTyp {
case nonIdrPic, idrPic, paramSet: case nonIdrPic, idrPic, paramSet, sei:
writeOut = true writeOut = true
} }
} }