From 487e30d4083561ce8ff3e985c1126b47381a81cb Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Wed, 14 Oct 2026 02:28:59 +0900 Subject: [PATCH 1/2] fix(export): give VideoToolbox exports a two-second keyframe interval --- crates/enc-ffmpeg/src/video/h264.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/enc-ffmpeg/src/video/h264.rs b/crates/enc-ffmpeg/src/video/h264.rs index c1aa052abe1..71149ac346c 100644 --- a/crates/enc-ffmpeg/src/video/h264.rs +++ b/crates/enc-ffmpeg/src/video/h264.rs @@ -1261,6 +1261,7 @@ fn get_codec_and_options( options.set("realtime", "false"); options.set("profile", "main"); options.set("allow_sw", "0"); + options.set("g", &keyframe_interval_str); } else { options.set("realtime", "true"); options.set("prio_speed", "true"); @@ -1691,6 +1692,33 @@ mod self_test_tests { .expect("healthy encoder passes the round trip"); } + #[cfg(target_os = "macos")] + #[test] + fn videotoolbox_export_uses_the_default_keyframe_interval() { + ffmpeg::init().ok(); + let config = VideoInfo::from_raw(cap_media_info::RawVideoFormat::Nv12, 1920, 1080, 60); + let videotoolbox_options = |is_export| { + get_codec_and_options( + &config, + H264Preset::Medium, + Some(&["h264_videotoolbox"]), + is_export, + None, + ) + .into_iter() + .find(|(codec, _)| codec.name() == "h264_videotoolbox") + .expect("VideoToolbox encoder is available on macOS") + .1 + }; + + let export = videotoolbox_options(true); + let expected = (DEFAULT_KEYFRAME_INTERVAL_SECS * 60).to_string(); + assert_eq!(export.get("g"), Some(expected.as_str())); + + let realtime = videotoolbox_options(false); + assert_eq!(realtime.get("g"), None); + } + #[cfg(target_os = "linux")] #[test] fn linux_nvidia_device_prefers_nvenc_and_keeps_software_fallback() { From 840b3fae6ab371f32939dc32a9ebf23e3bf2dc45 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Wed, 14 Oct 2026 02:33:30 +0900 Subject: [PATCH 2/2] test(enc-ffmpeg): skip the VideoToolbox keyframe test when software encoding is forced --- crates/enc-ffmpeg/src/video/h264.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/enc-ffmpeg/src/video/h264.rs b/crates/enc-ffmpeg/src/video/h264.rs index 71149ac346c..6ad7b80bf87 100644 --- a/crates/enc-ffmpeg/src/video/h264.rs +++ b/crates/enc-ffmpeg/src/video/h264.rs @@ -1695,6 +1695,9 @@ mod self_test_tests { #[cfg(target_os = "macos")] #[test] fn videotoolbox_export_uses_the_default_keyframe_interval() { + if force_software_encoder() { + return; + } ffmpeg::init().ok(); let config = VideoInfo::from_raw(cap_media_info::RawVideoFormat::Nv12, 1920, 1080, 60); let videotoolbox_options = |is_export| {