Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 2/2 v3] avformat/demux: extract extradata from packets when context update is requested
Date: Mon, 22 Apr 2024 00:01:15 -0300
Message-ID: <20240422030115.1296-1-jamrial@gmail.com> (raw)
In-Reply-To: <AS8P250MB0744D640566BE823894028AD8F132@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM>

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@gmail.com>
---
 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;
-- 
2.44.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".

  reply	other threads:[~2024-04-22  3:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-20 23:43 [FFmpeg-devel] [PATCH 1/2] avcodec/codec_par: always clear extradata_size in avcodec_parameters_to_context() James Almer
2024-04-20 23:43 ` [FFmpeg-devel] [PATCH 2/2] avformat/demux: extract extradata from packets when context update is requested James Almer
2024-04-21 15:18   ` [FFmpeg-devel] [PATCH 2/2 v2] " James Almer
2024-04-21 15:32     ` Andreas Rheinhardt
2024-04-21 15:52       ` James Almer
2024-04-21 16:48         ` Andreas Rheinhardt
2024-04-22  3:01           ` James Almer [this message]
2024-04-23 13:57 ` [FFmpeg-devel] [PATCH 1/2] avcodec/codec_par: always clear extradata_size in avcodec_parameters_to_context() James Almer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240422030115.1296-1-jamrial@gmail.com \
    --to=jamrial@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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