PR #26379 opened by wood1986 URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26379 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26379.patch
- Select ConstantQualityFactor on Apple OS 27 and newer. Keep Quality on older systems. - Load the new key dynamically for older SDK compatibility. - Log unsupported properties and fall back to Quality. Report other quality errors explicitly. Co-authored-by: Copilot <[email protected]> Copilot-Session: 171f7cdc-84c1-473d-aa5a-17d23d196763 # Summary of changes Briefly describe what this PR does and why. <!-- If this PR requires new FATE test samples, attach them to the PR and list their target paths below (relative to the fate-suite root). Attached filenames must match the sample's filename: ```fate-samples # e.g. vorbis/new-sample.ogg ``` --> >From 8516b1c4343b3ca8ca62b4e12330f9bcb4e23074 Mon Sep 17 00:00:00 2001 From: wood1986 <[email protected]> Date: Thu, 26 Nov 2026 12:22:08 -0700 Subject: [PATCH] feat(videotoolbox): support constant quality factor on Apple OS 27 - Select ConstantQualityFactor on Apple OS 27 and newer. Keep Quality on older systems. - Load the new key dynamically for older SDK compatibility. - Log unsupported properties and fall back to Quality. Report other quality errors explicitly. Co-authored-by: Copilot <[email protected]> Copilot-Session: 171f7cdc-84c1-473d-aa5a-17d23d196763 --- libavcodec/videotoolboxenc.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c index 36a08d0a094..9c5c96e430e 100644 --- a/libavcodec/videotoolboxenc.c +++ b/libavcodec/videotoolboxenc.c @@ -141,6 +141,7 @@ static struct{ CFStringRef kVTProfileLevel_HEVC_Main42210_AutoLevel; CFStringRef kVTCompressionPropertyKey_RealTime; + CFStringRef kVTCompressionPropertyKey_ConstantQualityFactor; CFStringRef kVTCompressionPropertyKey_TargetQualityForAlpha; CFStringRef kVTCompressionPropertyKey_PrioritizeEncodingSpeedOverQuality; CFStringRef kVTCompressionPropertyKey_ConstantBitRate; @@ -214,6 +215,8 @@ static void loadVTEncSymbols(void){ GET_SYM(kVTProfileLevel_HEVC_Main42210_AutoLevel, "HEVC_Main42210_AutoLevel"); GET_SYM(kVTCompressionPropertyKey_RealTime, "RealTime"); + GET_SYM(kVTCompressionPropertyKey_ConstantQualityFactor, + "ConstantQualityFactor"); GET_SYM(kVTCompressionPropertyKey_TargetQualityForAlpha, "TargetQualityForAlpha"); GET_SYM(kVTCompressionPropertyKey_PrioritizeEncodingSpeedOverQuality, @@ -1320,6 +1323,7 @@ static int vtenc_create_encoder(AVCodecContext *avctx, } if (avctx->flags & AV_CODEC_FLAG_QSCALE || avctx->global_quality > 0) { + CFStringRef quality_key = kVTCompressionPropertyKey_Quality; float factor = (avctx->flags & AV_CODEC_FLAG_QSCALE) ? FF_QP2LAMBDA * 100.0f : 100.0f; Float32 quality = fminf(avctx->global_quality / factor, 1.0f); @@ -1328,10 +1332,25 @@ static int vtenc_create_encoder(AVCodecContext *avctx, &quality); if (!quality_num) return AVERROR(ENOMEM); + if (__builtin_available(macOS 27.0, iOS 27.0, tvOS 27.0, visionOS 27.0, *)) + quality_key = compat_keys.kVTCompressionPropertyKey_ConstantQualityFactor; + status = VTSessionSetProperty(vtctx->session, - kVTCompressionPropertyKey_Quality, + quality_key, quality_num); + if (status == kVTPropertyNotSupportedErr && + quality_key == compat_keys.kVTCompressionPropertyKey_ConstantQualityFactor) { + av_log(avctx, AV_LOG_WARNING, + "ConstantQualityFactor is not supported by the encoder. Falling back to Quality.\n"); + status = VTSessionSetProperty(vtctx->session, + kVTCompressionPropertyKey_Quality, + quality_num); + } CFRelease(quality_num); + if (status) { + av_log(avctx, AV_LOG_ERROR, "Error setting quality property: %d\n", status); + return AVERROR_EXTERNAL; + } } else if (avctx->codec_id != AV_CODEC_ID_PRORES) { bit_rate_num = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
