[FFmpeg-cvslog] avformat/demux: extract extradata from packets when context update is requested

James Almer git at videolan.org
Wed Apr 24 06:16:49 EEST 2024


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Sun Apr 21 12:18:51 2024 -0300| [757367e068679e0f2884262ab7c1f53de490e6ad] | committer: James Almer

avformat/demux: extract extradata from packets when context update is requested

If the demuxer doesn't set extradata in the stream's codecpar, a
need_context_update request will delete the previously extracted extradata in
the stream's internal AVCodecContext.
As we can't ensure the old extradata is valid for the stream in its post
context update request state, try to get extradata from the new packet instead
of attempting to preserve the old in some form.

Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=757367e068679e0f2884262ab7c1f53de490e6ad
---

 libavformat/demux.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index abfd5fee7d..ecefe7e0a7 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -1319,6 +1319,8 @@ fail:
     return ret;
 }
 
+static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt);
+
 static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
 {
     FFFormatContext *const si = ffformatcontext(s);
@@ -1373,6 +1375,16 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
                 return ret;
             }
 
+            if (!sti->avctx->extradata) {
+                sti->extract_extradata.inited = 0;
+
+                ret = extract_extradata(si, st, pkt);
+                if (ret < 0) {
+                    av_packet_unref(pkt);
+                    return ret;
+                }
+            }
+
             sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id);
 
             sti->need_context_update = 0;
@@ -2427,6 +2439,7 @@ static int extract_extradata_init(AVStream *st)
     if (!ret)
         goto finish;
 
+    av_bsf_free(&sti->extract_extradata.bsf);
     ret = av_bsf_alloc(f, &sti->extract_extradata.bsf);
     if (ret < 0)
         return ret;



More information about the ffmpeg-cvslog mailing list