Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(export): stop frame inspection before unrequested clips

songsong79c3aa2442e0
diff --git a/crates/compositor/src/export_control.rs b/crates/compositor/src/export_control.rs
index 4be350265..d289dc55c 100644
--- a/crates/compositor/src/export_control.rs
+++ b/crates/compositor/src/export_control.rs
@@ -132,6 +132,7 @@ struct VideoValidation {
}
impl Drop for VideoValidation {
+ /// Release decoder buffers and close the input before rename or cleanup.
fn drop(&mut self) {
unsafe {
crate::ffi::av_frame_free(&mut self.frame);
diff --git a/crates/compositor/src/pipeline_linux.rs b/crates/compositor/src/pipeline_linux.rs
index 15c8d2b15..288c2fc48 100644
--- a/crates/compositor/src/pipeline_linux.rs
+++ b/crates/compositor/src/pipeline_linux.rs
@@ -878,6 +878,8 @@ pub fn run_composited_multi_cancellable(
})
}
+/// Encode and close the staged MP4. The caller must validate a displayable
+/// decoded frame before publishing it; returned stats count composed frames.
fn run_multi_inner(
clips: &[ClipSource],
out: &str,
diff --git a/crates/compositor/src/pipeline_macos.rs b/crates/compositor/src/pipeline_macos.rs
index 5cebfa1ed..b407d7966 100644
--- a/crates/compositor/src/pipeline_macos.rs
+++ b/crates/compositor/src/pipeline_macos.rs
@@ -1191,6 +1191,8 @@ pub fn run_composited_multi_cancellable(
})
}
+/// Encode and close the staged MP4. The caller must validate a displayable
+/// decoded frame before publishing it; returned stats count composed frames.
fn run_multi_inner(
clips: &[ClipSource],
out: &str,
diff --git a/crates/compositor/src/pipeline_windows.rs b/crates/compositor/src/pipeline_windows.rs
index a697326b5..39ad180fa 100644
--- a/crates/compositor/src/pipeline_windows.rs
+++ b/crates/compositor/src/pipeline_windows.rs
@@ -1680,6 +1680,8 @@ impl Default for ExportParams {
}
+/// Encode and close the staged MP4. The caller must validate a displayable
+/// decoded frame before publishing it; returned stats count composed frames.
unsafe fn run_multi_inner(
clips: &[ClipSource],
out: &str,
diff --git a/crates/compositor/src/timeline_walk.rs b/crates/compositor/src/timeline_walk.rs
index 59c00150e..3ad2456a3 100644
--- a/crates/compositor/src/timeline_walk.rs
+++ b/crates/compositor/src/timeline_walk.rs
@@ -310,6 +310,12 @@ unsafe fn walk_timeline(
comp.set_segmentation_deterministic(true);
'clips: for (clip_index, clip) in clips.iter().enumerate() {
+ // A completed inspection must not open or seek an unrelated later clip.
+ if let Some(only) = only {
+ if only.last().map_or(true, |&last| frames > last) {
+ break 'clips;
+ }
+ }
// Le preset de layout est GLOBAL (un seul panneau pour toute la timeline) mais la
// caméra est PAR CLIP : un projet mélange sans problème un enregistrement avec webcam
// et un import qui n'en a pas. Le preset ne doit donc s'appliquer qu'aux clips qui ont
diff --git a/crates/compositor/tests/export_timing.rs b/crates/compositor/tests/export_timing.rs
index ba917d202..7bc5d0e87 100644
--- a/crates/compositor/tests/export_timing.rs
+++ b/crates/compositor/tests/export_timing.rs
@@ -427,6 +427,63 @@ fn mp4_export_bounds_tail_recovery_and_reports_the_correct_source() {
std::fs::remove_dir_all(out_dir).expect("remove test outputs");
}
+/// Inspecting a completed selection must not prepare an unrelated later clip,
+/// while a selection that reaches the bad camera must still report its error.
+#[test]
+fn frame_inspection_stops_before_an_unrequested_unreadable_clip() {
+ let Some(dir) = media_dir() else {
+ eprintln!("skipped: set OPENSCREEN_TEST_MEDIA");
+ return;
+ };
+ let gpu = Gpu::create(false).expect("gpu");
+ let comp = Compositor::new_sized(&gpu, 640, 360).expect("compositor");
+ let mut bad = whole_clip(&dir);
+ bad.webcam_offset_sec = -(SOURCE_SEC + 1.0);
+ let clips = [whole_clip(&dir), bad];
+ let frames = unsafe {
+ openscreen_compositor::timeline_walk::render_frames(
+ &clips,
+ &gpu,
+ &comp,
+ &Cfg::c8(),
+ 30,
+ &[119],
+ )
+ }
+ .expect("the last frame of the valid clip must not inspect the next camera");
+ assert_eq!(frames.len(), 1);
+ assert_eq!(frames[0].index, 119);
+ let empty = unsafe {
+ openscreen_compositor::timeline_walk::render_frames(
+ &clips[1..],
+ &gpu,
+ &comp,
+ &Cfg::c8(),
+ 30,
+ &[],
+ )
+ }
+ .expect("an empty selection must not prepare any clip");
+ assert!(empty.is_empty());
+ let error = unsafe {
+ openscreen_compositor::timeline_walk::render_frames(
+ &clips,
+ &gpu,
+ &comp,
+ &Cfg::c8(),
+ 30,
+ &[120],
+ )
+ }
+ .err()
+ .expect("a requested unreadable clip must still fail");
+ let message = format!("{error:#}");
+ assert!(
+ message.contains("clip 2") && message.contains("camera"),
+ "{message}"
+ );
+}
+
/// The staged decode check must accept short exports in both supported MP4 codecs.
#[cfg(target_os = "macos")]
#[test]
diff --git a/technical-documentation/architecture/export-pipeline.md b/technical-documentation/architecture/export-pipeline.md
index 79bdcb80d..37bdda496 100644
--- a/technical-documentation/architecture/export-pipeline.md
+++ b/technical-documentation/architecture/export-pipeline.md
@@ -148,7 +148,9 @@ and **one** encoder + muxer pair:
never a successful empty file. These errors discard the staged output and
preserve an existing destination, including when earlier clips rendered
successfully. Frame inspection (`renderFrames`) may still return an empty
- selection when the requested frame indices are outside the timeline. Both
+ selection when the requested frame indices are outside the timeline. It stops
+ before opening subsequent clips once its requested frame range is exhausted,
+ so an unrelated later camera cannot fail an already completed selection. Both
export and frame inspection hold the last video frame when entering a clip
within the 0.5-second tail margin (audio can outlast video). Clips starting
beyond their declared end within this margin retain the existing skip