|
18 | 18 | codec_type_to_print_fmt(codec_type), ##__VA_ARGS__) |
19 | 19 | #define VT_BLOG(level, format, ...) VT_LOG_ENCODER(enc->encoder, enc->codec_type, level, format, ##__VA_ARGS__) |
20 | 20 |
|
| 21 | +enum aq_mode { |
| 22 | + AQ_INVALID = 0, |
| 23 | + AQ_AUTO, |
| 24 | + AQ_DISABLED, |
| 25 | + AQ_ENABLED, |
| 26 | +}; |
| 27 | + |
21 | 28 | struct vt_encoder_type_data { |
22 | 29 | const char *disp_name; |
23 | 30 | const char *id; |
@@ -56,6 +63,7 @@ struct vt_encoder { |
56 | 63 | const char *profile; |
57 | 64 | CMVideoCodecType codec_type; |
58 | 65 | bool bframes; |
| 66 | + bool spatial_aq; |
59 | 67 |
|
60 | 68 | int vt_pix_fmt; |
61 | 69 | enum video_colorspace colorspace; |
@@ -567,6 +575,20 @@ static OSStatus create_encoder(struct vt_encoder *enc) |
567 | 575 | if (code != noErr) { |
568 | 576 | return code; |
569 | 577 | } |
| 578 | + |
| 579 | + if (__builtin_available(macOS 15.0, *)) { |
| 580 | + int spatial_aq = enc->spatial_aq ? kVTQPModulationLevel_Default : kVTQPModulationLevel_Disable; |
| 581 | + CFNumberRef spatialAQ = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &spatial_aq); |
| 582 | + |
| 583 | + code = VTSessionSetProperty(s, kVTCompressionPropertyKey_SpatialAdaptiveQPLevel, spatialAQ); |
| 584 | + |
| 585 | + if (code != noErr) { |
| 586 | + log_osstatus(LOG_WARNING, enc, |
| 587 | + "setting kVTCompressionPropertyKey_SpatialAdaptiveQPLevel failed", code); |
| 588 | + } |
| 589 | + |
| 590 | + CFRelease(spatialAQ); |
| 591 | + } |
570 | 592 | } |
571 | 593 |
|
572 | 594 | // This can fail depending on hardware configuration |
@@ -624,11 +646,12 @@ static void dump_encoder_info(struct vt_encoder *enc) |
624 | 646 | "\trc_max_bitrate: %d (kbps)\n" |
625 | 647 | "\trc_max_bitrate_window: %f (s)\n" |
626 | 648 | "\thw_enc: %s\n" |
| 649 | + "\tspatial_aq: %s\n" |
627 | 650 | "\tprofile: %s\n" |
628 | 651 | "\tcodec_type: %.4s\n", |
629 | 652 | enc->vt_encoder_id, enc->rate_control, enc->bitrate, enc->quality, enc->fps_num, enc->fps_den, |
630 | 653 | enc->width, enc->height, enc->keyint, enc->limit_bitrate ? "on" : "off", enc->rc_max_bitrate, |
631 | | - enc->rc_max_bitrate_window, enc->hw_enc ? "on" : "off", |
| 654 | + enc->rc_max_bitrate_window, enc->hw_enc ? "on" : "off", enc->spatial_aq ? "on" : "off", |
632 | 655 | (enc->profile != NULL && !!strlen(enc->profile)) ? enc->profile : "default", |
633 | 656 | codec_type_to_print_fmt(enc->codec_type)); |
634 | 657 | } |
@@ -724,6 +747,14 @@ static bool update_params(struct vt_encoder *enc, obs_data_t *settings) |
724 | 747 | enc->rc_max_bitrate_window = obs_data_get_double(settings, "max_bitrate_window"); |
725 | 748 | enc->bframes = obs_data_get_bool(settings, "bframes"); |
726 | 749 |
|
| 750 | + enum aq_mode spatial_aq_mode = obs_data_get_int(settings, "spatial_aq_mode"); |
| 751 | + if (spatial_aq_mode == AQ_AUTO) { |
| 752 | + /* Only enable by default in CRF mode. */ |
| 753 | + enc->spatial_aq = strcmp(enc->rate_control, "CRF") == 0; |
| 754 | + } else { |
| 755 | + enc->spatial_aq = spatial_aq_mode == AQ_ENABLED; |
| 756 | + } |
| 757 | + |
727 | 758 | return true; |
728 | 759 | } |
729 | 760 |
|
@@ -1261,6 +1292,14 @@ static obs_properties_t *vt_properties_h26x(void *data __unused, void *type_data |
1261 | 1292 |
|
1262 | 1293 | obs_properties_add_bool(props, "bframes", obs_module_text("UseBFrames")); |
1263 | 1294 |
|
| 1295 | + if (__builtin_available(macOS 15.0, *)) { |
| 1296 | + p = obs_properties_add_list(props, "spatial_aq_mode", obs_module_text("SpatialAQ"), OBS_COMBO_TYPE_LIST, |
| 1297 | + OBS_COMBO_FORMAT_INT); |
| 1298 | + obs_property_list_add_int(p, obs_module_text("SpatialAQ.Auto"), AQ_AUTO); |
| 1299 | + obs_property_list_add_int(p, obs_module_text("SpatialAQ.Disabled"), AQ_DISABLED); |
| 1300 | + obs_property_list_add_int(p, obs_module_text("SpatialAQ.Enabled"), AQ_ENABLED); |
| 1301 | + } |
| 1302 | + |
1264 | 1303 | return props; |
1265 | 1304 | } |
1266 | 1305 |
|
@@ -1346,6 +1385,7 @@ static void vt_defaults(obs_data_t *settings, void *data) |
1346 | 1385 | type_data->codec_type == kCMVideoCodecType_H264 ? "high" : "main"); |
1347 | 1386 | obs_data_set_default_int(settings, "codec_type", kCMVideoCodecType_AppleProRes422); |
1348 | 1387 | obs_data_set_default_bool(settings, "bframes", true); |
| 1388 | + obs_data_set_default_int(settings, "spatial_aq_mode", AQ_AUTO); |
1349 | 1389 | } |
1350 | 1390 |
|
1351 | 1391 | static void vt_free_type_data(void *data) |
|
0 commit comments