Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avcodec/av1dec: fix handling of frame size and format changes (PR #21316)
@ 2025-12-29 20:40 cgutman via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: cgutman via ffmpeg-devel @ 2025-12-29 20:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: cgutman

PR #21316 opened by cgutman
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21316
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21316.patch

`ff_get_format()` must be called to reinitialize the hwaccel when the pixel format or frame size changes.

This also fixes a bug where `ff_get_format()` was never called when `AVCodecContext.pix_fmt` was initialized by the user.

This PR supersedes #20720 and fixes a regression introduced by 194414f.


>From 87ac3d092472db9676a8075a681194308554fb37 Mon Sep 17 00:00:00 2001
From: Cameron Gutman <aicommander@gmail.com>
Date: Mon, 29 Dec 2025 14:19:37 -0600
Subject: [PATCH] avcodec/av1dec: fix handling of frame size and format changes

ff_get_format() must be called to reinitialize the hwaccel when the
pixel format or frame size changes.

This also fixes a bug where ff_get_format() was never called when
AVCodecContext.pix_fmt was initialized by the user.

Signed-off-by: Cameron Gutman <aicommander@gmail.com>
---
 libavcodec/av1dec.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 1dffc7c1b9..6b278dc958 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -656,12 +656,6 @@ static int get_pixel_format(AVCodecContext *avctx)
     *fmtp++ = pix_fmt;
     *fmtp = AV_PIX_FMT_NONE;
 
-    for (int i = 0; pix_fmts[i] != pix_fmt; i++)
-        if (pix_fmts[i] == avctx->pix_fmt) {
-            s->pix_fmt = pix_fmt;
-            return 1;
-        }
-
     ret = ff_get_format(avctx, pix_fmts);
 
     /**
@@ -768,6 +762,7 @@ static av_cold int av1_decode_free(AVCodecContext *avctx)
 static int set_context_with_sequence(AVCodecContext *avctx,
                                      const AV1RawSequenceHeader *seq)
 {
+    AV1DecContext *s = avctx->priv_data;
     int width = seq->max_frame_width_minus_1 + 1;
     int height = seq->max_frame_height_minus_1 + 1;
 
@@ -804,7 +799,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
         int ret = ff_set_dimensions(avctx, width, height);
         if (ret < 0)
             return ret;
-    }
+        s->pix_fmt = AV_PIX_FMT_NONE;
+    } else if (s->pix_fmt != get_sw_pixel_format(avctx, seq))
+        s->pix_fmt = AV_PIX_FMT_NONE;
 
     if (seq->timing_info_present_flag)
         avctx->framerate = ff_av1_framerate(1LL + seq->timing_info.num_ticks_per_picture_minus_1,
@@ -820,6 +817,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 static int update_context_with_frame_header(AVCodecContext *avctx,
                                             const AV1RawFrameHeader *header)
 {
+    AV1DecContext *s = avctx->priv_data;
     AVRational aspect_ratio;
     int width = header->frame_width_minus_1 + 1;
     int height = header->frame_height_minus_1 + 1;
@@ -831,6 +829,7 @@ static int update_context_with_frame_header(AVCodecContext *avctx,
         ret = ff_set_dimensions(avctx, width, height);
         if (ret < 0)
             return ret;
+        s->pix_fmt = AV_PIX_FMT_NONE;
     }
 
     av_reduce(&aspect_ratio.num, &aspect_ratio.den,
@@ -924,12 +923,6 @@ static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f)
     AVFrame *frame;
     int ret;
 
-    ret = update_context_with_frame_header(avctx, header);
-    if (ret < 0) {
-        av_log(avctx, AV_LOG_ERROR, "Failed to update context with frame header\n");
-        return ret;
-    }
-
     ret = ff_progress_frame_get_buffer(avctx, &f->pf, AV_GET_BUFFER_FLAG_REF);
     if (ret < 0)
         goto fail;
@@ -1234,6 +1227,12 @@ static int get_current_frame(AVCodecContext *avctx)
         avctx->skip_frame >= AVDISCARD_ALL)
         return 0;
 
+    ret = update_context_with_frame_header(avctx, s->raw_frame_header);
+    if (ret < 0) {
+        av_log(avctx, AV_LOG_ERROR, "Failed to update context with frame header\n");
+        return ret;
+    }
+
     if (s->pix_fmt == AV_PIX_FMT_NONE) {
         ret = get_pixel_format(avctx);
         if (ret < 0) {
@@ -1317,8 +1316,6 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
 
             s->operating_point_idc = s->raw_seq->operating_point_idc[s->operating_point];
 
-            s->pix_fmt = AV_PIX_FMT_NONE;
-
             if (FF_HW_HAS_CB(avctx, decode_params)) {
                 ret = FF_HW_CALL(avctx, decode_params, AV1_OBU_SEQUENCE_HEADER,
                                  s->seq_data_ref->data, s->seq_data_ref->size);
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-12-29 20:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-29 20:40 [FFmpeg-devel] [PATCH] avcodec/av1dec: fix handling of frame size and format changes (PR #21316) cgutman via ffmpeg-devel

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