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): bound clip-start recovery to normal video tails

songsongc9b723ae0871
diff --git a/crates/compositor/src/timeline_walk.rs b/crates/compositor/src/timeline_walk.rs
index 53465edc7..28e8518ad 100644
--- a/crates/compositor/src/timeline_walk.rs
+++ b/crates/compositor/src/timeline_walk.rs
@@ -257,6 +257,17 @@ unsafe fn catch_up(dec: &mut Decoder, target: f64, clip_start: f64) -> Result<()
}
}
+/// Normal recordings can have audio up to roughly half a second longer than
+/// video. Hold the last frame only in that margin: an unbounded fallback would
+/// hide a genuinely truncated camera recording.
+const CLIP_START_TAIL_TOLERANCE_SEC: f64 = 0.5;
+
+unsafe fn seek_clip_start(decoder: &mut Decoder, target: f64) -> Result<bool> {
+ let frame = decoder.seek_to_or_last(target)?;
+ Ok(!frame.is_null()
+ && target - decoder.cur_time_sec() <= CLIP_START_TAIL_TOLERANCE_SEC + 1e-6)
+}
+
/// `walk_composited_timeline`, qui ne compose que les frames de sortie `only` (triées) quand il y
/// en a : les autres avancent le compteur sans décoder ni composer, et la marche s'arrête après
/// la dernière. Un flux sans pts fiable avance d'une frame par frame de sortie : sauter le rend
@@ -354,7 +365,7 @@ unsafe fn walk_timeline(
// par le même offset que le seek (`webcam_time = screen_time - offset`).
let webcam_available_screen_end =
webcam_available_duration.map(|duration| duration + clip.webcam_offset_sec);
- if has_camera && webcam_available_screen_end.is_some_and(|end| end <= clip.source_start_sec) {
+ if has_camera && webcam_available_screen_end.is_some_and(|end| end + CLIP_START_TAIL_TOLERANCE_SEC < clip.source_start_sec) {
bail!(
"Cannot export clip {}: the camera video ends before this clip starts. Record the camera again or remove its track before exporting.",
clip_index + 1,
@@ -401,18 +412,21 @@ unsafe fn walk_timeline(
// un seul seek keyframe, puis chaque décodeur avance selon son propre pts jusqu'aux
// temps source demandés par les spans de vitesse.
- if sdec.seek_to(clip.source_start_sec)?.is_null() {
+ if !seek_clip_start(sdec, clip.source_start_sec)? {
bail!("Cannot export clip {}: the screen video has no readable frame at the clip's start.", clip_index + 1);
}
- if wdec
- .seek_to((clip.source_start_sec - clip.webcam_offset_sec).max(0.0))
- .with_context(|| format!("Cannot export clip {}: could not read the camera video. Record the camera again or remove its track before exporting.", clip_index + 1))?
- .is_null()
- {
- bail!(
- "Cannot export clip {}: the camera video has no readable frame at the clip's start. Record the camera again or remove its track before exporting.",
- clip_index + 1,
- );
+ let webcam_start = if has_camera {
+ (clip.source_start_sec - clip.webcam_offset_sec).max(0.0)
+ } else {
+ clip.source_start_sec
+ };
+ let webcam_error = if has_camera {
+ format!("Cannot export clip {}: the camera video has no readable frame at the clip's start. Record the camera again or remove its track before exporting.", clip_index + 1)
+ } else {
+ format!("Cannot export clip {}: the screen video has no readable frame at the clip's start.", clip_index + 1)
+ };
+ if !seek_clip_start(wdec, webcam_start).with_context(|| webcam_error.clone())? {
+ bail!(webcam_error);
}
if cursor_enabled {
diff --git a/crates/compositor/tests/export_timing.rs b/crates/compositor/tests/export_timing.rs
index e9e564664..8581ebe2c 100644
--- a/crates/compositor/tests/export_timing.rs
+++ b/crates/compositor/tests/export_timing.rs
@@ -271,6 +271,161 @@ fn mp4_export_rejects_a_timeline_that_produces_no_frames() {
std::fs::remove_file(out).expect("remove test output");
}
+/// Entering a clip just past its last frame is normal when audio outlasts video.
+/// Exercise screen-only, real-camera and unknown-duration camera sources, including
+/// frame inspection, which shares the export walk.
+#[test]
+fn mp4_export_accepts_tail_clips_and_frame_inspection() {
+ let Some(dir) = media_dir() else {
+ eprintln!("skipped: set OPENSCREEN_TEST_MEDIA");
+ return;
+ };
+ let out_dir = dir.join("tail_clip_export");
+ std::fs::create_dir_all(&out_dir).expect("output dir");
+ let camera = out_dir.join("camera.mkv");
+ openscreen_compositor::remux::remux_to_seekable_matroska(
+ &dir.join("webcam_gray.mp4").to_string_lossy(),
+ &camera.to_string_lossy(),
+ )
+ .expect("unknown-duration camera");
+ let gpu = Gpu::create(false).expect("gpu");
+ let comp = Compositor::new_sized(&gpu, 640, 360).expect("compositor");
+ let params = ExportParams {
+ width: 640,
+ height: 360,
+ fps: Some(30),
+ codec: ExportCodec::H264,
+ bit_rate: None,
+ };
+ for source in 0..5 {
+ let mut tail = whole_clip(&dir);
+ if source == 0 || source == 4 {
+ tail.webcam.clear();
+ } else if source == 2 {
+ tail.webcam = camera.to_string_lossy().into_owned();
+ }
+ // Last video pts is 4 - 1/60; the declared stream end is 4 seconds.
+ tail.source_start_sec = if source >= 3 {
+ SOURCE_SEC + 0.25
+ } else {
+ SOURCE_SEC - 0.01
+ };
+ tail.source_end_sec = tail.source_start_sec + 0.01;
+ let expected_tail_frames = if source >= 3 { 0 } else { 1 };
+ let clips = [whole_clip(&dir), tail];
+ let frames = unsafe {
+ openscreen_compositor::timeline_walk::render_frames(
+ &clips,
+ &gpu,
+ &comp,
+ &Cfg::c8(),
+ 30,
+ &[120],
+ )
+ }
+ .expect("inspect tail frame");
+ assert_eq!(
+ frames.len(),
+ expected_tail_frames,
+ "source {source}: tail inspection"
+ );
+ if let Some(frame) = frames.first() {
+ assert_eq!(frame.index, 120);
+ }
+ let out = out_dir.join("out.mp4");
+ let stats = pipeline::run_composited_multi(
+ &clips,
+ &out.to_string_lossy(),
+ &gpu,
+ &comp,
+ &Cfg::c8(),
+ &params,
+ &mut |_| {},
+ )
+ .expect("tail must not fail the complete export");
+ assert_eq!(
+ stats.frames,
+ 120 + expected_tail_frames as u64,
+ "source {source}: tail export"
+ );
+ std::fs::remove_file(out).expect("remove output");
+ }
+ std::fs::remove_dir_all(out_dir).expect("remove test outputs");
+}
+
+/// Unknown stream duration must not turn last-frame recovery into an unbounded
+/// hold. A real gap still fails, and the screen stand-in must not blame a camera.
+#[test]
+fn mp4_export_bounds_tail_recovery_and_reports_the_correct_source() {
+ let Some(dir) = media_dir() else {
+ eprintln!("skipped: set OPENSCREEN_TEST_MEDIA");
+ return;
+ };
+ let out_dir = dir.join("bounded_tail_export");
+ std::fs::create_dir_all(&out_dir).expect("output dir");
+ let source = out_dir.join("source.mkv");
+ openscreen_compositor::remux::remux_to_seekable_matroska(
+ &dir.join("screen_colors.mp4").to_string_lossy(),
+ &source.to_string_lossy(),
+ )
+ .expect("unknown-duration source");
+ let gpu = Gpu::create(false).expect("gpu");
+ let comp = Compositor::new_sized(&gpu, 640, 360).expect("compositor");
+ let params = ExportParams {
+ width: 640,
+ height: 360,
+ fps: Some(30),
+ codec: ExportCodec::H264,
+ bit_rate: None,
+ };
+ for has_camera in [false, true] {
+ for gap in [0.25, 0.6] {
+ let mut clip = whole_clip(&dir);
+ if has_camera {
+ clip.webcam = source.to_string_lossy().into_owned();
+ clip.webcam_offset_sec = -(SOURCE_SEC + gap);
+ clip.source_end_sec = 0.1;
+ } else {
+ clip.screen = source.to_string_lossy().into_owned();
+ clip.webcam.clear();
+ clip.source_start_sec = SOURCE_SEC + gap;
+ clip.source_end_sec = clip.source_start_sec + 0.1;
+ }
+ let out = out_dir.join("out.mp4");
+ std::fs::write(&out, b"previous export").expect("seed output");
+ let result = pipeline::run_composited_multi(
+ &[clip],
+ &out.to_string_lossy(),
+ &gpu,
+ &comp,
+ &Cfg::c8(),
+ &params,
+ &mut |_| {},
+ );
+ if gap < 0.5 {
+ assert_eq!(result.expect("normal tail hold").frames, 3);
+ } else {
+ let message = format!("{:#}", result.err().expect("real gap must fail"));
+ assert!(
+ message.contains(if has_camera { "camera" } else { "screen" }),
+ "{message}"
+ );
+ if !has_camera {
+ assert!(!message.contains("camera"), "{message}");
+ }
+ assert_eq!(std::fs::read(&out).unwrap(), b"previous export");
+ }
+ std::fs::remove_file(out).expect("remove output");
+ assert_eq!(
+ std::fs::read_dir(&out_dir).unwrap().count(),
+ 1,
+ "partial output left behind"
+ );
+ }
+ }
+ std::fs::remove_dir_all(out_dir).expect("remove test outputs");
+}
+
/// Cancelling an MP4 mid-render stops the walk at the next frame, reports `ExportCancelled`,
/// and publishes nothing: the destination keeps what it held and no partial is left beside
/// it. On Windows that last check also proves the muxer closed its file, since an open
diff --git a/technical-documentation/architecture/export-pipeline.md b/technical-documentation/architecture/export-pipeline.md
index 636d185a6..6149c5d46 100644
--- a/technical-documentation/architecture/export-pipeline.md
+++ b/technical-documentation/architecture/export-pipeline.md
@@ -139,8 +139,8 @@ and **one** encoder + muxer pair:
finish.
- **An unreadable camera must not silently remove a clip.** If the camera ends
- before the clip starts, or cannot produce a frame at its requested start
- offset, the shared MP4/GIF timeline walk fails with the clip number and a
+ more than 0.5 seconds before the clip starts, or cannot produce a frame
+ within 0.5 seconds of its requested start offset, the shared MP4/GIF timeline walk fails with the clip number and a
camera-specific explanation. This also covers browser recordings whose
declared container duration outlasts their actual video frames. The user can
re-record the camera or remove its track explicitly; the exporter does not
@@ -148,7 +148,12 @@ 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.
+ selection when the requested frame indices are outside the timeline. 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
+ behavior; an entirely empty export still fails. Screen-only clips report
+ screen errors, including errors from the stand-in decoder.
- **Imported audio tracks** (voiceover / BGM / SFX, issue #350) are mixed
on top of the assembled programme by `audio.rs::mix_external_tracks`,
diff --git a/technical-documentation/testing/manual-e2e-checklist.md b/technical-documentation/testing/manual-e2e-checklist.md
index 340df1480..b2220ec30 100644
--- a/technical-documentation/testing/manual-e2e-checklist.md
+++ b/technical-documentation/testing/manual-e2e-checklist.md
@@ -913,6 +913,7 @@ These checks are the human slice: an agent cannot click Apple's picker (see abov
| Date | Build / tag | Platform | Pass/fail | Notes |
|------|-------------|----------|-----------|-------|
+| 2026-10-24 | dev `fix/reject-empty-exports`, follow-up to PR #1377; rebuilt native addon | macOS 15.7.1, Apple Silicon | Partial — launch/editor only; GUI export unverified | Computer-use opened the isolated test profile, permissions onboarding and editor. The native file picker repeatedly cleared the synthetic project path on confirmation, so the project was not loaded and no GUI export is claimed. Native synthetic export/inspection tests separately cover screen/camera tails, unknown stream duration, real gaps, zero frames and destination preservation (7 passed; the unchanged macOS frame-count probe stub causes 1 existing failure). Recording, Presenter Overlay compatibility, other editor features, Windows/Linux and release validation were not exercised. |
| 2026-09-23 | dev `fix/725-hidden-cursor-auto-zoom`; rebuilt compositor addon SHA256 `a0bcd61e17084c010141049a9978121e45be2985449ff1618ab6a3145f8381f6` | Windows 11 Home 26200 | Partial — issue #725 slider slice passed | Human-driven real recording in the Electron dev build: moving a slider whose application cursor becomes hidden kept the reconstructed cursor hidden in the Studio recording and did not create a click-driven automatic zoom for that press. A visible control click still produced the normal automatic zoom. Sidecar inspection independently confirmed the hidden interval (`visible: false`) and that no zoom was centred on the press immediately preceding it. Recording, stop and editor open passed. Not covered: export, packaged build, audio/webcam, tray/HUD, other editor features, macOS or Linux. |
| 2026-09-12 | dev `fix/643-gif-export-cancel`, based on `fbe461e9`; rebuilt compositor addon SHA256 `128c89fe65a459b3f17721d610ea9a78e0d3e980e9eb0b5fb2b0e5d018619e15` | Windows | Partial — export cancellation passed | Computer-use OS input, real Electron and native save dialog, imported synthetic 8 s source. GIF 15 FPS / Medium (720p) / loop on: observed 55/120 frames, clicked Cancel while rendering (pending snapshot 104/120), returned to the same options; no final or partial output remained. Retried in that dialog to the same path and received Saved to; resulting GIF is 1280×720, 120 frames, 8,200,202 bytes, fully decodes with ffmpeg (exit 0). Automated real-addon tests separately pass existing-destination preservation, GIF retry, ordinary GIF and MP4 export. Desktop adapter required screenshot-based coordinates and Ctrl+O to reach the editor; HUD reachability is not claimed. An unrelated process error window partly obscured the retry success screenshot; file verification independently passed. Skipped: recording, audio/mic, webcam, tray/HUD, effect/caption comparisons, second viewer, macOS/Linux and release promotion. Task-local profile and evidence retained; test app stopped. |
| 2026-07-31 | dev build, `claude/e2e-tests-v1-8-0-474894` (e9578f09) | macOS 26.5, M1 | Partial — 1 defect | Ran launch/HUD, media, modifier anchoring, and export. **Defect: a dangling asset blanks the preview.** Modifier anchoring across a reorder verified in preview and in the exported frames. macOS export produced 1280×720 h264 + AAC at ~2× realtime. Chat sections skipped: no AI provider configured. HUD drag not runnable under computer-use (drop point is the desktop). |