Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(export): give VideoToolbox exports a two-second keyframe interval

Richie McIlroy487e30d40835
diff --git a/crates/enc-ffmpeg/src/video/h264.rs b/crates/enc-ffmpeg/src/video/h264.rs
index c1aa052ab..71149ac34 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() {