revid,stream/flv: add back initial header write

This commit is contained in:
Dan Kortschak 2019-01-11 13:47:17 +10:30
parent 9eeefef8c7
commit 7f07c4cb20
3 changed files with 19 additions and 5 deletions

View File

@ -289,7 +289,10 @@ func (r *Revid) reset(config Config) error {
r.encoder = mts.NewEncoder(&r.packer, float64(r.config.FrameRate))
case Flv:
r.config.Logger.Log(logger.Info, pkg+"using FLV packetisation")
r.encoder = flv.NewEncoder(&r.packer, true, true, int(r.config.FrameRate))
r.encoder, err = flv.NewEncoder(&r.packer, true, true, int(r.config.FrameRate))
if err != nil {
r.config.Logger.Log(logger.Fatal, pkg+"failed to open FLV encoder", err.Error())
}
}
return nil

View File

@ -180,7 +180,10 @@ func TestFromFrame(t *testing.T) {
// 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)
flvEncoder, err := flv.NewEncoder(s, true, true, 25)
if err != nil {
t.Fatalf("failed to create encoder: %v", err)
}
for i := 0; i < 25; i++ {
err := flvEncoder.Encode(b)
if err != nil {
@ -219,7 +222,10 @@ func TestFromFile(t *testing.T) {
defer f.Close()
// Pass RTMP session, true for audio, true for video, and 25 FPS
flvEncoder := flv.NewEncoder(s, true, true, 25)
flvEncoder, err := flv.NewEncoder(s, true, true, 25)
if err != nil {
t.Fatalf("failed to create encoder: %v", err)
}
err = lex.H264(flvEncoder, f, time.Second/time.Duration(25))
if err != nil {
t.Errorf("Lexing and encoding failed with error: %v", err)

View File

@ -66,13 +66,18 @@ type Encoder struct {
}
// NewEncoder retuns a new FLV encoder.
func NewEncoder(dst io.Writer, audio, video bool, fps int) *Encoder {
return &Encoder{
func NewEncoder(dst io.Writer, audio, video bool, fps int) (*Encoder, error) {
e := Encoder{
dst: dst,
fps: fps,
audio: audio,
video: video,
}
_, err := dst.Write(e.HeaderBytes())
if err != nil {
return nil, err
}
return &e, err
}
// HeaderBytes returns the a