[FFmpeg-cvslog] avformat/flvdec: Fix regression loosing streams

Michael Niedermayer git at videolan.org
Fri Oct 28 13:32:30 EEST 2016


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Fri Oct 28 12:18:35 2016 +0200| [077939626eeaa0c1364065414c18ab9b3a072281] | committer: Michael Niedermayer

avformat/flvdec: Fix regression loosing streams

Fixes: unknown_video.flv

Found-by: Thierry Foucu <tfoucu at google.com>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=077939626eeaa0c1364065414c18ab9b3a072281
---

 libavformat/flvdec.c | 12 +++++++++++-
 libavformat/utils.c  |  2 ++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index 68ab680..e53c345 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -66,6 +66,7 @@ typedef struct FLVContext {
     int keyframe_count;
     int64_t *keyframe_times;
     int64_t *keyframe_filepositions;
+    int missing_streams;
 } FLVContext;
 
 static int probe(AVProbeData *p, int live)
@@ -137,6 +138,11 @@ static AVStream *create_stream(AVFormatContext *s, int codec_type)
                            && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
                            && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE))
         s->ctx_flags &= ~AVFMTCTX_NOHEADER;
+    if (codec_type == AVMEDIA_TYPE_AUDIO)
+        flv->missing_streams &= ~FLV_HEADER_FLAG_HASAUDIO;
+    if (codec_type == AVMEDIA_TYPE_VIDEO)
+        flv->missing_streams &= ~FLV_HEADER_FLAG_HASVIDEO;
+
 
     avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
     flv->last_keyframe_stream_index = s->nb_streams - 1;
@@ -674,11 +680,14 @@ static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
 
 static int flv_read_header(AVFormatContext *s)
 {
+    int flags;
     FLVContext *flv = s->priv_data;
     int offset;
 
     avio_skip(s->pb, 4);
-    avio_r8(s->pb); // flags
+    flags = avio_r8(s->pb);
+
+    flv->missing_streams = flags & (FLV_HEADER_FLAG_HASVIDEO | FLV_HEADER_FLAG_HASAUDIO);
 
     s->ctx_flags |= AVFMTCTX_NOHEADER;
 
@@ -1216,6 +1225,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_BOOL, { .i64 = 0 }, 0, 1, VD },
+    { "missing_streams", "", OFFSET(missing_streams), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0xFF, VD | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
     { NULL }
 };
 
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 70dbfa1..31572f3 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3349,6 +3349,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
     int64_t max_subtitle_analyze_duration;
     int64_t probesize = ic->probesize;
     int eof_reached = 0;
+    int64_t *missing_streams = av_opt_ptr(ic->iformat->priv_class, ic->priv_data, "missing_streams");
 
     flush_codecs = probesize > 0;
 
@@ -3502,6 +3503,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
                 break;
         }
         analyzed_all_streams = 0;
+        if (!missing_streams || !*missing_streams)
         if (i == ic->nb_streams) {
             analyzed_all_streams = 1;
             /* NOTE: If the format has no header, then we need to read some



More information about the ffmpeg-cvslog mailing list