Skip to content

Commit 78ff378

Browse files
derrodmstorsjo
authored andcommitted
lavc/videotoolboxenc: Add spatial_aq option
Added in macOS 15 "Sequoia". Signed-off-by: Dennis Sädtler <[email protected]> Signed-off-by: Martin Storsjö <[email protected]>
1 parent 586de32 commit 78ff378

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

configure

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,6 +2490,7 @@ TYPES_LIST="
24902490
kCVImageBufferColorPrimaries_ITU_R_2020
24912491
kCVImageBufferTransferFunction_ITU_R_2020
24922492
kCVImageBufferTransferFunction_SMPTE_ST_428_1
2493+
kVTQPModulationLevel_Default
24932494
socklen_t
24942495
struct_addrinfo
24952496
struct_group_source_req
@@ -6749,6 +6750,7 @@ enabled videotoolbox && {
67496750
check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferColorPrimaries_ITU_R_2020 "-framework CoreVideo"
67506751
check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferTransferFunction_ITU_R_2020 "-framework CoreVideo"
67516752
check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferTransferFunction_SMPTE_ST_428_1 "-framework CoreVideo"
6753+
check_func_headers VideoToolbox/VTCompressionProperties.h kVTQPModulationLevel_Default "-framework CoreVideo"
67526754
}
67536755

67546756
enabled metal && test_cmd $metalcc -v || disable metal

libavcodec/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "version_major.h"
3131

3232
#define LIBAVCODEC_VERSION_MINOR 33
33-
#define LIBAVCODEC_VERSION_MICRO 100
33+
#define LIBAVCODEC_VERSION_MICRO 101
3434

3535
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
3636
LIBAVCODEC_VERSION_MINOR, \

libavcodec/videotoolboxenc.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ enum { kCVPixelFormatType_420YpCbCr10BiPlanarFullRange = 'xf20' };
5454
enum { kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange = 'x420' };
5555
#endif
5656

57+
#if !HAVE_KVTQPMODULATIONLEVEL_DEFAULT
58+
enum { kVTQPModulationLevel_Default = -1 };
59+
enum { kVTQPModulationLevel_Disable = 0 };
60+
#endif
61+
5762
#ifndef TARGET_CPU_ARM64
5863
# define TARGET_CPU_ARM64 0
5964
#endif
@@ -121,6 +126,7 @@ static struct{
121126
CFStringRef kVTCompressionPropertyKey_PrioritizeEncodingSpeedOverQuality;
122127
CFStringRef kVTCompressionPropertyKey_ConstantBitRate;
123128
CFStringRef kVTCompressionPropertyKey_EncoderID;
129+
CFStringRef kVTCompressionPropertyKey_SpatialAdaptiveQPLevel;
124130

125131
CFStringRef kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder;
126132
CFStringRef kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder;
@@ -208,6 +214,7 @@ static void loadVTEncSymbols(void){
208214
"ReferenceBufferCount");
209215
GET_SYM(kVTCompressionPropertyKey_MaxAllowedFrameQP, "MaxAllowedFrameQP");
210216
GET_SYM(kVTCompressionPropertyKey_MinAllowedFrameQP, "MinAllowedFrameQP");
217+
GET_SYM(kVTCompressionPropertyKey_SpatialAdaptiveQPLevel, "SpatialAdaptiveQPLevel");
211218
}
212219

213220
#define H264_PROFILE_CONSTRAINED_HIGH (AV_PROFILE_H264_HIGH | AV_PROFILE_H264_CONSTRAINED)
@@ -279,6 +286,7 @@ typedef struct VTEncContext {
279286
int max_slice_bytes;
280287
int power_efficient;
281288
int max_ref_frames;
289+
int spatialaq;
282290
} VTEncContext;
283291

284292
static void vtenc_free_buf_node(BufNode *info)
@@ -1599,6 +1607,13 @@ static int vtenc_create_encoder(AVCodecContext *avctx,
15991607
}
16001608
}
16011609

1610+
if (vtctx->spatialaq >= 0) {
1611+
set_encoder_int_property_or_log(avctx,
1612+
compat_keys.kVTCompressionPropertyKey_SpatialAdaptiveQPLevel,
1613+
"spatialaq",
1614+
vtctx->spatialaq ? kVTQPModulationLevel_Default : kVTQPModulationLevel_Disable);
1615+
}
1616+
16021617
status = VTCompressionSessionPrepareToEncodeFrames(vtctx->session);
16031618
if (status) {
16041619
av_log(avctx, AV_LOG_ERROR, "Error: cannot prepare encoder: %d\n", status);
@@ -2891,6 +2906,8 @@ static const enum AVPixelFormat prores_pix_fmts[] = {
28912906
{ .i64 = -1 }, -1, 1, VE }, \
28922907
{ "power_efficient", "Set to 1 to enable more power-efficient encoding if supported.", \
28932908
OFFSET(power_efficient), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE }, \
2909+
{ "spatial_aq", "Set to 1 to enable spatial AQ if supported.", \
2910+
OFFSET(spatialaq), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE }, \
28942911
{ "max_ref_frames", \
28952912
"Sets the maximum number of reference frames. This only has an effect when the value is less than the maximum allowed by the profile/level.", \
28962913
OFFSET(max_ref_frames), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },

0 commit comments

Comments
 (0)