[FFmpeg-devel] [PATCH] flvdec: Honor the "flv_metadata" option for the "datastream" metadata field

Martin Storsjö martin at martin.st
Fri Feb 9 13:04:43 EET 2024


By default the option "flv_metadata" (internally using the field
name "trust_metadata") is set to 0, meaning that we don't allocate
streams based on information in the metadata, only based on
actual streams we encounter. However the "datastream" metadata field
still would allocate a subtitle stream.

When muxing, the "datastream" field is added if either a data stream
or subtitle stream is present - but the same metadata field is used
to preemtively create a subtitle stream only. Thus, if the field
was added due to a data stream, not a subtitle stream, the demuxer
would create a stream which won't get any actual packets.

If there was such an extra, empty subtitle stream, running
avformat_find_stream_info still used to terminate within reasonable
time before 3749eede66c3774799766b1f246afae8a6ffc9bb. After that
commit, it no longer would terminate until it reaches the max
analyze duration, which is 90 seconds for flv streams (see
e6a084641aada7a2e4672172f2ee26642800a361,
24fdf7334d2bb9aab0abdbc878b8ae51eb57c86b and
f58e011a1f30332ba824c155078ca701e29aef63).

Before that commit (which removed the deprecated AVStream.codec), the
"st->codecpar->codec_id = AV_CODEC_ID_TEXT", set within the demuxer,
would get propagated into st->codec->codec_id by numerous
avcodec_parameters_to_context(st->codec, st->codecpar), then further
into st->internal->avctx->codec_id by update_stream_avctx within
read_frame_internal in libavformat/utils.c (demux.c these days).
---
 libavformat/flvdec.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index e25b5bd163..d898341871 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -627,12 +627,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
                 else if (!strcmp(key, "audiodatarate") &&
                          0 <= (int)(num_val * 1024.0))
                     flv->audio_bit_rate = num_val * 1024.0;
-                else if (!strcmp(key, "datastream")) {
-                    AVStream *st = create_stream(s, AVMEDIA_TYPE_SUBTITLE);
-                    if (!st)
-                        return AVERROR(ENOMEM);
-                    st->codecpar->codec_id = AV_CODEC_ID_TEXT;
-                } else if (!strcmp(key, "framerate")) {
+                else if (!strcmp(key, "framerate")) {
                     flv->framerate = av_d2q(num_val, 1000);
                     if (vstream)
                         vstream->avg_frame_rate = flv->framerate;
@@ -654,6 +649,11 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
                         vpar->width = num_val;
                     } else if (!strcmp(key, "height") && vpar) {
                         vpar->height = num_val;
+                    } else if (!strcmp(key, "datastream")) {
+                        AVStream *st = create_stream(s, AVMEDIA_TYPE_SUBTITLE);
+                        if (!st)
+                            return AVERROR(ENOMEM);
+                        st->codecpar->codec_id = AV_CODEC_ID_TEXT;
                     }
                 }
             }
-- 
2.39.3 (Apple Git-145)



More information about the ffmpeg-devel mailing list