PR #26200 opened by Zhao Zhili (quink) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26200 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26200.patch
# Summary of changes The session's source image buffer attributes were only created for software pixel formats. Without them VideoToolbox writes video_full_range_flag as 0, so full range hardware frames were tagged limited range in the bitstream while avctx->color_range said full. Create the attributes for AV_PIX_FMT_VIDEOTOOLBOX, naming the format from sw_pix_fmt, which hw_frames_ctx provides. They stay optional on this path: without a sw_pix_fmt, or with a format that has no CoreVideo equivalent for the requested range, the session is created without them as before. >From 49d3f3c37f83185c447f8f2f8240edcdd0c4bdc2 Mon Sep 17 00:00:00 2001 From: Zhao Zhili <[email protected]> Date: Thu, 19 Nov 2026 18:11:41 +0800 Subject: [PATCH] avcodec/videotoolboxenc: signal full range for hardware frame input The session's source image buffer attributes were only created for software pixel formats. Without them VideoToolbox writes video_full_range_flag as 0, so full range hardware frames were tagged limited range in the bitstream while avctx->color_range said full. Create the attributes for AV_PIX_FMT_VIDEOTOOLBOX, naming the format from sw_pix_fmt, which hw_frames_ctx provides. They stay optional on this path: without a sw_pix_fmt, or with a format that has no CoreVideo equivalent for the requested range, the session is created without them as before. --- libavcodec/videotoolboxenc.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c index 36a08d0a094..712e5490769 100644 --- a/libavcodec/videotoolboxenc.c +++ b/libavcodec/videotoolboxenc.c @@ -1123,12 +1123,28 @@ static int create_cv_pixel_buffer_info(AVCodecContext* avctx, CFNumberRef width_num = NULL; CFNumberRef height_num = NULL; CFMutableDictionaryRef pixel_buffer_info = NULL; + enum AVPixelFormat fmt = avctx->pix_fmt; int cv_color_format; - int status = get_cv_pixel_format(avctx, - avctx->pix_fmt, - avctx->color_range, - &cv_color_format, - NULL); + int status; + + if (fmt == AV_PIX_FMT_VIDEOTOOLBOX) { + /* Hardware frames carry no format of their own. The attributes are + * optional here, so a caller that gives no usable sw_pix_fmt keeps + * the session defaults instead of failing to open. + */ + fmt = avctx->sw_pix_fmt; + if (!av_map_videotoolbox_format_from_pixfmt2( + fmt, avctx->color_range == AVCOL_RANGE_JPEG)) { + *dict = NULL; + return 0; + } + } + + status = get_cv_pixel_format(avctx, + fmt, + avctx->color_range, + &cv_color_format, + NULL); if (status) return status; pixel_buffer_info = CFDictionaryCreateMutable( @@ -1796,11 +1812,9 @@ static int vtenc_configure_encoder(AVCodecContext *avctx) kCFBooleanTrue); } - if (avctx->pix_fmt != AV_PIX_FMT_VIDEOTOOLBOX) { - status = create_cv_pixel_buffer_info(avctx, &pixel_buffer_info); - if (status) - goto init_cleanup; - } + status = create_cv_pixel_buffer_info(avctx, &pixel_buffer_info); + if (status) + goto init_cleanup; vtctx->dts_delta = vtctx->has_b_frames ? -1 : 0; -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
