Skip to content

Commit

Permalink
mac-videotoolbox: Add Spatial AQ option (macOS 15)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsaedtler committed Oct 26, 2024
1 parent 448d1c8 commit 3eb273a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/mac-videotoolbox/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
21 changes: 21 additions & 0 deletions plugins/mac-videotoolbox/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3eb273a

Please sign in to comment.