This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit c9c95f6f322dedf1a1b734023201e9e060cf8d42
Author:     James Almer <[email protected]>
AuthorDate: Tue Dec 16 19:20:40 2025 -0300
Commit:     James Almer <[email protected]>
CommitDate: Tue Dec 16 22:45:17 2025 -0300

    avformat/demux: ensure avformat_find_stream_info updates internal stream 
contexts
    
    read_frame_internal() may result in a stream being modified without also
    returning a packet from it. Given said function only bothered to update the
    internal stream context for the returned packet, the result would be a 
desync
    between the stream's AVCodecParameters and the internal AVCodecContext.
    
    This change makes sure all streams are updated within the
    avformat_find_stream_info() loop.
    
    Fixes #YWH-PGM40646-20
    
    Signed-off-by: James Almer <[email protected]>
---
 libavformat/demux.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 934eb80553..b1918d2110 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -186,6 +186,8 @@ static int init_input(AVFormatContext *s, const char 
*filename,
                                   s, 0, s->format_probesize);
 }
 
+static int codec_close(FFStream *sti);
+
 static int update_stream_avctx(AVFormatContext *s)
 {
     int ret;
@@ -196,6 +198,14 @@ static int update_stream_avctx(AVFormatContext *s)
         if (!sti->need_context_update)
             continue;
 
+        if (avcodec_is_open(sti->avctx)) {
+            av_log(s, AV_LOG_DEBUG, "Demuxer context update while decoder is 
open, closing and trying to re-open\n");
+            ret = codec_close(sti);
+            sti->info->found_decoder = 0;
+            if (ret < 0)
+                return ret;
+        }
+
         /* close parser, because it depends on the codec */
         if (sti->parser && sti->avctx->codec_id != st->codecpar->codec_id) {
             av_parser_close(sti->parser);
@@ -2682,6 +2692,13 @@ int avformat_find_stream_info(AVFormatContext *ic, 
AVDictionary **options)
             break;
         }
 
+        /* read_frame_internal() in a previous iteration of this loop may
+         * have made changes to streams without returning a packet for them.
+         * Handle that here. */
+        ret = update_stream_avctx(ic);
+        if (ret < 0)
+            goto unref_then_goto_end;
+
         /* check if one codec still needs to be handled */
         for (i = 0; i < ic->nb_streams; i++) {
             AVStream *const st  = ic->streams[i];

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to