Commit 2934bf6f6a for ffmpeg
commit 2934bf6f6ae8497bb2caa807e8850890cd655aea
Author: Zhao Zhili <quinkblack@foxmail.com>
Date: Sat Nov 28 00:23:23 2026 +0800
avcodec/videotoolboxenc: fix unspecified range for single-range formats
An unspecified color range was always taken as MPEG range. Some source
formats exist in CoreVideo in one range only, such as BGRA in full
range, so the encoder failed to open for BGRA input without a range.
Fall back to the range the format has, and only warn about a guess
when both ranges exist.
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 6223e38e77..71ed2609ac 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -1074,10 +1074,17 @@ static uint32_t get_cv_pixel_format(enum AVPixelFormat fmt,
enum AVColorRange range,
int *range_guessed)
{
- *range_guessed = range != AVCOL_RANGE_MPEG && range != AVCOL_RANGE_JPEG;
+ uint32_t video_range, full_range;
- //MPEG range is used when no range is set
- return av_map_videotoolbox_format_from_pixfmt2(fmt, range == AVCOL_RANGE_JPEG);
+ *range_guessed = 0;
+ if (range == AVCOL_RANGE_MPEG || range == AVCOL_RANGE_JPEG)
+ return av_map_videotoolbox_format_from_pixfmt2(fmt, range == AVCOL_RANGE_JPEG);
+
+ //MPEG range is used when no range is set, unless the format has none
+ video_range = av_map_videotoolbox_format_from_pixfmt2(fmt, false);
+ full_range = av_map_videotoolbox_format_from_pixfmt2(fmt, true);
+ *range_guessed = video_range && full_range;
+ return video_range ? video_range : full_range;
}
static void add_color_attr(AVCodecContext *avctx, CFMutableDictionaryRef dict) {