WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 0e40cbe

Browse files
committed
Improve error handling and remux status in recording
1 parent 1b4ae9b commit 0e40cbe

File tree

3 files changed

+78
-44
lines changed

3 files changed

+78
-44
lines changed

crates/editor/src/editor_instance.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,17 @@ impl EditorInstance {
7272
let timeline_segments = match meta {
7373
StudioRecordingMeta::SingleSegment { segment } => {
7474
let display_path = recording_meta.path(&segment.display.path);
75-
let duration = Video::new(&display_path, 0.0)
76-
.map(|v| v.duration)
77-
.unwrap_or(5.0);
75+
let duration = match Video::new(&display_path, 0.0) {
76+
Ok(v) => v.duration,
77+
Err(e) => {
78+
warn!(
79+
"Failed to load video for duration calculation: {} (path: {}), using default duration 5.0s",
80+
e,
81+
display_path.display()
82+
);
83+
5.0
84+
}
85+
};
7886
vec![TimelineSegment {
7987
recording_clip: 0,
8088
start: 0.0,
@@ -88,9 +96,17 @@ impl EditorInstance {
8896
.enumerate()
8997
.filter_map(|(i, segment)| {
9098
let display_path = recording_meta.path(&segment.display.path);
91-
let duration = Video::new(&display_path, 0.0)
92-
.map(|v| v.duration)
93-
.unwrap_or(5.0);
99+
let duration = match Video::new(&display_path, 0.0) {
100+
Ok(v) => v.duration,
101+
Err(e) => {
102+
warn!(
103+
"Failed to load video for duration calculation: {} (path: {}), using default duration 5.0s",
104+
e,
105+
display_path.display()
106+
);
107+
5.0
108+
}
109+
};
94110
if duration <= 0.0 {
95111
return None;
96112
}

crates/recording/src/sources/screen_capture/windows.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use tracing::*;
2525

2626
// const WINDOW_DURATION: Duration = Duration::from_secs(3);
2727
// const LOG_INTERVAL: Duration = Duration::from_secs(5);
28-
const MAX_DROP_RATE_THRESHOLD: f64 = 0.25;
2928

3029
#[derive(Debug)]
3130
pub struct Direct3DCapture;

crates/recording/src/studio_recording.rs

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ impl Message<Stop> for Actor {
145145
self.recording_dir.clone(),
146146
std::mem::take(&mut self.segments),
147147
cursors,
148+
self.segment_factory.fragmented,
148149
)
149150
.await?;
150151

@@ -610,51 +611,69 @@ async fn stop_recording(
610611
recording_dir: PathBuf,
611612
segments: Vec<RecordingSegment>,
612613
cursors: Cursors,
614+
fragmented: bool,
613615
) -> Result<CompletedRecording, RecordingError> {
614616
use cap_project::*;
615617

616618
let make_relative = |path: &PathBuf| {
617619
RelativePathBuf::from_path(path.strip_prefix(&recording_dir).unwrap()).unwrap()
618620
};
619621

622+
let segment_metas: Vec<_> = futures::stream::iter(segments)
623+
.then(async |s| {
624+
let to_start_time = |timestamp: Timestamp| {
625+
timestamp
626+
.duration_since(s.pipeline.start_time)
627+
.as_secs_f64()
628+
};
629+
630+
MultipleSegment {
631+
display: VideoMeta {
632+
path: make_relative(&s.pipeline.screen.path),
633+
fps: s.pipeline.screen.video_info.unwrap().fps(),
634+
start_time: Some(to_start_time(s.pipeline.screen.first_timestamp)),
635+
},
636+
camera: s.pipeline.camera.map(|camera| VideoMeta {
637+
path: make_relative(&camera.path),
638+
fps: camera.video_info.unwrap().fps(),
639+
start_time: Some(to_start_time(camera.first_timestamp)),
640+
}),
641+
mic: s.pipeline.microphone.map(|mic| AudioMeta {
642+
path: make_relative(&mic.path),
643+
start_time: Some(to_start_time(mic.first_timestamp)),
644+
}),
645+
system_audio: s.pipeline.system_audio.map(|audio| AudioMeta {
646+
path: make_relative(&audio.path),
647+
start_time: Some(to_start_time(audio.first_timestamp)),
648+
}),
649+
cursor: s
650+
.pipeline
651+
.cursor
652+
.as_ref()
653+
.map(|cursor| make_relative(&cursor.output_path)),
654+
}
655+
})
656+
.collect::<Vec<_>>()
657+
.await;
658+
659+
let needs_remux = if fragmented {
660+
segment_metas.iter().any(|seg| {
661+
let display_path = seg.display.path.to_path(&recording_dir);
662+
display_path.is_dir()
663+
})
664+
} else {
665+
false
666+
};
667+
668+
let status = if needs_remux {
669+
Some(StudioRecordingStatus::NeedsRemux)
670+
} else {
671+
Some(StudioRecordingStatus::Complete)
672+
};
673+
620674
let meta = StudioRecordingMeta::MultipleSegments {
621675
inner: MultipleSegments {
622-
segments: futures::stream::iter(segments)
623-
.then(async |s| {
624-
let to_start_time = |timestamp: Timestamp| {
625-
timestamp
626-
.duration_since(s.pipeline.start_time)
627-
.as_secs_f64()
628-
};
629-
630-
MultipleSegment {
631-
display: VideoMeta {
632-
path: make_relative(&s.pipeline.screen.path),
633-
fps: s.pipeline.screen.video_info.unwrap().fps(),
634-
start_time: Some(to_start_time(s.pipeline.screen.first_timestamp)),
635-
},
636-
camera: s.pipeline.camera.map(|camera| VideoMeta {
637-
path: make_relative(&camera.path),
638-
fps: camera.video_info.unwrap().fps(),
639-
start_time: Some(to_start_time(camera.first_timestamp)),
640-
}),
641-
mic: s.pipeline.microphone.map(|mic| AudioMeta {
642-
path: make_relative(&mic.path),
643-
start_time: Some(to_start_time(mic.first_timestamp)),
644-
}),
645-
system_audio: s.pipeline.system_audio.map(|audio| AudioMeta {
646-
path: make_relative(&audio.path),
647-
start_time: Some(to_start_time(audio.first_timestamp)),
648-
}),
649-
cursor: s
650-
.pipeline
651-
.cursor
652-
.as_ref()
653-
.map(|cursor| make_relative(&cursor.output_path)),
654-
}
655-
})
656-
.collect::<Vec<_>>()
657-
.await,
676+
segments: segment_metas,
658677
cursors: cap_project::Cursors::Correct(
659678
cursors
660679
.into_values()
@@ -671,7 +690,7 @@ async fn stop_recording(
671690
})
672691
.collect(),
673692
),
674-
status: Some(StudioRecordingStatus::Complete),
693+
status,
675694
},
676695
};
677696

0 commit comments

Comments
 (0)