Commit 246d0da2c1 for ffmpeg
commit 246d0da2c1b1f1924c9ba3b585a1ff3582d0e3f1
Author: Zhao Zhili <quinkblack@foxmail.com>
Date: Mon Oct 19 21:11:12 2026 +0800
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 <zhilizhao@tencent.com>
diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index 5a39a1b0c0..7bde30cb81 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;