* [FFmpeg-devel] [PATCH] avformat/mpegts: Add AVFMT_FLAG_ALLOW_CODEC_CHANGES @ 2025-06-22 18:10 Pavel Koshevoy 2025-06-28 1:39 ` Pavel Koshevoy 2025-06-28 23:03 ` Michael Niedermayer 0 siblings, 2 replies; 7+ messages in thread From: Pavel Koshevoy @ 2025-06-22 18:10 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Pavel Koshevoy Make midstream AVStream.codecpar updates optional and disabled by default, so that avformat API clients can enable this feature explicitly when they add support for midstream codec changes. --- doc/APIchanges | 3 +++ doc/formats.texi | 5 +++++ libavformat/avformat.h | 2 ++ libavformat/mpegts.c | 4 +++- libavformat/options_table.h | 1 + libavformat/version.h | 2 +- tests/fate/demux.mak | 2 +- 7 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 91710bb27d..43172fbcdd 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28 API changes, most recent first: +2025-06-17 - xxxxxxxxxx - lavf 62.2.100 - avformat.h + Add AVFMT_FLAG_ALLOW_CODEC_CHANGES flag. + 2025-05-21 - xxxxxxxxxx - lavu 60.3.100 - avassert.h Add av_unreachable() and av_assume() macros. diff --git a/doc/formats.texi b/doc/formats.texi index 876a9e92b3..5a0d070247 100644 --- a/doc/formats.texi +++ b/doc/formats.texi @@ -39,6 +39,11 @@ Set format flags. Some are implemented for a limited number of formats. Possible values for input files: @table @samp +@item allow_codec_changes +Allow AVStream.codecpar to change midstream if input changes +(for example when MPEG-TS ES stream_type changes). +This is disabled by default, because most clients of avformat API +do not support random midstream codec changes. @item discardcorrupt Discard corrupted packets. @item fastseek diff --git a/libavformat/avformat.h b/libavformat/avformat.h index b6c63e2237..2e5232c96d 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1436,6 +1436,8 @@ typedef struct AVFormatContext { #define AVFMT_FLAG_FAST_SEEK 0x80000 ///< Enable fast, but inaccurate seeks for some formats #define AVFMT_FLAG_AUTO_BSF 0x200000 ///< Add bitstream filters as requested by the muxer +#define AVFMT_FLAG_ALLOW_CODEC_CHANGES 0x400000 ///< Allow AVStream.codecpar to be updated midstream if input changes (e.g. MPEG-TS ES stream_type changes) + /** * Maximum number of bytes read from input in order to determine stream * properties. Used when reading the global header and in diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index deb69a0548..ed4ff580e5 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -2510,7 +2510,9 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len if (!st) goto out; - if (pes && pes->stream_type != stream_type) + if (pes && (!pes->stream_type || + (pes->stream_type != stream_type && + !!(ts->stream->flags & AVFMT_FLAG_ALLOW_CODEC_CHANGES)))) mpegts_set_stream_info(st, pes, stream_type, prog_reg_desc); add_pid_to_program(prg, pid); diff --git a/libavformat/options_table.h b/libavformat/options_table.h index e2e690fd2a..811dd342cc 100644 --- a/libavformat/options_table.h +++ b/libavformat/options_table.h @@ -50,6 +50,7 @@ static const AVOption avformat_options[] = { {"sortdts", "try to interleave outputted packets by dts", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_SORT_DTS }, INT_MIN, INT_MAX, D, .unit = "fflags"}, {"fastseek", "fast but inaccurate seeks", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_FAST_SEEK }, INT_MIN, INT_MAX, D, .unit = "fflags"}, {"nobuffer", "reduce the latency introduced by optional buffering", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_NOBUFFER }, 0, INT_MAX, D, .unit = "fflags"}, +{"allow_codec_changes", "allow AVStream.codecpar to change at runtime if input changes", 0, AV_OPT_TYPE_CONST, { .i64 = AVFMT_FLAG_ALLOW_CODEC_CHANGES }, 0, 0, D, .unit = "fflags" }, {"bitexact", "do not write random/volatile data", 0, AV_OPT_TYPE_CONST, { .i64 = AVFMT_FLAG_BITEXACT }, 0, 0, E, .unit = "fflags" }, {"autobsf", "add needed bsfs automatically", 0, AV_OPT_TYPE_CONST, { .i64 = AVFMT_FLAG_AUTO_BSF }, 0, 0, E, .unit = "fflags" }, {"seek2any", "allow seeking to non-keyframes on demuxer level when supported", OFFSET(seek2any), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, D}, diff --git a/libavformat/version.h b/libavformat/version.h index a7c80dc564..904e7f06aa 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -31,7 +31,7 @@ #include "version_major.h" -#define LIBAVFORMAT_VERSION_MINOR 1 +#define LIBAVFORMAT_VERSION_MINOR 2 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak index ead5ad4b10..e293a00dc0 100644 --- a/tests/fate/demux.mak +++ b/tests/fate/demux.mak @@ -158,7 +158,7 @@ FATE_SAMPLES_DEMUX-$(CONFIG_XWMA_DEMUXER) += fate-xwma-demux fate-xwma-demux: CMD = crc -i $(TARGET_SAMPLES)/xwma/ergon.xwma -c:a copy FATE_FFPROBE_DEMUX-$(CONFIG_MPEGTS_DEMUXER) += fate-ts-demux -fate-ts-demux: CMD = ffprobe_demux $(TARGET_SAMPLES)/ac3/mp3ac325-4864-small.ts +fate-ts-demux: CMD = ffprobe_demux $(TARGET_SAMPLES)/ac3/mp3ac325-4864-small.ts -fflags +allow_codec_changes FATE_FFPROBE_DEMUX-$(CONFIG_MPEGTS_DEMUXER) += fate-ts-timed-id3-demux fate-ts-timed-id3-demux: CMD = ffprobe_demux $(TARGET_SAMPLES)/mpegts/id3.ts -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/mpegts: Add AVFMT_FLAG_ALLOW_CODEC_CHANGES 2025-06-22 18:10 [FFmpeg-devel] [PATCH] avformat/mpegts: Add AVFMT_FLAG_ALLOW_CODEC_CHANGES Pavel Koshevoy @ 2025-06-28 1:39 ` Pavel Koshevoy 2025-06-28 23:03 ` Michael Niedermayer 1 sibling, 0 replies; 7+ messages in thread From: Pavel Koshevoy @ 2025-06-28 1:39 UTC (permalink / raw) To: ffmpeg-devel ping On Sun, Jun 22, 2025 at 12:10 PM Pavel Koshevoy <pkoshevoy@gmail.com> wrote: > Make midstream AVStream.codecpar updates optional and disabled > by default, so that avformat API clients can enable this feature > explicitly when they add support for midstream codec changes. > --- > doc/APIchanges | 3 +++ > doc/formats.texi | 5 +++++ > libavformat/avformat.h | 2 ++ > libavformat/mpegts.c | 4 +++- > libavformat/options_table.h | 1 + > libavformat/version.h | 2 +- > tests/fate/demux.mak | 2 +- > 7 files changed, 16 insertions(+), 3 deletions(-) > > diff --git a/doc/APIchanges b/doc/APIchanges > index 91710bb27d..43172fbcdd 100644 > --- a/doc/APIchanges > +++ b/doc/APIchanges > @@ -2,6 +2,9 @@ The last version increases of all libraries were on > 2025-03-28 > > API changes, most recent first: > > +2025-06-17 - xxxxxxxxxx - lavf 62.2.100 - avformat.h > + Add AVFMT_FLAG_ALLOW_CODEC_CHANGES flag. > + > 2025-05-21 - xxxxxxxxxx - lavu 60.3.100 - avassert.h > Add av_unreachable() and av_assume() macros. > > diff --git a/doc/formats.texi b/doc/formats.texi > index 876a9e92b3..5a0d070247 100644 > --- a/doc/formats.texi > +++ b/doc/formats.texi > @@ -39,6 +39,11 @@ Set format flags. Some are implemented for a limited > number of formats. > > Possible values for input files: > @table @samp > +@item allow_codec_changes > +Allow AVStream.codecpar to change midstream if input changes > +(for example when MPEG-TS ES stream_type changes). > +This is disabled by default, because most clients of avformat API > +do not support random midstream codec changes. > @item discardcorrupt > Discard corrupted packets. > @item fastseek > diff --git a/libavformat/avformat.h b/libavformat/avformat.h > index b6c63e2237..2e5232c96d 100644 > --- a/libavformat/avformat.h > +++ b/libavformat/avformat.h > @@ -1436,6 +1436,8 @@ typedef struct AVFormatContext { > #define AVFMT_FLAG_FAST_SEEK 0x80000 ///< Enable fast, but inaccurate > seeks for some formats > #define AVFMT_FLAG_AUTO_BSF 0x200000 ///< Add bitstream filters as > requested by the muxer > > +#define AVFMT_FLAG_ALLOW_CODEC_CHANGES 0x400000 ///< Allow > AVStream.codecpar to be updated midstream if input changes (e.g. MPEG-TS ES > stream_type changes) > + > /** > * Maximum number of bytes read from input in order to determine > stream > * properties. Used when reading the global header and in > diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c > index deb69a0548..ed4ff580e5 100644 > --- a/libavformat/mpegts.c > +++ b/libavformat/mpegts.c > @@ -2510,7 +2510,9 @@ static void pmt_cb(MpegTSFilter *filter, const > uint8_t *section, int section_len > if (!st) > goto out; > > - if (pes && pes->stream_type != stream_type) > + if (pes && (!pes->stream_type || > + (pes->stream_type != stream_type && > + !!(ts->stream->flags & > AVFMT_FLAG_ALLOW_CODEC_CHANGES)))) > mpegts_set_stream_info(st, pes, stream_type, prog_reg_desc); > > add_pid_to_program(prg, pid); > diff --git a/libavformat/options_table.h b/libavformat/options_table.h > index e2e690fd2a..811dd342cc 100644 > --- a/libavformat/options_table.h > +++ b/libavformat/options_table.h > @@ -50,6 +50,7 @@ static const AVOption avformat_options[] = { > {"sortdts", "try to interleave outputted packets by dts", 0, > AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_SORT_DTS }, INT_MIN, INT_MAX, D, > .unit = "fflags"}, > {"fastseek", "fast but inaccurate seeks", 0, AV_OPT_TYPE_CONST, {.i64 = > AVFMT_FLAG_FAST_SEEK }, INT_MIN, INT_MAX, D, .unit = "fflags"}, > {"nobuffer", "reduce the latency introduced by optional buffering", 0, > AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_NOBUFFER }, 0, INT_MAX, D, .unit = > "fflags"}, > +{"allow_codec_changes", "allow AVStream.codecpar to change at runtime if > input changes", 0, AV_OPT_TYPE_CONST, { .i64 = > AVFMT_FLAG_ALLOW_CODEC_CHANGES }, 0, 0, D, .unit = "fflags" }, > {"bitexact", "do not write random/volatile data", 0, AV_OPT_TYPE_CONST, { > .i64 = AVFMT_FLAG_BITEXACT }, 0, 0, E, .unit = "fflags" }, > {"autobsf", "add needed bsfs automatically", 0, AV_OPT_TYPE_CONST, { .i64 > = AVFMT_FLAG_AUTO_BSF }, 0, 0, E, .unit = "fflags" }, > {"seek2any", "allow seeking to non-keyframes on demuxer level when > supported", OFFSET(seek2any), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, D}, > diff --git a/libavformat/version.h b/libavformat/version.h > index a7c80dc564..904e7f06aa 100644 > --- a/libavformat/version.h > +++ b/libavformat/version.h > @@ -31,7 +31,7 @@ > > #include "version_major.h" > > -#define LIBAVFORMAT_VERSION_MINOR 1 > +#define LIBAVFORMAT_VERSION_MINOR 2 > #define LIBAVFORMAT_VERSION_MICRO 100 > > #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, > \ > diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak > index ead5ad4b10..e293a00dc0 100644 > --- a/tests/fate/demux.mak > +++ b/tests/fate/demux.mak > @@ -158,7 +158,7 @@ FATE_SAMPLES_DEMUX-$(CONFIG_XWMA_DEMUXER) += > fate-xwma-demux > fate-xwma-demux: CMD = crc -i $(TARGET_SAMPLES)/xwma/ergon.xwma -c:a copy > > FATE_FFPROBE_DEMUX-$(CONFIG_MPEGTS_DEMUXER) += fate-ts-demux > -fate-ts-demux: CMD = ffprobe_demux > $(TARGET_SAMPLES)/ac3/mp3ac325-4864-small.ts > +fate-ts-demux: CMD = ffprobe_demux > $(TARGET_SAMPLES)/ac3/mp3ac325-4864-small.ts -fflags +allow_codec_changes > > FATE_FFPROBE_DEMUX-$(CONFIG_MPEGTS_DEMUXER) += fate-ts-timed-id3-demux > fate-ts-timed-id3-demux: CMD = ffprobe_demux > $(TARGET_SAMPLES)/mpegts/id3.ts > -- > 2.43.0 > > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/mpegts: Add AVFMT_FLAG_ALLOW_CODEC_CHANGES 2025-06-22 18:10 [FFmpeg-devel] [PATCH] avformat/mpegts: Add AVFMT_FLAG_ALLOW_CODEC_CHANGES Pavel Koshevoy 2025-06-28 1:39 ` Pavel Koshevoy @ 2025-06-28 23:03 ` Michael Niedermayer 2025-06-29 2:49 ` Pavel Koshevoy 1 sibling, 1 reply; 7+ messages in thread From: Michael Niedermayer @ 2025-06-28 23:03 UTC (permalink / raw) To: FFmpeg development discussions and patches [-- Attachment #1.1: Type: text/plain, Size: 4475 bytes --] Hi On Sun, Jun 22, 2025 at 12:10:30PM -0600, Pavel Koshevoy wrote: > Make midstream AVStream.codecpar updates optional and disabled > by default, so that avformat API clients can enable this feature > explicitly when they add support for midstream codec changes. > --- > doc/APIchanges | 3 +++ > doc/formats.texi | 5 +++++ > libavformat/avformat.h | 2 ++ > libavformat/mpegts.c | 4 +++- > libavformat/options_table.h | 1 + > libavformat/version.h | 2 +- > tests/fate/demux.mak | 2 +- > 7 files changed, 16 insertions(+), 3 deletions(-) > > diff --git a/doc/APIchanges b/doc/APIchanges > index 91710bb27d..43172fbcdd 100644 > --- a/doc/APIchanges > +++ b/doc/APIchanges > @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28 > > API changes, most recent first: > > +2025-06-17 - xxxxxxxxxx - lavf 62.2.100 - avformat.h > + Add AVFMT_FLAG_ALLOW_CODEC_CHANGES flag. > + > 2025-05-21 - xxxxxxxxxx - lavu 60.3.100 - avassert.h > Add av_unreachable() and av_assume() macros. > > diff --git a/doc/formats.texi b/doc/formats.texi > index 876a9e92b3..5a0d070247 100644 > --- a/doc/formats.texi > +++ b/doc/formats.texi > @@ -39,6 +39,11 @@ Set format flags. Some are implemented for a limited number of formats. > > Possible values for input files: > @table @samp > +@item allow_codec_changes > +Allow AVStream.codecpar to change midstream if input changes > +(for example when MPEG-TS ES stream_type changes). > +This is disabled by default, because most clients of avformat API > +do not support random midstream codec changes. > @item discardcorrupt > Discard corrupted packets. > @item fastseek should this document the relation to resolution & pixfmt changes ? > diff --git a/libavformat/avformat.h b/libavformat/avformat.h > index b6c63e2237..2e5232c96d 100644 > --- a/libavformat/avformat.h > +++ b/libavformat/avformat.h > @@ -1436,6 +1436,8 @@ typedef struct AVFormatContext { > #define AVFMT_FLAG_FAST_SEEK 0x80000 ///< Enable fast, but inaccurate seeks for some formats > #define AVFMT_FLAG_AUTO_BSF 0x200000 ///< Add bitstream filters as requested by the muxer > > +#define AVFMT_FLAG_ALLOW_CODEC_CHANGES 0x400000 ///< Allow AVStream.codecpar to be updated midstream if input changes (e.g. MPEG-TS ES stream_type changes) > + > /** > * Maximum number of bytes read from input in order to determine stream > * properties. Used when reading the global header and in > diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c > index deb69a0548..ed4ff580e5 100644 > --- a/libavformat/mpegts.c > +++ b/libavformat/mpegts.c > @@ -2510,7 +2510,9 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len > if (!st) > goto out; > > - if (pes && pes->stream_type != stream_type) > + if (pes && (!pes->stream_type || > + (pes->stream_type != stream_type && > + !!(ts->stream->flags & AVFMT_FLAG_ALLOW_CODEC_CHANGES)))) > mpegts_set_stream_info(st, pes, stream_type, prog_reg_desc); > > add_pid_to_program(prg, pid); > diff --git a/libavformat/options_table.h b/libavformat/options_table.h > index e2e690fd2a..811dd342cc 100644 > --- a/libavformat/options_table.h > +++ b/libavformat/options_table.h > @@ -50,6 +50,7 @@ static const AVOption avformat_options[] = { > {"sortdts", "try to interleave outputted packets by dts", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_SORT_DTS }, INT_MIN, INT_MAX, D, .unit = "fflags"}, > {"fastseek", "fast but inaccurate seeks", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_FAST_SEEK }, INT_MIN, INT_MAX, D, .unit = "fflags"}, > {"nobuffer", "reduce the latency introduced by optional buffering", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_NOBUFFER }, 0, INT_MAX, D, .unit = "fflags"}, > +{"allow_codec_changes", "allow AVStream.codecpar to change at runtime if input changes", 0, AV_OPT_TYPE_CONST, { .i64 = AVFMT_FLAG_ALLOW_CODEC_CHANGES }, 0, 0, D, .unit = "fflags" }, If the option is user settable then ffmpeg/ffplay should possibly print a warning, that they do not support this if the user forces the flag thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The educated differ from the uneducated as much as the living from the dead. -- Aristotle [-- Attachment #1.2: signature.asc --] [-- Type: application/pgp-signature, Size: 195 bytes --] [-- Attachment #2: Type: text/plain, Size: 251 bytes --] _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/mpegts: Add AVFMT_FLAG_ALLOW_CODEC_CHANGES 2025-06-28 23:03 ` Michael Niedermayer @ 2025-06-29 2:49 ` Pavel Koshevoy 2025-06-30 1:01 ` Michael Niedermayer 0 siblings, 1 reply; 7+ messages in thread From: Pavel Koshevoy @ 2025-06-29 2:49 UTC (permalink / raw) To: FFmpeg development discussions and patches On Sat, Jun 28, 2025 at 5:03 PM Michael Niedermayer <michael@niedermayer.cc> wrote: > Hi > > On Sun, Jun 22, 2025 at 12:10:30PM -0600, Pavel Koshevoy wrote: > > Make midstream AVStream.codecpar updates optional and disabled > > by default, so that avformat API clients can enable this feature > > explicitly when they add support for midstream codec changes. > > --- > > doc/APIchanges | 3 +++ > > doc/formats.texi | 5 +++++ > > libavformat/avformat.h | 2 ++ > > libavformat/mpegts.c | 4 +++- > > libavformat/options_table.h | 1 + > > libavformat/version.h | 2 +- > > tests/fate/demux.mak | 2 +- > > 7 files changed, 16 insertions(+), 3 deletions(-) > > > > diff --git a/doc/APIchanges b/doc/APIchanges > > index 91710bb27d..43172fbcdd 100644 > > --- a/doc/APIchanges > > +++ b/doc/APIchanges > > @@ -2,6 +2,9 @@ The last version increases of all libraries were on > 2025-03-28 > > > > API changes, most recent first: > > > > +2025-06-17 - xxxxxxxxxx - lavf 62.2.100 - avformat.h > > + Add AVFMT_FLAG_ALLOW_CODEC_CHANGES flag. > > + > > 2025-05-21 - xxxxxxxxxx - lavu 60.3.100 - avassert.h > > Add av_unreachable() and av_assume() macros. > > > > diff --git a/doc/formats.texi b/doc/formats.texi > > index 876a9e92b3..5a0d070247 100644 > > --- a/doc/formats.texi > > +++ b/doc/formats.texi > > @@ -39,6 +39,11 @@ Set format flags. Some are implemented for a limited > number of formats. > > > > Possible values for input files: > > @table @samp > > +@item allow_codec_changes > > +Allow AVStream.codecpar to change midstream if input changes > > +(for example when MPEG-TS ES stream_type changes). > > +This is disabled by default, because most clients of avformat API > > +do not support random midstream codec changes. > > @item discardcorrupt > > Discard corrupted packets. > > @item fastseek > > should this document the relation to resolution & pixfmt changes ? > How about this: Allow AVStream.codecpar to change midstream if input changes (for example when MPEG-TS ES stream_type changes). This is disabled by default, because most clients of avformat API do not support random midstream codec changes. Changes may include media type, codec id, pixel format, color specs, channel layout, sample rate, and may be accompanied by timeline anomalies. > > > > diff --git a/libavformat/avformat.h b/libavformat/avformat.h > > index b6c63e2237..2e5232c96d 100644 > > --- a/libavformat/avformat.h > > +++ b/libavformat/avformat.h > > @@ -1436,6 +1436,8 @@ typedef struct AVFormatContext { > > #define AVFMT_FLAG_FAST_SEEK 0x80000 ///< Enable fast, but inaccurate > seeks for some formats > > #define AVFMT_FLAG_AUTO_BSF 0x200000 ///< Add bitstream filters as > requested by the muxer > > > > +#define AVFMT_FLAG_ALLOW_CODEC_CHANGES 0x400000 ///< Allow > AVStream.codecpar to be updated midstream if input changes (e.g. MPEG-TS ES > stream_type changes) > > + > > /** > > * Maximum number of bytes read from input in order to determine > stream > > * properties. Used when reading the global header and in > > diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c > > index deb69a0548..ed4ff580e5 100644 > > --- a/libavformat/mpegts.c > > +++ b/libavformat/mpegts.c > > @@ -2510,7 +2510,9 @@ static void pmt_cb(MpegTSFilter *filter, const > uint8_t *section, int section_len > > if (!st) > > goto out; > > > > - if (pes && pes->stream_type != stream_type) > > + if (pes && (!pes->stream_type || > > + (pes->stream_type != stream_type && > > + !!(ts->stream->flags & > AVFMT_FLAG_ALLOW_CODEC_CHANGES)))) > > mpegts_set_stream_info(st, pes, stream_type, prog_reg_desc); > > > > add_pid_to_program(prg, pid); > > diff --git a/libavformat/options_table.h b/libavformat/options_table.h > > index e2e690fd2a..811dd342cc 100644 > > --- a/libavformat/options_table.h > > +++ b/libavformat/options_table.h > > @@ -50,6 +50,7 @@ static const AVOption avformat_options[] = { > > {"sortdts", "try to interleave outputted packets by dts", 0, > AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_SORT_DTS }, INT_MIN, INT_MAX, D, > .unit = "fflags"}, > > {"fastseek", "fast but inaccurate seeks", 0, AV_OPT_TYPE_CONST, {.i64 = > AVFMT_FLAG_FAST_SEEK }, INT_MIN, INT_MAX, D, .unit = "fflags"}, > > {"nobuffer", "reduce the latency introduced by optional buffering", 0, > AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_NOBUFFER }, 0, INT_MAX, D, .unit = > "fflags"}, > > +{"allow_codec_changes", "allow AVStream.codecpar to change at runtime > if input changes", 0, AV_OPT_TYPE_CONST, { .i64 = > AVFMT_FLAG_ALLOW_CODEC_CHANGES }, 0, 0, D, .unit = "fflags" }, > > If the option is user settable then ffmpeg/ffplay should possibly print a > warning, that they do not support this if the user forces the flag > Well, it's not as if they don't support it at all ... they consume the option and set the flag, and the demuxer does what it's supposed to. In case of ffplay, with -fflags +allow_codec_changes it's actually able to play 1_poc.mp4 and render a partially decoded image. Anyway, what would this warning look like? I'm having a hard time coming up with a warning message that isn't misleading or confusing. Would you like to suggest one? Would something like this work: if (!!(ic->flags & AVFMT_FLAG_ALLOW_CODEC_CHANGES)) av_log(NULL, AV_LOG_WARNING, "downstream support for allow_codec_changes is not implemented"); Thank you, Pavel. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/mpegts: Add AVFMT_FLAG_ALLOW_CODEC_CHANGES 2025-06-29 2:49 ` Pavel Koshevoy @ 2025-06-30 1:01 ` Michael Niedermayer 2025-06-30 3:45 ` Pavel Koshevoy 0 siblings, 1 reply; 7+ messages in thread From: Michael Niedermayer @ 2025-06-30 1:01 UTC (permalink / raw) To: FFmpeg development discussions and patches [-- Attachment #1.1: Type: text/plain, Size: 7187 bytes --] Hi On Sat, Jun 28, 2025 at 08:49:08PM -0600, Pavel Koshevoy wrote: > On Sat, Jun 28, 2025 at 5:03 PM Michael Niedermayer <michael@niedermayer.cc> > wrote: > > > Hi > > > > On Sun, Jun 22, 2025 at 12:10:30PM -0600, Pavel Koshevoy wrote: > > > Make midstream AVStream.codecpar updates optional and disabled > > > by default, so that avformat API clients can enable this feature > > > explicitly when they add support for midstream codec changes. > > > --- > > > doc/APIchanges | 3 +++ > > > doc/formats.texi | 5 +++++ > > > libavformat/avformat.h | 2 ++ > > > libavformat/mpegts.c | 4 +++- > > > libavformat/options_table.h | 1 + > > > libavformat/version.h | 2 +- > > > tests/fate/demux.mak | 2 +- > > > 7 files changed, 16 insertions(+), 3 deletions(-) > > > > > > diff --git a/doc/APIchanges b/doc/APIchanges > > > index 91710bb27d..43172fbcdd 100644 > > > --- a/doc/APIchanges > > > +++ b/doc/APIchanges > > > @@ -2,6 +2,9 @@ The last version increases of all libraries were on > > 2025-03-28 > > > > > > API changes, most recent first: > > > > > > +2025-06-17 - xxxxxxxxxx - lavf 62.2.100 - avformat.h > > > + Add AVFMT_FLAG_ALLOW_CODEC_CHANGES flag. > > > + > > > 2025-05-21 - xxxxxxxxxx - lavu 60.3.100 - avassert.h > > > Add av_unreachable() and av_assume() macros. > > > > > > diff --git a/doc/formats.texi b/doc/formats.texi > > > index 876a9e92b3..5a0d070247 100644 > > > --- a/doc/formats.texi > > > +++ b/doc/formats.texi > > > @@ -39,6 +39,11 @@ Set format flags. Some are implemented for a limited > > number of formats. > > > > > > Possible values for input files: > > > @table @samp > > > +@item allow_codec_changes > > > +Allow AVStream.codecpar to change midstream if input changes > > > +(for example when MPEG-TS ES stream_type changes). > > > +This is disabled by default, because most clients of avformat API > > > +do not support random midstream codec changes. > > > @item discardcorrupt > > > Discard corrupted packets. > > > @item fastseek > > > > should this document the relation to resolution & pixfmt changes ? > > > > How about this: > > Allow AVStream.codecpar to change midstream if input changes > (for example when MPEG-TS ES stream_type changes). > This is disabled by default, because most clients of avformat API > do not support random midstream codec changes. > Changes may include media type, codec id, pixel format, color specs, > channel layout, sample rate, and may be accompanied by timeline anomalies. The chain suppports pixel format and resolution changes from demuxers to decoder and ffmpeg/ffplay completely unrelated to this flag. > > > > > > > > > > > diff --git a/libavformat/avformat.h b/libavformat/avformat.h > > > index b6c63e2237..2e5232c96d 100644 > > > --- a/libavformat/avformat.h > > > +++ b/libavformat/avformat.h > > > @@ -1436,6 +1436,8 @@ typedef struct AVFormatContext { > > > #define AVFMT_FLAG_FAST_SEEK 0x80000 ///< Enable fast, but inaccurate > > seeks for some formats > > > #define AVFMT_FLAG_AUTO_BSF 0x200000 ///< Add bitstream filters as > > requested by the muxer > > > > > > +#define AVFMT_FLAG_ALLOW_CODEC_CHANGES 0x400000 ///< Allow > > AVStream.codecpar to be updated midstream if input changes (e.g. MPEG-TS ES > > stream_type changes) > > > + > > > /** > > > * Maximum number of bytes read from input in order to determine > > stream > > > * properties. Used when reading the global header and in > > > diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c > > > index deb69a0548..ed4ff580e5 100644 > > > --- a/libavformat/mpegts.c > > > +++ b/libavformat/mpegts.c > > > @@ -2510,7 +2510,9 @@ static void pmt_cb(MpegTSFilter *filter, const > > uint8_t *section, int section_len > > > if (!st) > > > goto out; > > > > > > - if (pes && pes->stream_type != stream_type) > > > + if (pes && (!pes->stream_type || > > > + (pes->stream_type != stream_type && > > > + !!(ts->stream->flags & > > AVFMT_FLAG_ALLOW_CODEC_CHANGES)))) > > > mpegts_set_stream_info(st, pes, stream_type, prog_reg_desc); > > > > > > add_pid_to_program(prg, pid); > > > diff --git a/libavformat/options_table.h b/libavformat/options_table.h > > > index e2e690fd2a..811dd342cc 100644 > > > --- a/libavformat/options_table.h > > > +++ b/libavformat/options_table.h > > > @@ -50,6 +50,7 @@ static const AVOption avformat_options[] = { > > > {"sortdts", "try to interleave outputted packets by dts", 0, > > AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_SORT_DTS }, INT_MIN, INT_MAX, D, > > .unit = "fflags"}, > > > {"fastseek", "fast but inaccurate seeks", 0, AV_OPT_TYPE_CONST, {.i64 = > > AVFMT_FLAG_FAST_SEEK }, INT_MIN, INT_MAX, D, .unit = "fflags"}, > > > {"nobuffer", "reduce the latency introduced by optional buffering", 0, > > AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_NOBUFFER }, 0, INT_MAX, D, .unit = > > "fflags"}, > > > +{"allow_codec_changes", "allow AVStream.codecpar to change at runtime > > if input changes", 0, AV_OPT_TYPE_CONST, { .i64 = > > AVFMT_FLAG_ALLOW_CODEC_CHANGES }, 0, 0, D, .unit = "fflags" }, > > > > If the option is user settable then ffmpeg/ffplay should possibly print a > > warning, that they do not support this if the user forces the flag > > > > Well, it's not as if they don't support it at all ... they consume the > option and set the flag, and the demuxer does what it's supposed to. > In case of ffplay, with -fflags +allow_codec_changes it's actually able to > play 1_poc.mp4 and render a partially decoded image. > > Anyway, what would this warning look like? > I'm having a hard time coming up with a warning message that isn't > misleading or confusing. > Would you like to suggest one? Would something like this work: > > if (!!(ic->flags & AVFMT_FLAG_ALLOW_CODEC_CHANGES)) > av_log(NULL, AV_LOG_WARNING, "downstream support for > allow_codec_changes is not implemented"); I was thinking more along the lines of the "--disable-safe-bitstream-reader" help text: disable buffer boundary checking in bitreaders (This disables some security checks and can cause undefined behavior, crashes and arbitrary code execution, it may be faster, but should only be used with trusted input) Bascially, what the goal here is, is to explain to the user that with this flag they are potentially giving the input file arbitrary code execution on their machiene I still think andreas comment that this should be set by the application not the user should be considered. Can you explain in what use case this is usefull ? (you cannot saftely use this for any untrusted input if the tool does not fully support this) thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB z(9) = an object that transcends all computable functions describable in finite terms. - ChatGPT in 2024 [-- Attachment #1.2: signature.asc --] [-- Type: application/pgp-signature, Size: 195 bytes --] [-- Attachment #2: Type: text/plain, Size: 251 bytes --] _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/mpegts: Add AVFMT_FLAG_ALLOW_CODEC_CHANGES 2025-06-30 1:01 ` Michael Niedermayer @ 2025-06-30 3:45 ` Pavel Koshevoy 2025-07-04 1:30 ` Michael Niedermayer 0 siblings, 1 reply; 7+ messages in thread From: Pavel Koshevoy @ 2025-06-30 3:45 UTC (permalink / raw) To: FFmpeg development discussions and patches On Sun, Jun 29, 2025 at 7:01 PM Michael Niedermayer <michael@niedermayer.cc> wrote: > Hi > > On Sat, Jun 28, 2025 at 08:49:08PM -0600, Pavel Koshevoy wrote: > > On Sat, Jun 28, 2025 at 5:03 PM Michael Niedermayer < > michael@niedermayer.cc> > > wrote: > > > > > Hi > > > > > > On Sun, Jun 22, 2025 at 12:10:30PM -0600, Pavel Koshevoy wrote: > > > > Make midstream AVStream.codecpar updates optional and disabled > > > > by default, so that avformat API clients can enable this feature > > > > explicitly when they add support for midstream codec changes. > > > > --- > > > > doc/APIchanges | 3 +++ > > > > doc/formats.texi | 5 +++++ > > > > libavformat/avformat.h | 2 ++ > > > > libavformat/mpegts.c | 4 +++- > > > > libavformat/options_table.h | 1 + > > > > libavformat/version.h | 2 +- > > > > tests/fate/demux.mak | 2 +- > > > > 7 files changed, 16 insertions(+), 3 deletions(-) > > > > > > > > diff --git a/doc/APIchanges b/doc/APIchanges > > > > index 91710bb27d..43172fbcdd 100644 > > > > --- a/doc/APIchanges > > > > +++ b/doc/APIchanges > > > > @@ -2,6 +2,9 @@ The last version increases of all libraries were on > > > 2025-03-28 > > > > > > > > API changes, most recent first: > > > > > > > > +2025-06-17 - xxxxxxxxxx - lavf 62.2.100 - avformat.h > > > > + Add AVFMT_FLAG_ALLOW_CODEC_CHANGES flag. > > > > + > > > > 2025-05-21 - xxxxxxxxxx - lavu 60.3.100 - avassert.h > > > > Add av_unreachable() and av_assume() macros. > > > > > > > > diff --git a/doc/formats.texi b/doc/formats.texi > > > > index 876a9e92b3..5a0d070247 100644 > > > > --- a/doc/formats.texi > > > > +++ b/doc/formats.texi > > > > @@ -39,6 +39,11 @@ Set format flags. Some are implemented for a > limited > > > number of formats. > > > > > > > > Possible values for input files: > > > > @table @samp > > > > +@item allow_codec_changes > > > > +Allow AVStream.codecpar to change midstream if input changes > > > > +(for example when MPEG-TS ES stream_type changes). > > > > +This is disabled by default, because most clients of avformat API > > > > +do not support random midstream codec changes. > > > > @item discardcorrupt > > > > Discard corrupted packets. > > > > @item fastseek > > > > > > should this document the relation to resolution & pixfmt changes ? > > > > > > > How about this: > > > > Allow AVStream.codecpar to change midstream if input changes > > (for example when MPEG-TS ES stream_type changes). > > This is disabled by default, because most clients of avformat API > > do not support random midstream codec changes. > > Changes may include media type, codec id, pixel format, color specs, > > channel layout, sample rate, and may be accompanied by timeline > anomalies. > > The chain suppports pixel format and resolution changes from demuxers > to decoder and ffmpeg/ffplay completely unrelated to this flag. > > IDK what this means ... I do know that ffplay can't play slate-to-network-short.ts correctly when stream changes from SDR mpeg2 video to HDR10 hevc video, with or without this flag. > > > > > > > > > > > > > > > > > > > diff --git a/libavformat/avformat.h b/libavformat/avformat.h > > > > index b6c63e2237..2e5232c96d 100644 > > > > --- a/libavformat/avformat.h > > > > +++ b/libavformat/avformat.h > > > > @@ -1436,6 +1436,8 @@ typedef struct AVFormatContext { > > > > #define AVFMT_FLAG_FAST_SEEK 0x80000 ///< Enable fast, but > inaccurate > > > seeks for some formats > > > > #define AVFMT_FLAG_AUTO_BSF 0x200000 ///< Add bitstream filters as > > > requested by the muxer > > > > > > > > +#define AVFMT_FLAG_ALLOW_CODEC_CHANGES 0x400000 ///< Allow > > > AVStream.codecpar to be updated midstream if input changes (e.g. > MPEG-TS ES > > > stream_type changes) > > > > + > > > > /** > > > > * Maximum number of bytes read from input in order to determine > > > stream > > > > * properties. Used when reading the global header and in > > > > diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c > > > > index deb69a0548..ed4ff580e5 100644 > > > > --- a/libavformat/mpegts.c > > > > +++ b/libavformat/mpegts.c > > > > @@ -2510,7 +2510,9 @@ static void pmt_cb(MpegTSFilter *filter, const > > > uint8_t *section, int section_len > > > > if (!st) > > > > goto out; > > > > > > > > - if (pes && pes->stream_type != stream_type) > > > > + if (pes && (!pes->stream_type || > > > > + (pes->stream_type != stream_type && > > > > + !!(ts->stream->flags & > > > AVFMT_FLAG_ALLOW_CODEC_CHANGES)))) > > > > mpegts_set_stream_info(st, pes, stream_type, > prog_reg_desc); > > > > > > > > add_pid_to_program(prg, pid); > > > > diff --git a/libavformat/options_table.h > b/libavformat/options_table.h > > > > index e2e690fd2a..811dd342cc 100644 > > > > --- a/libavformat/options_table.h > > > > +++ b/libavformat/options_table.h > > > > @@ -50,6 +50,7 @@ static const AVOption avformat_options[] = { > > > > {"sortdts", "try to interleave outputted packets by dts", 0, > > > AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_SORT_DTS }, INT_MIN, INT_MAX, D, > > > .unit = "fflags"}, > > > > {"fastseek", "fast but inaccurate seeks", 0, AV_OPT_TYPE_CONST, > {.i64 = > > > AVFMT_FLAG_FAST_SEEK }, INT_MIN, INT_MAX, D, .unit = "fflags"}, > > > > {"nobuffer", "reduce the latency introduced by optional buffering", > 0, > > > AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_NOBUFFER }, 0, INT_MAX, D, .unit > = > > > "fflags"}, > > > > +{"allow_codec_changes", "allow AVStream.codecpar to change at > runtime > > > if input changes", 0, AV_OPT_TYPE_CONST, { .i64 = > > > AVFMT_FLAG_ALLOW_CODEC_CHANGES }, 0, 0, D, .unit = "fflags" }, > > > > > > If the option is user settable then ffmpeg/ffplay should possibly > print a > > > warning, that they do not support this if the user forces the flag > > > > > > > Well, it's not as if they don't support it at all ... they consume the > > option and set the flag, and the demuxer does what it's supposed to. > > In case of ffplay, with -fflags +allow_codec_changes it's actually able > to > > play 1_poc.mp4 and render a partially decoded image. > > > > > Anyway, what would this warning look like? > > I'm having a hard time coming up with a warning message that isn't > > misleading or confusing. > > Would you like to suggest one? Would something like this work: > > > > if (!!(ic->flags & AVFMT_FLAG_ALLOW_CODEC_CHANGES)) > > av_log(NULL, AV_LOG_WARNING, "downstream support for > > allow_codec_changes is not implemented"); > > I was thinking more along the lines of the > "--disable-safe-bitstream-reader" > help text: > disable buffer boundary checking in bitreaders > (This disables some security checks and can > cause undefined behavior, > crashes and arbitrary code execution, it may > be faster, but > should only be used with trusted input) > > Bascially, what the goal here is, is to explain to the user that with this > flag > they are potentially giving the input file arbitrary code execution on > their > machiene > No, that's not what this flag does, and I will not document it as such. The arbitrary code execution is not a feature controlled by this flag... if such thing exists -- it was not added by me. This flag only controls the re-probing of the input stream when PMT ES stream_type changes, that is all. The ffprobe 1_poc.mp4 segfault was due to a previously unknown defect in demux.c codec_close probing helper function, for which I provided a fix. > > I still think andreas comment that this should be set by the application > not the user should be considered. > Fine, I can make this feature more hidden. That would also obviate any need to document it in formats.texi, so I'll remove that as well. > Can you explain in what use case this is usefull ? > It is useful for playback of real-world mpeg-ts captures like the one I've provided: slate-to-network-short.ts ... but not with ffplay, obviously. > > (you cannot saftely use this for any untrusted input if the tool does not > fully support this) > By this reasoning I wouldn't trust using ffmpeg with any un-trusted input, regardless of this flag. A fix for the codec_close bug in demux.c has been committed, and I am not aware of any additional issues that may be exposed when this is enabled. I will submit a new patch removing the allow_codec_changes flag from option_table.h and formats.texi Pavel _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/mpegts: Add AVFMT_FLAG_ALLOW_CODEC_CHANGES 2025-06-30 3:45 ` Pavel Koshevoy @ 2025-07-04 1:30 ` Michael Niedermayer 0 siblings, 0 replies; 7+ messages in thread From: Michael Niedermayer @ 2025-07-04 1:30 UTC (permalink / raw) To: FFmpeg development discussions and patches [-- Attachment #1.1: Type: text/plain, Size: 10236 bytes --] Hi On Sun, Jun 29, 2025 at 09:45:22PM -0600, Pavel Koshevoy wrote: > On Sun, Jun 29, 2025 at 7:01 PM Michael Niedermayer <michael@niedermayer.cc> > wrote: > > > Hi > > > > On Sat, Jun 28, 2025 at 08:49:08PM -0600, Pavel Koshevoy wrote: > > > On Sat, Jun 28, 2025 at 5:03 PM Michael Niedermayer < > > michael@niedermayer.cc> > > > wrote: > > > > > > > Hi > > > > > > > > On Sun, Jun 22, 2025 at 12:10:30PM -0600, Pavel Koshevoy wrote: > > > > > Make midstream AVStream.codecpar updates optional and disabled > > > > > by default, so that avformat API clients can enable this feature > > > > > explicitly when they add support for midstream codec changes. > > > > > --- > > > > > doc/APIchanges | 3 +++ > > > > > doc/formats.texi | 5 +++++ > > > > > libavformat/avformat.h | 2 ++ > > > > > libavformat/mpegts.c | 4 +++- > > > > > libavformat/options_table.h | 1 + > > > > > libavformat/version.h | 2 +- > > > > > tests/fate/demux.mak | 2 +- > > > > > 7 files changed, 16 insertions(+), 3 deletions(-) > > > > > > > > > > diff --git a/doc/APIchanges b/doc/APIchanges > > > > > index 91710bb27d..43172fbcdd 100644 > > > > > --- a/doc/APIchanges > > > > > +++ b/doc/APIchanges > > > > > @@ -2,6 +2,9 @@ The last version increases of all libraries were on > > > > 2025-03-28 > > > > > > > > > > API changes, most recent first: > > > > > > > > > > +2025-06-17 - xxxxxxxxxx - lavf 62.2.100 - avformat.h > > > > > + Add AVFMT_FLAG_ALLOW_CODEC_CHANGES flag. > > > > > + > > > > > 2025-05-21 - xxxxxxxxxx - lavu 60.3.100 - avassert.h > > > > > Add av_unreachable() and av_assume() macros. > > > > > > > > > > diff --git a/doc/formats.texi b/doc/formats.texi > > > > > index 876a9e92b3..5a0d070247 100644 > > > > > --- a/doc/formats.texi > > > > > +++ b/doc/formats.texi > > > > > @@ -39,6 +39,11 @@ Set format flags. Some are implemented for a > > limited > > > > number of formats. > > > > > > > > > > Possible values for input files: > > > > > @table @samp > > > > > +@item allow_codec_changes > > > > > +Allow AVStream.codecpar to change midstream if input changes > > > > > +(for example when MPEG-TS ES stream_type changes). > > > > > +This is disabled by default, because most clients of avformat API > > > > > +do not support random midstream codec changes. > > > > > @item discardcorrupt > > > > > Discard corrupted packets. > > > > > @item fastseek > > > > > > > > should this document the relation to resolution & pixfmt changes ? > > > > > > > > > > How about this: > > > > > > Allow AVStream.codecpar to change midstream if input changes > > > (for example when MPEG-TS ES stream_type changes). > > > This is disabled by default, because most clients of avformat API > > > do not support random midstream codec changes. > > > Changes may include media type, codec id, pixel format, color specs, > > > channel layout, sample rate, and may be accompanied by timeline > > anomalies. > > > > The chain suppports pixel format and resolution changes from demuxers > > to decoder and ffmpeg/ffplay completely unrelated to this flag. > > > > > IDK what this means ... I do know that ffplay can't play > slate-to-network-short.ts > correctly when stream changes from SDR mpeg2 video to HDR10 hevc video, > with or without this flag. If the resolution changes but the codec does not change its supported also if the 2nd (codec) starts as a seperate AVStream, ffplay should handle it correctly too (meaning you can switch to it and watch it) similarly ffmpeg should be able to handle it with multiple AVStreams > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > diff --git a/libavformat/avformat.h b/libavformat/avformat.h > > > > > index b6c63e2237..2e5232c96d 100644 > > > > > --- a/libavformat/avformat.h > > > > > +++ b/libavformat/avformat.h > > > > > @@ -1436,6 +1436,8 @@ typedef struct AVFormatContext { > > > > > #define AVFMT_FLAG_FAST_SEEK 0x80000 ///< Enable fast, but > > inaccurate > > > > seeks for some formats > > > > > #define AVFMT_FLAG_AUTO_BSF 0x200000 ///< Add bitstream filters as > > > > requested by the muxer > > > > > > > > > > +#define AVFMT_FLAG_ALLOW_CODEC_CHANGES 0x400000 ///< Allow > > > > AVStream.codecpar to be updated midstream if input changes (e.g. > > MPEG-TS ES > > > > stream_type changes) > > > > > + > > > > > /** > > > > > * Maximum number of bytes read from input in order to determine > > > > stream > > > > > * properties. Used when reading the global header and in > > > > > diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c > > > > > index deb69a0548..ed4ff580e5 100644 > > > > > --- a/libavformat/mpegts.c > > > > > +++ b/libavformat/mpegts.c > > > > > @@ -2510,7 +2510,9 @@ static void pmt_cb(MpegTSFilter *filter, const > > > > uint8_t *section, int section_len > > > > > if (!st) > > > > > goto out; > > > > > > > > > > - if (pes && pes->stream_type != stream_type) > > > > > + if (pes && (!pes->stream_type || > > > > > + (pes->stream_type != stream_type && > > > > > + !!(ts->stream->flags & > > > > AVFMT_FLAG_ALLOW_CODEC_CHANGES)))) > > > > > mpegts_set_stream_info(st, pes, stream_type, > > prog_reg_desc); > > > > > > > > > > add_pid_to_program(prg, pid); > > > > > diff --git a/libavformat/options_table.h > > b/libavformat/options_table.h > > > > > index e2e690fd2a..811dd342cc 100644 > > > > > --- a/libavformat/options_table.h > > > > > +++ b/libavformat/options_table.h > > > > > @@ -50,6 +50,7 @@ static const AVOption avformat_options[] = { > > > > > {"sortdts", "try to interleave outputted packets by dts", 0, > > > > AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_SORT_DTS }, INT_MIN, INT_MAX, D, > > > > .unit = "fflags"}, > > > > > {"fastseek", "fast but inaccurate seeks", 0, AV_OPT_TYPE_CONST, > > {.i64 = > > > > AVFMT_FLAG_FAST_SEEK }, INT_MIN, INT_MAX, D, .unit = "fflags"}, > > > > > {"nobuffer", "reduce the latency introduced by optional buffering", > > 0, > > > > AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_NOBUFFER }, 0, INT_MAX, D, .unit > > = > > > > "fflags"}, > > > > > +{"allow_codec_changes", "allow AVStream.codecpar to change at > > runtime > > > > if input changes", 0, AV_OPT_TYPE_CONST, { .i64 = > > > > AVFMT_FLAG_ALLOW_CODEC_CHANGES }, 0, 0, D, .unit = "fflags" }, > > > > > > > > If the option is user settable then ffmpeg/ffplay should possibly > > print a > > > > warning, that they do not support this if the user forces the flag > > > > > > > > > > Well, it's not as if they don't support it at all ... they consume the > > > option and set the flag, and the demuxer does what it's supposed to. > > > In case of ffplay, with -fflags +allow_codec_changes it's actually able > > to > > > play 1_poc.mp4 and render a partially decoded image. > > > > > > > > Anyway, what would this warning look like? > > > I'm having a hard time coming up with a warning message that isn't > > > misleading or confusing. > > > Would you like to suggest one? Would something like this work: > > > > > > if (!!(ic->flags & AVFMT_FLAG_ALLOW_CODEC_CHANGES)) > > > av_log(NULL, AV_LOG_WARNING, "downstream support for > > > allow_codec_changes is not implemented"); > > > > I was thinking more along the lines of the > > "--disable-safe-bitstream-reader" > > help text: > > disable buffer boundary checking in bitreaders > > (This disables some security checks and can > > cause undefined behavior, > > crashes and arbitrary code execution, it may > > be faster, but > > should only be used with trusted input) > > > > Bascially, what the goal here is, is to explain to the user that with this > > flag > > they are potentially giving the input file arbitrary code execution on > > their > > machiene > > > > > No, that's not what this flag does, and I will not document it as such. > The arbitrary code execution is not a feature controlled by this flag... if > such thing exists -- it was not added by me. > This flag only controls the re-probing of the input stream when PMT ES > stream_type changes, that is all. > > The ffprobe 1_poc.mp4 segfault was due to a previously unknown defect > in demux.c codec_close probing helper function, for which I provided a fix. If you look at the documentation: " * @li an @ref AVFormatContext.streams "array" of AVStreams, which describe all * elementary streams stored in the file. AVStreams are typically referred to * using their index in this array. " Now consider that one presentation uses first mpeg2 SDR and later HEVC. An elementary stream can NEVER mix mpeg2 and HEVC these must be 2 seperate elementary streams. because either violates the others syntax. To describe ALL ES in one array the mpeg2 SDR stream at the begin and the hevc HDR stream at the end must be in the same array at the same time. That implies that they are distinct AVStream s And also a muxer writing this will take the AVStreams from the array. That will work if all streams are in there. Maybe if they appears later it will work too. But if streams change their type while muxing everything is going to fall appart. I think the problem arrises because we are missing a layer. If we add a presentation layer for edit lists, that becomes a very convenient place to switch codecs while preserving all the stuff below seperately all that said, anything that works is fine with me. I just want to make sure the documentation is clear (which can be improved), and that we have a plan how everything works together and for everyone before making a final decission on design. Iam fine with either AVStreams changing or not but it needs to be consistent and thought through and working. thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Those who are best at talking, realize last or never when they are wrong. [-- Attachment #1.2: signature.asc --] [-- Type: application/pgp-signature, Size: 195 bytes --] [-- Attachment #2: Type: text/plain, Size: 251 bytes --] _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-07-04 1:30 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2025-06-22 18:10 [FFmpeg-devel] [PATCH] avformat/mpegts: Add AVFMT_FLAG_ALLOW_CODEC_CHANGES Pavel Koshevoy 2025-06-28 1:39 ` Pavel Koshevoy 2025-06-28 23:03 ` Michael Niedermayer 2025-06-29 2:49 ` Pavel Koshevoy 2025-06-30 1:01 ` Michael Niedermayer 2025-06-30 3:45 ` Pavel Koshevoy 2025-07-04 1:30 ` Michael Niedermayer
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git