PR #25326 opened by Zhao Zhili (quink)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25326
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25326.patch

AV_PIX_FMT_FLAG_PLANAR does not exclude semi-planar formats such as
NV12, so they were split into .y/.U/.V files with corrupted chroma:

    ffmpeg -f lavfi -i testsrc -frames:v 1 -pix_fmt nv12 \
        -c:v rawvideo out.%03d.y


>From f192d1232afd3918a1cd7df66217025cbc8e611a Mon Sep 17 00:00:00 2001
From: Zhao Zhili <[email protected]>
Date: Mon, 19 Oct 2026 21:11:12 +0800
Subject: [PATCH] avformat/img2enc: Split rawvideo planes only for fully planar
 formats

AV_PIX_FMT_FLAG_PLANAR does not exclude semi-planar formats such as
NV12, so they were split into .y/.U/.V files with corrupted chroma:

    ffmpeg -f lavfi -i testsrc -frames:v 1 -pix_fmt nv12 \
        -c:v rawvideo out.%03d.y

Signed-off-by: Zhao Zhili <[email protected]>
---
 libavformat/img2enc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index 5a39a1b0c04..7bde30cb815 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -106,7 +106,12 @@ static int write_header(AVFormatContext *s)
                              && !av_strcasecmp(str + 1, "y")
                              && s->nb_streams == 1
                              && desc
-                             &&(desc->flags & AV_PIX_FMT_FLAG_PLANAR)
+                            /* Semi-planar formats such as NV12 keep several
+                             * components in one plane, so splitting per
+                             * component needs one plane per component.
+                             */
+                             && av_pix_fmt_count_planes(st->codecpar->format)
+                                == desc->nb_components
                              && desc->nb_components >= 3;
     }
     img->img_number = img->start_img_number;
-- 
2.54.0

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

Reply via email to