Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(export): fill in clip offsets for projects the editor never opened

Richie McIlroyc20be14321bd
diff --git a/crates/export/src/lib.rs b/crates/export/src/lib.rs
index 1a5667796..1d4cd7574 100644
--- a/crates/export/src/lib.rs
+++ b/crates/export/src/lib.rs
@@ -127,6 +127,11 @@ impl ExporterBuilder {
);
synthesize_default_timeline(&mut project_config, &recordings);
+ fill_clip_offsets(
+ &mut project_config,
+ &recording_meta.project_path,
+ studio_meta,
+ );
cap_project::synchronize_legacy_keyboard(&recording_meta, &mut project_config);
cap_project::synchronize_captions(
@@ -703,6 +708,96 @@ mod forward_read_tests {
}
}
+/// A Studio recording with a camera is saved without clip offsets: the
+/// editor fills them in from the tracks' start times (and the devices'
+/// calibration) when it first opens the project. An export of a project the
+/// editor never opened would otherwise play every audio track from its own
+/// start, late against the screen by how much earlier it started.
+fn fill_clip_offsets(
+ config: &mut ProjectConfiguration,
+ project_path: &std::path::Path,
+ studio_meta: &StudioRecordingMeta,
+) {
+ if config.clips.is_empty() {
+ config.clips = cap_editor::initial_clip_configuration(project_path, studio_meta);
+ }
+}
+
+#[cfg(test)]
+mod clip_offset_tests {
+ use super::*;
+ use cap_project::{
+ AudioMeta, ClipConfiguration, ClipOffsets, Cursors, MultipleSegment, MultipleSegments,
+ VideoMeta,
+ };
+
+ fn camera_recording() -> StudioRecordingMeta {
+ let video = |path: &str, start: f64| VideoMeta {
+ path: path.into(),
+ fps: 30,
+ start_time: Some(start),
+ device_id: None,
+ };
+ let audio = |path: &str, start: f64| AudioMeta {
+ path: path.into(),
+ start_time: Some(start),
+ device_id: None,
+ gap_summary: None,
+ };
+ StudioRecordingMeta::MultipleSegments {
+ inner: MultipleSegments {
+ segments: vec![MultipleSegment {
+ display: video("display.mp4", 0.2026),
+ camera: Some(video("camera.mp4", 0.0331)),
+ mic: Some(audio("audio-input.ogg", 0.0331)),
+ system_audio: Some(audio("system_audio.ogg", 0.0)),
+ cursor: None,
+ keyboard: None,
+ display_notch: None,
+ }],
+ cursors: Cursors::default(),
+ status: None,
+ },
+ }
+ }
+
+ #[test]
+ fn a_project_without_clip_offsets_gets_the_editors() {
+ let dir = tempfile::tempdir().unwrap();
+ let meta = camera_recording();
+ let mut config = ProjectConfiguration::default();
+ assert!(config.clips.is_empty());
+ fill_clip_offsets(&mut config, dir.path(), &meta);
+ let offsets = config.clips[0].offsets;
+ assert!((offsets.mic - 0.1695).abs() < 1e-4, "mic {}", offsets.mic);
+ assert!(
+ (offsets.system_audio - 0.2026).abs() < 1e-4,
+ "system {}",
+ offsets.system_audio
+ );
+ assert_eq!(offsets.camera, 0.0);
+ }
+
+ #[test]
+ fn saved_clip_offsets_are_kept() {
+ let dir = tempfile::tempdir().unwrap();
+ let mut config = ProjectConfiguration {
+ clips: vec![ClipConfiguration {
+ index: 0,
+ offsets: ClipOffsets {
+ camera: 0.0,
+ mic: 0.5,
+ system_audio: 0.0,
+ },
+ offsets_auto_calculated: false,
+ }],
+ ..Default::default()
+ };
+ fill_clip_offsets(&mut config, dir.path(), &camera_recording());
+ assert_eq!(config.clips[0].offsets.mic, 0.5);
+ }
+}
+
#[cfg(test)]
mod subtitle_export_tests {
use super::*;