Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Add Windows-specific fragmented muxer support

Richie McIlroy82361aa69e0a
diff --git a/crates/enc-ffmpeg/src/mux/segmented_stream.rs b/crates/enc-ffmpeg/src/mux/segmented_stream.rs
index 91df680cc..0ab253b0a 100644
--- a/crates/enc-ffmpeg/src/mux/segmented_stream.rs
+++ b/crates/enc-ffmpeg/src/mux/segmented_stream.rs
@@ -148,6 +148,19 @@ impl SegmentedVideoEncoder {
let mut output = format::output_as(&manifest_path, "dash")?;
+ let init_seg_path = base_path.join(INIT_SEGMENT_NAME);
+ let media_seg_pattern = base_path.join("segment_$Number%03d$.m4s");
+
+ #[cfg(windows)]
+ let init_seg_str = init_seg_path.to_string_lossy().replace('\\', "/");
+ #[cfg(windows)]
+ let media_seg_str = media_seg_pattern.to_string_lossy().replace('\\', "/");
+
+ #[cfg(not(windows))]
+ let init_seg_str = init_seg_path.to_string_lossy().to_string();
+ #[cfg(not(windows))]
+ let media_seg_str = media_seg_pattern.to_string_lossy().to_string();
+
unsafe {
let opts = output.as_mut_ptr();
@@ -157,8 +170,8 @@ impl SegmentedVideoEncoder {
ffmpeg::ffi::av_opt_set((*opts).priv_data, k.as_ptr(), v.as_ptr(), 0);
};
- set_opt("init_seg_name", INIT_SEGMENT_NAME);
- set_opt("media_seg_name", "segment_$Number%03d$.m4s");
+ set_opt("init_seg_name", &init_seg_str);
+ set_opt("media_seg_name", &media_seg_str);
set_opt(
"seg_duration",
&config.segment_duration.as_secs_f64().to_string(),
diff --git a/crates/recording/src/capture_pipeline.rs b/crates/recording/src/capture_pipeline.rs
index 7f745d347..86eef4298 100644
--- a/crates/recording/src/capture_pipeline.rs
+++ b/crates/recording/src/capture_pipeline.rs
@@ -8,6 +8,10 @@ use crate::{
#[cfg(target_os = "macos")]
use crate::output_pipeline::{MacOSFragmentedM4SMuxer, MacOSFragmentedM4SMuxerConfig};
+#[cfg(windows)]
+use crate::output_pipeline::{WindowsFragmentedM4SMuxer, WindowsFragmentedM4SMuxerConfig};
+#[cfg(windows)]
+use cap_enc_ffmpeg::h264::H264Preset;
use anyhow::anyhow;
use cap_timestamp::Timestamps;
use std::{path::PathBuf, sync::Arc};
@@ -136,11 +140,9 @@ impl MakeCapturePipeline for screen_capture::Direct3DCapture {
output_path: PathBuf,
start_time: Timestamps,
fragmented: bool,
- _shared_pause_state: Option<SharedPauseState>,
+ shared_pause_state: Option<SharedPauseState>,
encoder_preferences: EncoderPreferences,
) -> anyhow::Result<OutputPipeline> {
- let d3d_device = screen_capture.d3d_device.clone();
-
if fragmented {
let fragments_dir = output_path
.parent()
@@ -150,17 +152,15 @@ impl MakeCapturePipeline for screen_capture::Direct3DCapture {
OutputPipeline::builder(fragments_dir)
.with_video::<screen_capture::VideoSource>(screen_capture)
.with_timestamps(start_time)
- .build::<WindowsSegmentedMuxer>(WindowsSegmentedMuxerConfig {
- pixel_format: screen_capture::Direct3DCapture::PIXEL_FORMAT.as_dxgi(),
- d3d_device,
- bitrate_multiplier: 0.15f32,
- frame_rate: 30u32,
- output_size: None,
- encoder_preferences,
+ .build::<WindowsFragmentedM4SMuxer>(WindowsFragmentedM4SMuxerConfig {
segment_duration: std::time::Duration::from_secs(3),
+ preset: H264Preset::Ultrafast,
+ output_size: None,
+ shared_pause_state,
})
.await
} else {
+ let d3d_device = screen_capture.d3d_device.clone();
OutputPipeline::builder(output_path.clone())
.with_video::<screen_capture::VideoSource>(screen_capture)
.with_timestamps(start_time)
diff --git a/crates/recording/src/studio_recording.rs b/crates/recording/src/studio_recording.rs
index ae2f50a6e..bc437d3fb 100644
--- a/crates/recording/src/studio_recording.rs
+++ b/crates/recording/src/studio_recording.rs
@@ -19,8 +19,8 @@ use crate::output_pipeline::{
#[cfg(windows)]
use crate::output_pipeline::{
- WindowsCameraMuxer, WindowsCameraMuxerConfig, WindowsSegmentedCameraMuxer,
- WindowsSegmentedCameraMuxerConfig,
+ WindowsCameraMuxer, WindowsCameraMuxerConfig, WindowsFragmentedM4SCameraMuxer,
+ WindowsFragmentedM4SCameraMuxerConfig,
};
use anyhow::{Context as _, anyhow, bail};
use cap_media_info::VideoInfo;
@@ -877,7 +877,13 @@ async fn create_segment_pipeline(
};
#[cfg(windows)]
- let shared_pause_state: Option<SharedPauseState> = None;
+ let shared_pause_state = if fragmented {
+ Some(SharedPauseState::new(Arc::new(
+ std::sync::atomic::AtomicBool::new(false),
+ )))
+ } else {
+ None
+ };
let screen = ScreenCaptureMethod::make_studio_mode_pipeline(
capture_source,
@@ -925,8 +931,8 @@ async fn create_segment_pipeline(
OutputPipeline::builder(fragments_dir)
.with_video::<sources::NativeCamera>(camera_feed)
.with_timestamps(start_time)
- .build::<WindowsSegmentedCameraMuxer>(WindowsSegmentedCameraMuxerConfig {
- encoder_preferences: encoder_preferences.clone(),
+ .build::<WindowsFragmentedM4SCameraMuxer>(WindowsFragmentedM4SCameraMuxerConfig {
+ shared_pause_state: shared_pause_state.clone(),
..Default::default()
})
.instrument(error_span!("camera-out"))