From 5a21ef83d279e67455de3096f22edb4ad288e035 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Fri, 18 Aug 2023 14:21:31 +0500 Subject: [PATCH] Also write tag size at end --- rtmp/flv/writer.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/rtmp/flv/writer.go b/rtmp/flv/writer.go index e70d842..492f601 100644 --- a/rtmp/flv/writer.go +++ b/rtmp/flv/writer.go @@ -35,13 +35,21 @@ func (writer *FLVWriter) WriteMetadataTag(data *[]byte) (err error) { binary.BigEndian.PutUint32(uint24_buf, uint32(len((*data)[16:]))) copy(tag_header[1:4], uint24_buf[1:]) - _, err = writer.w.Write(tag_header) - if err == nil { - _, err = writer.w.Write((*data)[16:]) + if _, err = writer.w.Write(tag_header); err != nil { + return } - return + if _, err = writer.w.Write((*data)[16:]); err != nil { + return + } + + + tag_len_buf := make([]byte, 4) + binary.BigEndian.PutUint32(tag_len_buf, uint32(len((*data)[16:]) + 11)) + _, err = writer.w.Write(tag_len_buf) + return } + func (writer *FLVWriter) write_flv_header() (err error) { header := make([]byte, 13) copy(header[:3], "FLV")