History

flvdec: Honor the "flv_metadata" option for the "datastream" metadata field

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).

Martin Storsjö committed 2 years ago

Commit 58ffe0d1 parent 8c00fe61 file · +6 −6Browse files

Showing the changes to libavformat (1 of 1 file). Show all

Unified · Split

libavformat/flvdec.c+6−6
@@ -627,12 +627,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, · 626 unmodified lines
627627 else if (!strcmp(key, "audiodatarate") &&
628628 0 <= (int)(num_val * 1024.0))
629629 flv->audio_bit_rate = num_val * 1024.0;
630− else if (!strcmp(key, "datastream")) {
631− AVStream *st = create_stream(s, AVMEDIA_TYPE_SUBTITLE);
632− if (!st)
633− return AVERROR(ENOMEM);
634− st->codecpar->codec_id = AV_CODEC_ID_TEXT;
635− } else if (!strcmp(key, "framerate")) {
630+ else if (!strcmp(key, "framerate")) {
636631 flv->framerate = av_d2q(num_val, 1000);
637632 if (vstream)
638633 vstream->avg_frame_rate = flv->framerate;
@@ -654,6 +649,11 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, · 15 unmodified lines
654649 vpar->width = num_val;
655650 } else if (!strcmp(key, "height") && vpar) {
656651 vpar->height = num_val;
652+ } else if (!strcmp(key, "datastream")) {
653+ AVStream *st = create_stream(s, AVMEDIA_TYPE_SUBTITLE);
654+ if (!st)
655+ return AVERROR(ENOMEM);
656+ st->codecpar->codec_id = AV_CODEC_ID_TEXT;
657657 }
658658 }
659659 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t