PR #23441 opened by James Almer (jamrial)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23441
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23441.patch

In case of an encoding scenario using a hardware encoder, 
AVCodecContext->pix_fmt may be a hwaccel format that conveys no information 
muxers can use when looking at its descriptor, as is the case of bitdepth.
As such, if sw_pix_fmt is set, copy that value instead.

Fixes issue #23420


>From ccbb1be29bad93ae0f2abd8d16d4dc0450e2aa3b Mon Sep 17 00:00:00 2001
From: James Almer <[email protected]>
Date: Wed, 10 Jun 2026 14:06:25 -0300
Subject: [PATCH] avcodec/codec_par: copy AVCodecContext sw_pix_fmt instead of
 pix_fmt to AVCodecParameters if set

In case of an encoding scenario using a hardware encoder, 
AVCodecContext->pix_fmt may be a
hwaccel format that conveys no information muxers can use when looking at its 
descriptor,
as is the case of bitdepth.
As such, if sw_pix_fmt is set, copy that value instead.

Fixes issue #23420

Signed-off-by: James Almer <[email protected]>
---
 libavcodec/codec_par.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c
index ddf349ceea..ddc58d1324 100644
--- a/libavcodec/codec_par.c
+++ b/libavcodec/codec_par.c
@@ -154,7 +154,8 @@ int avcodec_parameters_from_context(AVCodecParameters *par,
 
     switch (par->codec_type) {
     case AVMEDIA_TYPE_VIDEO:
-        par->format              = codec->pix_fmt;
+        par->format              = codec->sw_pix_fmt != AV_PIX_FMT_NONE ?
+                                   codec->sw_pix_fmt : codec->pix_fmt;
         par->width               = codec->width;
         par->height              = codec->height;
         par->field_order         = codec->field_order;
@@ -219,6 +220,7 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
 
     switch (par->codec_type) {
     case AVMEDIA_TYPE_VIDEO:
+        codec->sw_pix_fmt             =
         codec->pix_fmt                = par->format;
         codec->width                  = par->width;
         codec->height                 = par->height;
-- 
2.52.0

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

Reply via email to