Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Improve error handling and remux status in recording
Richie McIlroy0e40cbe2d22c
diff --git a/crates/editor/src/editor_instance.rs b/crates/editor/src/editor_instance.rsindex ad1b9331d..ac627b243 100644--- a/crates/editor/src/editor_instance.rs+++ b/crates/editor/src/editor_instance.rs@@ -72,9 +72,17 @@ impl EditorInstance {let timeline_segments = match meta {StudioRecordingMeta::SingleSegment { segment } => {let display_path = recording_meta.path(&segment.display.path);- let duration = Video::new(&display_path, 0.0)- .map(|v| v.duration)- .unwrap_or(5.0);+ let duration = match Video::new(&display_path, 0.0) {+ Ok(v) => v.duration,+ Err(e) => {+ warn!(+ "Failed to load video for duration calculation: {} (path: {}), using default duration 5.0s",+ e,+ display_path.display()+ );+ 5.0+ }+ };vec![TimelineSegment {recording_clip: 0,start: 0.0,@@ -88,9 +96,17 @@ impl EditorInstance {.enumerate().filter_map(|(i, segment)| {let display_path = recording_meta.path(&segment.display.path);- let duration = Video::new(&display_path, 0.0)- .map(|v| v.duration)- .unwrap_or(5.0);+ let duration = match Video::new(&display_path, 0.0) {+ Ok(v) => v.duration,+ Err(e) => {+ warn!(+ "Failed to load video for duration calculation: {} (path: {}), using default duration 5.0s",+ e,+ display_path.display()+ );+ 5.0+ }+ };if duration <= 0.0 {return None;}diff --git a/crates/recording/src/sources/screen_capture/windows.rs b/crates/recording/src/sources/screen_capture/windows.rsindex bb9b3513f..a62d59e3c 100644--- a/crates/recording/src/sources/screen_capture/windows.rs+++ b/crates/recording/src/sources/screen_capture/windows.rs@@ -25,7 +25,6 @@ use tracing::*;// const WINDOW_DURATION: Duration = Duration::from_secs(3);// const LOG_INTERVAL: Duration = Duration::from_secs(5);-const MAX_DROP_RATE_THRESHOLD: f64 = 0.25;#[derive(Debug)]pub struct Direct3DCapture;diff --git a/crates/recording/src/studio_recording.rs b/crates/recording/src/studio_recording.rsindex 3138045a3..592679b8b 100644--- a/crates/recording/src/studio_recording.rs+++ b/crates/recording/src/studio_recording.rs@@ -145,6 +145,7 @@ impl Message<Stop> for Actor {self.recording_dir.clone(),std::mem::take(&mut self.segments),cursors,+ self.segment_factory.fragmented,).await?;@@ -610,6 +611,7 @@ async fn stop_recording(recording_dir: PathBuf,segments: Vec<RecordingSegment>,cursors: Cursors,+ fragmented: bool,) -> Result<CompletedRecording, RecordingError> {use cap_project::*;@@ -617,44 +619,61 @@ async fn stop_recording(RelativePathBuf::from_path(path.strip_prefix(&recording_dir).unwrap()).unwrap()};+ let segment_metas: Vec<_> = futures::stream::iter(segments)+ .then(async |s| {+ let to_start_time = |timestamp: Timestamp| {+ timestamp+ .duration_since(s.pipeline.start_time)+ .as_secs_f64()+ };++ MultipleSegment {+ display: VideoMeta {+ path: make_relative(&s.pipeline.screen.path),+ fps: s.pipeline.screen.video_info.unwrap().fps(),+ start_time: Some(to_start_time(s.pipeline.screen.first_timestamp)),+ },+ camera: s.pipeline.camera.map(|camera| VideoMeta {+ path: make_relative(&camera.path),+ fps: camera.video_info.unwrap().fps(),+ start_time: Some(to_start_time(camera.first_timestamp)),+ }),+ mic: s.pipeline.microphone.map(|mic| AudioMeta {+ path: make_relative(&mic.path),+ start_time: Some(to_start_time(mic.first_timestamp)),+ }),+ system_audio: s.pipeline.system_audio.map(|audio| AudioMeta {+ path: make_relative(&audio.path),+ start_time: Some(to_start_time(audio.first_timestamp)),+ }),+ cursor: s+ .pipeline+ .cursor+ .as_ref()+ .map(|cursor| make_relative(&cursor.output_path)),+ }+ })+ .collect::<Vec<_>>()+ .await;++ let needs_remux = if fragmented {+ segment_metas.iter().any(|seg| {+ let display_path = seg.display.path.to_path(&recording_dir);+ display_path.is_dir()+ })+ } else {+ false+ };++ let status = if needs_remux {+ Some(StudioRecordingStatus::NeedsRemux)+ } else {+ Some(StudioRecordingStatus::Complete)+ };+let meta = StudioRecordingMeta::MultipleSegments {inner: MultipleSegments {- segments: futures::stream::iter(segments)- .then(async |s| {- let to_start_time = |timestamp: Timestamp| {- timestamp- .duration_since(s.pipeline.start_time)- .as_secs_f64()- };-- MultipleSegment {- display: VideoMeta {- path: make_relative(&s.pipeline.screen.path),- fps: s.pipeline.screen.video_info.unwrap().fps(),- start_time: Some(to_start_time(s.pipeline.screen.first_timestamp)),- },- camera: s.pipeline.camera.map(|camera| VideoMeta {- path: make_relative(&camera.path),- fps: camera.video_info.unwrap().fps(),- start_time: Some(to_start_time(camera.first_timestamp)),- }),- mic: s.pipeline.microphone.map(|mic| AudioMeta {- path: make_relative(&mic.path),- start_time: Some(to_start_time(mic.first_timestamp)),- }),- system_audio: s.pipeline.system_audio.map(|audio| AudioMeta {- path: make_relative(&audio.path),- start_time: Some(to_start_time(audio.first_timestamp)),- }),- cursor: s- .pipeline- .cursor- .as_ref()- .map(|cursor| make_relative(&cursor.output_path)),- }- })- .collect::<Vec<_>>()- .await,+ segments: segment_metas,cursors: cap_project::Cursors::Correct(cursors.into_values()@@ -671,7 +690,7 @@ async fn stop_recording(}).collect(),),- status: Some(StudioRecordingStatus::Complete),+ status,},};