From 7f07c4cb201fc4670e7d258a33d0fbd0f92cda57 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Fri, 11 Jan 2019 13:47:17 +1030 Subject: [PATCH] revid,stream/flv: add back initial header write --- revid/revid.go | 5 ++++- rtmp/rtmp_test.go | 10 ++++++++-- stream/flv/encoder.go | 9 +++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/revid/revid.go b/revid/revid.go index b9051a12..409ba702 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -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 diff --git a/rtmp/rtmp_test.go b/rtmp/rtmp_test.go index 01dad10f..aeb86263 100644 --- a/rtmp/rtmp_test.go +++ b/rtmp/rtmp_test.go @@ -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) diff --git a/stream/flv/encoder.go b/stream/flv/encoder.go index cb663fe6..f527e864 100644 --- a/stream/flv/encoder.go +++ b/stream/flv/encoder.go @@ -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