From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id C2BAC4F4D9 for ; Tue, 17 Jun 2025 14:00:55 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 309DC68C9A2; Tue, 17 Jun 2025 17:00:52 +0300 (EEST) Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 9C45768C4C1 for ; Tue, 17 Jun 2025 17:00:45 +0300 (EEST) Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-607ec30df2bso10605503a12.1 for ; Tue, 17 Jun 2025 07:00:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750168845; x=1750773645; darn=ffmpeg.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=WkN7d+qfWKpcbu94ErR7Vra0wDTyRYIkfiJXE2Vc/8g=; b=lK4PJU4gxyqICYrMn9KiCUNd7USMaeB4cjBjX5QlMVcwv3Tw+IWREM6B4HUcpqHesB uhbXczZ/2pXntnlyPOUpQPkRDF+7X25UbrGHwjJOvgkrP1SOXQ2JV4WuP0knnL7bPWi3 VRWsLG4Q1Oxc2Y7zfM4DqWUuy/3uHFjNz+IWks9jLsp2iUuGVr/tWDtyul7CFHqm9xvL 6IZGHsYJDLTOCT0bntnjgFSCEh8RnRl+d4hrnhiX2G7gVY6Gwpe0/4VM0kn5dxnnBYsW 9mOsTr2cpZbVnNMv9WFmg3kLkzC1vdx+evRgJwkpAQ8lrRsFe98iqrlWfSVl25dqa1LI kuww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750168845; x=1750773645; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WkN7d+qfWKpcbu94ErR7Vra0wDTyRYIkfiJXE2Vc/8g=; b=O92/bBB8blbnlmoua2aaRT1TRaX2TzhD8L+q5xMjvrV9Z2I5eu7rblxa9KQUgzGq+d iEW/tBTD/DtAv6jrn+Wet3Nq45RFvCRrgD1adXO736XomIL7USUYLk+lpY8DD9TfkPgZ XZt7OlKZATEr2NWgoHCN/2UadSy2/WimdqJaDGW6pnp62zzMQ/98Sk8MnEcUe2XjF2dM /b44BXldbVHkgacglnqJbVqMQfmh23ukSrnjLIqhF+YRuc8y3xuNBxm2OYlVMFxIPdYQ rmfgJkhG+GR2mEa7i7Mm5KbAOV3sHduqReVF2UjqheQ19QcL5g7YKbuMaPIugMf0u3k6 MPKg== X-Gm-Message-State: AOJu0Yy/j52rQUoIYtcJ58ZwTEaQo0NQs45jqtQDOM45GGjxd/WnDAkj BDAV0TXh7a4yaZIzEhiuMv2rTxq1u8u2wjpEqBozIexsYbMe/gRHfW1ed7X014D303SmSaH/QbH xAG/FZsnW6I+LCLnVTv2DFa9XuHTc0gXFnPp2 X-Gm-Gg: ASbGncs/FLUqFP03HlO5/BJsZhYXE7DpIHmOgJ7eamAiaLLvvcffKMlmnfaWYuDPC8K HQQT7PSsGHL1FwNftzKmGbGK3g8gxPLLeDH+4+As5F30MBugtONBVoXHhnVDHNFt9/JtBZAF2a6 mqJTmze1OP02mVElIY2YzyvEWU1YJ8pYrdVRxfqa/F/tmjl5xqaTS8/lQqpVQaOAseSOci/04Sk StK9Y6oifH5exjf X-Google-Smtp-Source: AGHT+IGDyCRK6EjjofpdTPPhWEZSuJium7Yqja7VFYwKS/w5vJbLU8/XmxSWrcG8Yhe399jQTqWfSMAjYOZiXLfGNf8= X-Received: by 2002:a17:907:3da0:b0:ad5:2328:e39b with SMTP id a640c23a62f3a-adfad53b7b4mr1478416966b.31.1750168844409; Tue, 17 Jun 2025 07:00:44 -0700 (PDT) MIME-Version: 1.0 References: <20250615205008.17903-1-pkoshevoy@gmail.com> In-Reply-To: From: Pavel Koshevoy Date: Tue, 17 Jun 2025 08:00:37 -0600 X-Gm-Features: AX0GCFvIXCaLJMERcFIGm8NpL7hBbzRA1IO0Z1p4MdbtrIIbPdK4d9W0NyTXIGg Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: Re: [FFmpeg-devel] [PATCH] avformat/demux: Add allow_codec_changes option to AVFormatContext X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Tue, Jun 17, 2025, 07:55 Pavel Koshevoy wrote: > Ping. I think I've addressed the concerns raised with the previous > patch. > Please let me know if I may commit this... it is a segfault fix, so it > probably should get some review priority. > > Thank you, > Pavel > > > On Sun, Jun 15, 2025, 14:50 Pavel Koshevoy wrote: > >> Make runtime AVStream.codecpar codec_id updates optional and disabled >> by default, so that avformat API clients can enable this feature >> explicitly >> when they add support for runtime codec changes. >> >> Accordingly, codec_close should not assume that the codec_id cannot >> change. >> This fixes 'ffprobe 1_poc.mp4' segfault introduced with >> commit 0021484d05f9b0f032fa319399de6e24eea0c04f >> --- >> doc/formats.texi | 6 ++++++ >> libavformat/avformat.h | 10 ++++++++++ >> libavformat/demux.c | 8 +++++++- >> libavformat/mpegts.c | 4 +++- >> libavformat/options_table.h | 1 + >> tests/fate/demux.mak | 2 +- >> 6 files changed, 28 insertions(+), 3 deletions(-) >> >> diff --git a/doc/formats.texi b/doc/formats.texi >> index 876a9e92b3..d18613f8bd 100644 >> --- a/doc/formats.texi >> +++ b/doc/formats.texi >> @@ -228,6 +228,12 @@ would require too many resources due to a large >> number of streams. >> Skip estimation of input duration if it requires an additional probing >> for PTS at end of file. >> At present, applicable for MPEG-PS and MPEG-TS. >> >> +@item allow_codec_changes @var{bool} (@emph{input}) >> +Allow AVStream.codecpar codec_type and codec_id to change at runtime >> +(for example when MPEG-TS PMT ES stream_type changes at runtime). >> +This is disabled by default, because most clients of avformat API >> +do not support random mid-stream codec changes. >> + >> @item duration_probesize @var{integer} (@emph{input}) >> Set probing size, in bytes, for input duration estimation when it >> actually requires >> an additional probing for PTS at end of file (at present: MPEG-PS and >> MPEG-TS). >> diff --git a/libavformat/avformat.h b/libavformat/avformat.h >> index b6c63e2237..c6956626b5 100644 >> --- a/libavformat/avformat.h >> +++ b/libavformat/avformat.h >> @@ -1884,6 +1884,16 @@ typedef struct AVFormatContext { >> * @see skip_estimate_duration_from_pts >> */ >> int64_t duration_probesize; >> + >> + /** >> + * Allow AVStream.codecpar codec_type and codec_id to change at >> runtime >> + * (for example when MPEG-TS PMT ES stream_type changes at runtime). >> + * This is disabled by default, because most clients of avformat API >> + * do not support random mid-stream codec changes. >> + * - muxing: unused >> + * - demuxing: set by user >> + */ >> + int allow_codec_changes; >> } AVFormatContext; >> > Oops, I forgot to bump up the minor version. >> /** >> diff --git a/libavformat/demux.c b/libavformat/demux.c >> index ecd4f40da9..3749ab67a3 100644 >> --- a/libavformat/demux.c >> +++ b/libavformat/demux.c >> @@ -1292,9 +1292,15 @@ static int codec_close(FFStream *sti) >> { >> AVCodecContext *avctx_new = NULL; >> AVCodecParameters *par_tmp = NULL; >> + const AVCodec *new_codec = NULL; >> int ret; >> >> - avctx_new = avcodec_alloc_context3(sti->avctx->codec); >> + new_codec = >> + (sti->avctx->codec_id != sti->pub.codecpar->codec_id) ? >> + avcodec_find_decoder(sti->pub.codecpar->codec_id) : >> + sti->avctx->codec; >> + >> + avctx_new = avcodec_alloc_context3(new_codec); >> if (!avctx_new) { >> ret = AVERROR(ENOMEM); >> goto fail; >> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c >> index deb69a0548..0c78e870bb 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->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..e949d60c3e 100644 >> --- a/libavformat/options_table.h >> +++ b/libavformat/options_table.h >> @@ -106,6 +106,7 @@ static const AVOption avformat_options[] = { >> {"skip_estimate_duration_from_pts", "skip duration calculation in >> estimate_timings_from_pts", OFFSET(skip_estimate_duration_from_pts), >> AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, D}, >> {"max_probe_packets", "Maximum number of packets to probe a codec", >> OFFSET(max_probe_packets), AV_OPT_TYPE_INT, { .i64 = 2500 }, 0, INT_MAX, D >> }, >> {"duration_probesize", "Maximum number of bytes to probe the durations >> of the streams in estimate_timings_from_pts", OFFSET(duration_probesize), >> AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX, D}, >> +{"allow_codec_changes", "Allow AVStream.codecpar codec_type and codec_id >> to change at runtime", OFFSET(allow_codec_changes), AV_OPT_TYPE_BOOL, {.i64 >> = 0}, 0, 1, D}, >> {NULL}, >> }; >> >> diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak >> index ead5ad4b10..4a39e950b9 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 -allow_codec_changes 1 >> >> 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".