Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(export): reject unreadable camera clips and empty output
songsong3b4863147746
diff --git a/crates/compositor/src/timeline_walk.rs b/crates/compositor/src/timeline_walk.rsindex 5556e577b..53465edc7 100644--- a/crates/compositor/src/timeline_walk.rs+++ b/crates/compositor/src/timeline_walk.rs@@ -22,7 +22,7 @@ use crate::frame_geometry::webcam_is_real;use crate::pipeline::{ClipSource, Decoder};use crate::regions::{speed_segments_for_window, SpeedSegment};use crate::scene::Scene;-use anyhow::Result;+use anyhow::{bail, Context, Result};use std::collections::HashMap;/// Ce que le décodeur sait de la PROCHAINE frame, sans l'adopter.@@ -158,7 +158,11 @@ pub(crate) unsafe fn walk_composited_timeline(on_frame: &mut dyn FnMut(u64) -> Result<()>,on_clip_end: &mut dyn FnMut(usize, f64, u64, &[SpeedSegment]) -> Result<()>,) -> Result<u64> {- walk_timeline(clips, gpu, comp, cfg, out_fps, scene, screen_decs, webcam_decs, None, on_frame, on_clip_end)+ let frames = walk_timeline(clips, gpu, comp, cfg, out_fps, scene, screen_decs, webcam_decs, None, on_frame, on_clip_end)?;+ if frames == 0 {+ bail!("No video frames were exported. Check that the clips contain readable video before exporting again.");+ }+ Ok(frames)}/// Une frame de sortie relue par `render_frames`.@@ -350,6 +354,12 @@ 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) {+ 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,+ );+ }let mut source_end_sec = clip.source_end_sec;if let Some(duration) = screen_available_duration {source_end_sec = source_end_sec.min(duration);@@ -392,13 +402,17 @@ 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() {- continue; // clip vide / au-delà de la source+ 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))?+ .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(){- continue;+ 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,+ );}if cursor_enabled {diff --git a/crates/compositor/tests/export_timing.rs b/crates/compositor/tests/export_timing.rsindex cffda4469..e9e564664 100644--- a/crates/compositor/tests/export_timing.rs+++ b/crates/compositor/tests/export_timing.rs@@ -161,6 +161,116 @@ fn mp4_export_frame_count_follows_output_fps() {assert_eq!(probed, 120, "muxed file disagrees with the reported count");}+/// A camera that ended before its requested offset must fail the whole export,+/// even after a good clip. Otherwise an empty or incomplete MP4 replaces the destination.+#[test]+fn mp4_export_rejects_an_unreadable_camera_without_publishing() {+ let Some(dir) = media_dir() else {+ eprintln!("skipped: set OPENSCREEN_TEST_MEDIA");+ return;+ };+ let out_dir = dir.join("unreadable_camera_export");+ std::fs::create_dir_all(&out_dir).expect("output dir");+ let camera = out_dir.join("camera.webm");+ openscreen_compositor::remux::remux_to_seekable_matroska(+ &dir.join("webcam_gray.mp4").to_string_lossy(),+ &camera.to_string_lossy(),+ )+ .expect("camera with no stream duration, like a browser recording");+ let gpu = Gpu::create(false).expect("gpu");+ let params = ExportParams {+ width: 640,+ height: 360,+ fps: Some(30),+ codec: ExportCodec::H264,+ bit_rate: None,+ };+ let comp = Compositor::new_sized(&gpu, 640, 360).expect("compositor");+ for unknown_duration in [false, true] {+ for after_valid_clip in [false, true] {+ let mut bad = whole_clip(&dir);+ if unknown_duration {+ bad.webcam = camera.to_string_lossy().into_owned();+ }+ bad.webcam_offset_sec = -(SOURCE_SEC + 1.0);+ let mut clips = Vec::new();+ if after_valid_clip {+ clips.push(whole_clip(&dir));+ }+ clips.push(bad);+ let out = out_dir.join("out.mp4");+ std::fs::write(&out, b"previous export").expect("seed destination");+ let error = pipeline::run_composited_multi(+ &clips,+ &out.to_string_lossy(),+ &gpu,+ &comp,+ &Cfg::c8(),+ ¶ms,+ &mut |_| {},+ )+ .err()+ .expect("an unreadable camera must not silently drop a clip");+ let message = format!("{error:#}");+ assert!(+ message.contains("camera"),+ "missing camera diagnosis: {message}"+ );+ assert!(+ message.contains(&format!("clip {}", clips.len())),+ "missing clip number: {message}"+ );+ assert_eq!(std::fs::read(&out).unwrap(), b"previous export");+ assert_eq!(+ std::fs::read_dir(&out_dir).unwrap().count(),+ 2,+ "partial output left behind"+ );+ }+ }+ std::fs::remove_dir_all(out_dir).expect("remove test outputs");+}++#[test]+fn mp4_export_rejects_a_timeline_that_produces_no_frames() {+ let Some(dir) = media_dir() else {+ eprintln!("skipped: set OPENSCREEN_TEST_MEDIA");+ return;+ };+ let gpu = Gpu::create(false).expect("gpu");+ let params = ExportParams {+ width: 640,+ height: 360,+ fps: Some(30),+ codec: ExportCodec::H264,+ bit_rate: None,+ };+ let comp = Compositor::new_sized(&gpu, 640, 360).expect("compositor");+ let mut clip = whole_clip(&dir);+ clip.webcam.clear();+ clip.source_start_sec = SOURCE_SEC + 1.0;+ clip.source_end_sec = SOURCE_SEC + 2.0;+ let out = dir.join("no_frames.mp4");+ std::fs::write(&out, b"previous export").expect("seed destination");+ let error = pipeline::run_composited_multi(+ &[clip],+ &out.to_string_lossy(),+ &gpu,+ &comp,+ &Cfg::c8(),+ ¶ms,+ &mut |_| {},+ )+ .err()+ .expect("zero video frames must not be a successful export");+ assert!(+ format!("{error:#}").contains("No video frames"),+ "unexpected error: {error:#}"+ );+ assert_eq!(std::fs::read(&out).unwrap(), b"previous export");+ std::fs::remove_file(out).expect("remove test output");+}+/// 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 opendiff --git a/technical-documentation/architecture/export-pipeline.md b/technical-documentation/architecture/export-pipeline.mdindex b1c99de54..636d185a6 100644--- a/technical-documentation/architecture/export-pipeline.md+++ b/technical-documentation/architecture/export-pipeline.md@@ -138,6 +138,18 @@ and **one** encoder + muxer pair:Audio jobs already in flight are joined, so a cancel settles once theyfinish.+- **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+ 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+ discard it automatically. A walk producing no video frames is an error,+ 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.+- **Imported audio tracks** (voiceover / BGM / SFX, issue #350) are mixedon top of the assembled programme by `audio.rs::mix_external_tracks`,between `assemble_concatenated_pcm` and `finish_audio`. Each track's