* Re: [FFmpeg-devel] [PATCH v2] lavc/videotoolboxenc: Add spatial_aq option
[not found] <20241216092829.1237-1-dennis@obsproject.com>
@ 2025-02-04 21:51 ` Martin Storsjö
0 siblings, 0 replies; only message in thread
From: Martin Storsjö @ 2025-02-04 21:51 UTC (permalink / raw)
To: Dennis Sädtler via ffmpeg-devel; +Cc: dennis
On Mon, 16 Dec 2024, Dennis Sädtler via ffmpeg-devel wrote:
> From: Dennis Sädtler <dennis@obsproject.com>
>
> Added in macOS 15 "Sequoia".
>
> Signed-off-by: Dennis Sädtler <dennis@obsproject.com>
> ---
> Fixed line-endings, otherwise identical to v1.
>
> libavcodec/videotoolboxenc.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> index da7b291b03..fb2de7b960 100644
> --- a/libavcodec/videotoolboxenc.c
> +++ b/libavcodec/videotoolboxenc.c
> @@ -121,6 +121,7 @@ static struct{
> CFStringRef kVTCompressionPropertyKey_PrioritizeEncodingSpeedOverQuality;
> CFStringRef kVTCompressionPropertyKey_ConstantBitRate;
> CFStringRef kVTCompressionPropertyKey_EncoderID;
> + CFStringRef kVTCompressionPropertyKey_SpatialAdaptiveQPLevel;
>
> CFStringRef kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder;
> CFStringRef kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder;
> @@ -208,6 +209,7 @@ static void loadVTEncSymbols(void){
> "ReferenceBufferCount");
> GET_SYM(kVTCompressionPropertyKey_MaxAllowedFrameQP, "MaxAllowedFrameQP");
> GET_SYM(kVTCompressionPropertyKey_MinAllowedFrameQP, "MinAllowedFrameQP");
> + GET_SYM(kVTCompressionPropertyKey_SpatialAdaptiveQPLevel, "SpatialAdaptiveQPLevel");
> }
>
> #define H264_PROFILE_CONSTRAINED_HIGH (AV_PROFILE_H264_HIGH | AV_PROFILE_H264_CONSTRAINED)
> @@ -279,6 +281,7 @@ typedef struct VTEncContext {
> int max_slice_bytes;
> int power_efficient;
> int max_ref_frames;
> + int spatialaq;
> } VTEncContext;
>
> static void vtenc_free_buf_node(BufNode *info)
> @@ -1599,6 +1602,13 @@ static int vtenc_create_encoder(AVCodecContext *avctx,
> }
> }
>
> + if (vtctx->spatialaq >= 0) {
> + set_encoder_int_property_or_log(avctx,
> + compat_keys.kVTCompressionPropertyKey_SpatialAdaptiveQPLevel,
> + "spatialaq",
> + vtctx->spatialaq ? kVTQPModulationLevel_Default : kVTQPModulationLevel_Disable);
These constants aren't available if building with an older SDK, so this
would break building in such cases.
For other similar cases of compile time constants that may or may not be
available, we have configure checks and provide the constants ourselves -
that seems to be reasonable here too.
With the following changes on top, it seems to build successfully even for
older versions:
diff --git a/configure b/configure
index 32fbe58126..020c2af843 100755
--- a/configure
+++ b/configure
@@ -2490,6 +2490,7 @@ TYPES_LIST="
kCVImageBufferColorPrimaries_ITU_R_2020
kCVImageBufferTransferFunction_ITU_R_2020
kCVImageBufferTransferFunction_SMPTE_ST_428_1
+ kVTQPModulationLevel_Default
socklen_t
struct_addrinfo
struct_group_source_req
@@ -6748,6 +6749,7 @@ enabled videotoolbox && {
check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferColorPrimaries_ITU_R_2020 "-framework CoreVideo"
check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferTransferFunction_ITU_R_2020 "-framework CoreVideo"
check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferTransferFunction_SMPTE_ST_428_1 "-framework CoreVideo"
+ check_func_headers VideoToolbox/VTCompressionProperties.h kVTQPModulationLevel_Default "-framework CoreVideo"
}
enabled metal && test_cmd $metalcc -v || disable metal
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index fb2de7b960..950a29d9fa 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -54,6 +54,11 @@ enum { kCVPixelFormatType_420YpCbCr10BiPlanarFullRange
= 'xf20' };
enum { kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange = 'x420' };
#endif
+#if !HAVE_KVTQPMODULATIONLEVEL_DEFAULT
+enum { kVTQPModulationLevel_Default = -1 };
+enum { kVTQPModulationLevel_Disable = 0 };
+#endif
+
#ifndef TARGET_CPU_ARM64
# define TARGET_CPU_ARM64 0
#endif
If you don't mind these changes, I could push the patch with these changes
squashed in.
// Martin
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] only message in thread