Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(project): stop applying the camera start alignment twice
Richie McIlroy2548148b00cd
diff --git a/crates/editor/src/editor_instance.rs b/crates/editor/src/editor_instance.rsindex ea0569daa..3f1c61bac 100644--- a/crates/editor/src/editor_instance.rs+++ b/crates/editor/src/editor_instance.rs@@ -2331,10 +2331,7 @@ mod initial_clip_configuration_tests {assert_eq!(clips.len(), 1);assert_eq!(clips[0].index, 0);assert!(clips[0].offsets_auto_calculated);- assert_eq!(- clips[0].offsets.camera.to_bits(),- ((1.23456789_f64 - 0.987654321) as f32).to_bits()- );+ assert_eq!(clips[0].offsets.camera.to_bits(), 0.0_f32.to_bits());assert_eq!(clips[0].offsets.mic.to_bits(),(((1.23456789_f64 - 0.876543219) as f32) + calibration).to_bits()diff --git a/crates/project/src/configuration.rs b/crates/project/src/configuration.rsindex fe550f5e0..f49a2d6e7 100644--- a/crates/project/src/configuration.rs+++ b/crates/project/src/configuration.rs@@ -2878,6 +2878,17 @@ impl ProjectConfiguration {config.text_anim_version = TEXT_ANIM_VERSION;}+ // Auto-calculated camera offsets used to repeat the camera decoder's+ // start-time alignment, playing the camera ahead by the same amount.+ // The correct automatic value is always 0; user-entered offsets stay.+ let mut needs_clip_offset_repair = false;+ for clip in &mut config.clips {+ if clip.offsets_auto_calculated && clip.offsets.camera != 0.0 {+ clip.offsets.camera = 0.0;+ needs_clip_offset_repair = true;+ }+ }+config.validate().map_err(|error| std::io::Error::new(std::io::ErrorKind::InvalidData, error))?;@@ -2886,6 +2897,7 @@ impl ProjectConfiguration {|| needs_motion_blur_clamp|| needs_screen_motion_blur_migration|| needs_text_size_migration+ || needs_clip_offset_repair{match config.write(project_path) {Ok(_) => {@@ -4252,6 +4264,62 @@ mod tests {}}+ #[test]+ fn load_resets_auto_calculated_camera_offsets_and_keeps_user_offsets() {+ let dir = tempfile::tempdir().unwrap();+ let config = ProjectConfiguration {+ clips: vec![+ ClipConfiguration {+ index: 0,+ offsets: ClipOffsets {+ camera: 1.0,+ mic: 0.25,+ system_audio: 0.5,+ },+ offsets_auto_calculated: true,+ },+ ClipConfiguration {+ index: 1,+ offsets: ClipOffsets {+ camera: -0.2,+ mic: 0.1,+ system_audio: 0.0,+ },+ offsets_auto_calculated: false,+ },+ ],+ ..Default::default()+ };+ config.write(dir.path()).unwrap();++ let loaded = ProjectConfiguration::load(dir.path()).unwrap();+ let written: ProjectConfiguration = serde_json::from_str(+ &std::fs::read_to_string(dir.path().join("project-config.json")).unwrap(),+ )+ .unwrap();++ for clips in [&loaded.clips, &written.clips] {+ assert_eq!(+ [+ clips[0].offsets.camera,+ clips[0].offsets.mic,+ clips[0].offsets.system_audio+ ],+ [0.0, 0.25, 0.5]+ );+ assert!(clips[0].offsets_auto_calculated);+ assert_eq!(+ [+ clips[1].offsets.camera,+ clips[1].offsets.mic,+ clips[1].offsets.system_audio+ ],+ [-0.2, 0.1, 0.0]+ );+ assert!(!clips[1].offsets_auto_calculated);+ }+ }+#[test]fn load_caps_motion_blur_to_slider_range() {let dir = tempfile::tempdir().unwrap();diff --git a/crates/project/src/meta.rs b/crates/project/src/meta.rsindex cc7818587..769d3561f 100644--- a/crates/project/src/meta.rs+++ b/crates/project/src/meta.rs@@ -751,13 +751,6 @@ impl MultipleSegment {let cal_offset = calibration_offset.unwrap_or(0.0);- let camera_offset = self- .camera- .as_ref()- .and_then(|c| c.start_time)- .map(|t| (latest - t) as f32)- .unwrap_or(0.0);-let mic_offset = self.mic.as_ref()@@ -772,8 +765,11 @@ impl MultipleSegment {.map(|t| (latest - t) as f32 + cal_offset).unwrap_or(0.0);+ // The camera needs no clip offset: its decoder is already aligned to+ // the latest start time (rendering's `segment_video_timing`). Adding+ // `latest - camera.start` here as well plays the camera that far ahead.crate::ClipOffsets {- camera: camera_offset,+ camera: 0.0,mic: mic_offset,system_audio: system_audio_offset,}@@ -1189,6 +1185,18 @@ mod test {assert!((offsets.mic - (0.6586015 - 0.5559852) as f32).abs() < 1e-6);assert_eq!(offsets.system_audio, 0.0);}++ // The camera decoder is aligned to the latest start time, so an early+ // camera must not get a clip offset on top of that alignment.+ #[test]+ fn early_camera_gets_no_clip_offset() {+ let mut early = segment(0.2, Some(1.0), None);+ early.camera = Some(video(Some(0.0)));+ assert_eq!(early.latest_start_time(), Some(1.0));+ let offsets = early.calculate_audio_offsets_with_calibration(Some(0.05));+ assert_eq!(offsets.camera, 0.0);+ assert!((offsets.mic - 0.05).abs() < 1e-6);+ }}}