diff --git a/plugins/mac-videotoolbox/data/locale/en-US.ini b/plugins/mac-videotoolbox/data/locale/en-US.ini index 1748656728d5f3..dda31c840ef666 100644 --- a/plugins/mac-videotoolbox/data/locale/en-US.ini +++ b/plugins/mac-videotoolbox/data/locale/en-US.ini @@ -13,6 +13,7 @@ MaxBitrateWindow="Maximum bitrate window" KeyframeIntervalSec="Keyframe Interval (0=auto)" Profile="Profile" UseBFrames="Use B-Frames" +UseSpatialAQ="Enable Spatial AQ" RateControl="Rate Control" 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." FullRangeUnsupported="Full range color is not supported by 16-bit Apple VT encoders. Select limited range color in Settings -> Advanced." diff --git a/plugins/mac-videotoolbox/encoder.c b/plugins/mac-videotoolbox/encoder.c index bad9043fee8dd8..e545fd2b4e1769 100644 --- a/plugins/mac-videotoolbox/encoder.c +++ b/plugins/mac-videotoolbox/encoder.c @@ -56,6 +56,7 @@ struct vt_encoder { const char *profile; CMVideoCodecType codec_type; bool bframes; + bool spatial_aq; int vt_pix_fmt; enum video_colorspace colorspace; @@ -567,6 +568,20 @@ static OSStatus create_encoder(struct vt_encoder *enc) if (code != noErr) { return code; } + + if (__builtin_available(macOS 15.0, *)) { + int spatialAq = enc->spatial_aq ? kVTQPModulationLevel_Default : kVTQPModulationLevel_Disable; + CFNumberRef SpatialAQ = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &spatialAq); + + code = VTSessionSetProperty(s, kVTCompressionPropertyKey_SpatialAdaptiveQPLevel, SpatialAQ); + + if (code != noErr) { + log_osstatus(LOG_WARNING, enc, + "setting kVTCompressionPropertyKey_SpatialAdaptiveQPLevel failed", code); + } + + CFRelease(SpatialAQ); + } } // This can fail depending on hardware configuration @@ -723,6 +738,7 @@ static bool update_params(struct vt_encoder *enc, obs_data_t *settings) enc->rc_max_bitrate = (uint32_t)obs_data_get_int(settings, "max_bitrate"); enc->rc_max_bitrate_window = obs_data_get_double(settings, "max_bitrate_window"); enc->bframes = obs_data_get_bool(settings, "bframes"); + enc->spatial_aq = obs_data_get_bool(settings, "spatial_aq"); return true; } @@ -1261,6 +1277,10 @@ static obs_properties_t *vt_properties_h26x(void *data __unused, void *type_data obs_properties_add_bool(props, "bframes", obs_module_text("UseBFrames")); + if (__builtin_available(macOS 15.0, *)) { + obs_properties_add_bool(props, "spatial_aq", obs_module_text("UseSpatialAQ")); + } + return props; } @@ -1346,6 +1366,7 @@ static void vt_defaults(obs_data_t *settings, void *data) type_data->codec_type == kCMVideoCodecType_H264 ? "high" : "main"); obs_data_set_default_int(settings, "codec_type", kCMVideoCodecType_AppleProRes422); obs_data_set_default_bool(settings, "bframes", true); + obs_data_set_default_bool(settings, "spatial_aq", true); } static void vt_free_type_data(void *data)