Skip to content

Commit 3eb273a

Browse files
committed
mac-videotoolbox: Add Spatial AQ option (macOS 15)
1 parent 448d1c8 commit 3eb273a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

plugins/mac-videotoolbox/data/locale/en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ MaxBitrateWindow="Maximum bitrate window"
1313
KeyframeIntervalSec="Keyframe Interval (0=auto)"
1414
Profile="Profile"
1515
UseBFrames="Use B-Frames"
16+
UseSpatialAQ="Enable Spatial AQ"
1617
RateControl="Rate Control"
1718
ColorFormatUnsupported="The selected color format is not supported by the selected Apple VT encoder. Select a compatible color format in Settings -> Advanced or use a different encoder."
1819
FullRangeUnsupported="Full range color is not supported by 16-bit Apple VT encoders. Select limited range color in Settings -> Advanced."

plugins/mac-videotoolbox/encoder.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct vt_encoder {
5656
const char *profile;
5757
CMVideoCodecType codec_type;
5858
bool bframes;
59+
bool spatial_aq;
5960

6061
int vt_pix_fmt;
6162
enum video_colorspace colorspace;
@@ -567,6 +568,20 @@ static OSStatus create_encoder(struct vt_encoder *enc)
567568
if (code != noErr) {
568569
return code;
569570
}
571+
572+
if (__builtin_available(macOS 15.0, *)) {
573+
int spatialAq = enc->spatial_aq ? kVTQPModulationLevel_Default : kVTQPModulationLevel_Disable;
574+
CFNumberRef SpatialAQ = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &spatialAq);
575+
576+
code = VTSessionSetProperty(s, kVTCompressionPropertyKey_SpatialAdaptiveQPLevel, SpatialAQ);
577+
578+
if (code != noErr) {
579+
log_osstatus(LOG_WARNING, enc,
580+
"setting kVTCompressionPropertyKey_SpatialAdaptiveQPLevel failed", code);
581+
}
582+
583+
CFRelease(SpatialAQ);
584+
}
570585
}
571586

572587
// This can fail depending on hardware configuration
@@ -723,6 +738,7 @@ static bool update_params(struct vt_encoder *enc, obs_data_t *settings)
723738
enc->rc_max_bitrate = (uint32_t)obs_data_get_int(settings, "max_bitrate");
724739
enc->rc_max_bitrate_window = obs_data_get_double(settings, "max_bitrate_window");
725740
enc->bframes = obs_data_get_bool(settings, "bframes");
741+
enc->spatial_aq = obs_data_get_bool(settings, "spatial_aq");
726742

727743
return true;
728744
}
@@ -1261,6 +1277,10 @@ static obs_properties_t *vt_properties_h26x(void *data __unused, void *type_data
12611277

12621278
obs_properties_add_bool(props, "bframes", obs_module_text("UseBFrames"));
12631279

1280+
if (__builtin_available(macOS 15.0, *)) {
1281+
obs_properties_add_bool(props, "spatial_aq", obs_module_text("UseSpatialAQ"));
1282+
}
1283+
12641284
return props;
12651285
}
12661286

@@ -1346,6 +1366,7 @@ static void vt_defaults(obs_data_t *settings, void *data)
13461366
type_data->codec_type == kCMVideoCodecType_H264 ? "high" : "main");
13471367
obs_data_set_default_int(settings, "codec_type", kCMVideoCodecType_AppleProRes422);
13481368
obs_data_set_default_bool(settings, "bframes", true);
1369+
obs_data_set_default_bool(settings, "spatial_aq", true);
13491370
}
13501371

13511372
static void vt_free_type_data(void *data)

0 commit comments

Comments
 (0)