[FFmpeg-devel] [PATCH 2/2] avformat/flvdec: Add flv_trustheader option

Michael Niedermayer michaelni at gmx.at
Sat Jan 3 23:35:26 CET 2015


This allows the 1 byte header to be ignored
Fixes creation of an empty audio stream

Found-by: cousin_luigi
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavformat/flvdec.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index 572268f..faf7885 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -42,6 +42,7 @@
 typedef struct {
     const AVClass *class; ///< Class for private options.
     int trust_metadata;   ///< configure streams according onMetaData
+    int trust_header;
     int wrong_dts;        ///< wrong dts due to negative cts
     uint8_t *new_extradata[FLV_STREAM_TYPE_NB];
     int new_extradata_size[FLV_STREAM_TYPE_NB];
@@ -597,6 +598,7 @@ static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
 
 static int flv_read_header(AVFormatContext *s)
 {
+    FLVContext *flv = s->priv_data;
     int offset, flags;
 
     avio_skip(s->pb, 4);
@@ -604,10 +606,10 @@ static int flv_read_header(AVFormatContext *s)
 
     s->ctx_flags |= AVFMTCTX_NOHEADER;
 
-    if (flags & FLV_HEADER_FLAG_HASVIDEO)
+    if (flv->trust_header && (flags & FLV_HEADER_FLAG_HASVIDEO))
         if (!create_stream(s, AVMEDIA_TYPE_VIDEO))
             return AVERROR(ENOMEM);
-    if (flags & FLV_HEADER_FLAG_HASAUDIO)
+    if (flv->trust_header && (flags & FLV_HEADER_FLAG_HASAUDIO))
         if (!create_stream(s, AVMEDIA_TYPE_AUDIO))
             return AVERROR(ENOMEM);
     // Flag doesn't indicate whether or not there is script-data present. Must
@@ -1063,6 +1065,7 @@ static int flv_read_seek(AVFormatContext *s, int stream_index,
 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
 static const AVOption options[] = {
     { "flv_metadata", "Allocate streams according to the onMetaData array", OFFSET(trust_metadata), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VD },
+    { "flv_trustheader", "Ignore 1byte header indicating the existence of A/V streams", OFFSET(trust_header), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VD },
     { NULL }
 };
 
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list