diff --git a/crates/editor/src/editor_instance.rs b/crates/editor/src/editor_instance.rs index ea0569daa9a..3f1c61bacbf 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.rs index fe550f5e093..f49a2d6e795 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.rs index cc7818587ed..769d3561f02 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); + } } } diff --git a/crates/rendering/src/main.rs b/crates/rendering/src/main.rs index d306057fc49..4918b8da1fb 100644 --- a/crates/rendering/src/main.rs +++ b/crates/rendering/src/main.rs @@ -68,11 +68,8 @@ async fn main() -> Result<()> { // Load the project similar to ExporterBase println!("Loading project from: {}", args.project_path.display()); - let project_config: ProjectConfiguration = serde_json::from_reader( - std::fs::File::open(args.project_path.join("project-config.json")) - .context("Failed to open project-config.json")?, - ) - .context("Failed to parse project configuration")?; + let project_config = ProjectConfiguration::load(&args.project_path) + .context("Failed to load project configuration")?; let recording_meta = RecordingMeta::load_for_project(&args.project_path) .map_err(|e| anyhow::anyhow!("Failed to load recording metadata: {}", e))?;