Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

wip: Merge of new exporter + custom config

Richie McIlroybb1283db32e4
diff --git a/Cargo.lock b/Cargo.lock
index 1a415665e..76e36339c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -945,6 +945,7 @@ dependencies = [
"bytemuck",
"cap-flags",
"cap-project",
+ "cap-recording",
"ffmpeg-hw-device",
"ffmpeg-next",
"ffmpeg-sys-next",
diff --git a/crates/recording/src/actor.rs b/crates/recording/src/actor.rs
deleted file mode 100644
index 6d523fbfc..000000000
--- a/crates/recording/src/actor.rs
+++ /dev/null
@@ -1,159 +0,0 @@
-use std::{
- path::{Path, PathBuf},
- sync::{atomic::AtomicBool, Arc},
- time::{SystemTime, UNIX_EPOCH},
-};
-
-use cap_flags::FLAGS;
-use cap_media::{
- encoders::{H264Encoder, MP3Encoder, Output},
- feeds::{AudioInputFeed, CameraFeed},
- filters::VideoFilter,
- pipeline::{builder::PipelineBuilder, Pipeline, RealTimeClock},
- sources::{AudioInputSource, CameraSource, ScreenCaptureSource, ScreenCaptureTarget},
- MediaError,
-};
-use cap_project::{CameraMeta, CursorEvents, RecordingMeta};
-use either::Either;
-use thiserror::Error;
-use tokio::sync::{oneshot, Mutex};
-
-use crate::{
- cursor::{spawn_cursor_recorder, CursorActor, Cursors},
- RecordingOptions,
-};
-
-struct CursorPipeline {
- pub output_path: PathBuf,
- pub actor: CursorActor,
-}
-
-pub struct CompletedRecording {
- pub id: String,
- pub recording_dir: PathBuf,
- pub display_source: ScreenCaptureTarget,
- pub meta: RecordingMeta,
- pub cursor_data: cap_project::CursorData,
- pub segments: Vec<f64>,
-}
-
-async fn stop_recording(mut actor: Actor) -> Result<CompletedRecording, RecordingError> {
- let segment = (actor.start_time, current_time_f64());
-
- use cap_project::*;
-
- let meta = RecordingMeta {
- project_path: actor.recording_dir.clone(),
- sharing: None,
- pretty_name: format!(
- "Cap {}",
- chrono::Local::now().format("%Y-%m-%d at %H.%M.%S")
- ),
- content: Content::SingleSegment {
- segment: SingleSegment {
- display: Display {
- path: actor
- .pipeline
- .display_output_path
- .strip_prefix(&actor.recording_dir)
- .unwrap()
- .to_owned(),
- },
- camera: actor
- .pipeline
- .camera_output_path
- .as_ref()
- .map(|path| CameraMeta {
- path: path.strip_prefix(&actor.recording_dir).unwrap().to_owned(),
- }),
- audio: actor
- .pipeline
- .audio_output_path
- .as_ref()
- .map(|path| AudioMeta {
- path: path.strip_prefix(&actor.recording_dir).unwrap().to_owned(),
- }),
- cursor: Some(PathBuf::from("content/cursor.json")),
- },
- },
- };
-
- actor.pipeline.inner.shutdown().await?;
-
- actor
- .stop_signal
- .store(true, std::sync::atomic::Ordering::Relaxed);
-
- let cursor_data = if let Some(cursor) = actor.cursor {
- let resp = cursor.stop().await;
- cap_project::CursorData {
- clicks: resp.clicks,
- moves: resp.moves,
- cursor_images: CursorImages(
- resp.cursors
- .into_values()
- .map(|(filename, id)| (id.to_string(), filename))
- .collect(),
- ),
- }
- } else {
- Default::default()
- };
-
- std::fs::write(
- actor.recording_dir.join("content/cursor.json"),
- serde_json::to_string_pretty(&cursor_data)?,
- )?;
-
- meta.save_for_project()
- .map_err(Either::either_into::<RecordingError>)?;
-
- Ok(CompletedRecording {
- id: actor.id,
- meta,
- cursor_data,
- recording_dir: actor.recording_dir,
- display_source: actor.options.capture_target,
- segments: vec![segment.0, segment.1],
- })
-}
-
-fn create_screen_capture(
- recording_options: &RecordingOptions,
-) -> ScreenCaptureSource<impl MakeCapturePipeline> {
- #[cfg(target_os = "macos")]
- {
- ScreenCaptureSource::<cap_media::sources::CMSampleBufferCapture>::init(
- dbg!(&recording_options.capture_target),
- None,
- None,
- )
- }
- #[cfg(not(target_os = "macos"))]
- {
- ScreenCaptureSource::<cap_media::sources::AVFrameCapture>::init(
- dbg!(&recording_options.capture_target),
- None,
- None,
- )
- }
-}
-
-struct RecordingPipeline {
- pub inner: Pipeline<RealTimeClock<()>>,
- pub display_output_path: PathBuf,
- pub audio_output_path: Option<PathBuf>,
- pub camera_output_path: Option<PathBuf>,
- pub cursor: Option<CursorPipeline>,
-}
-
-impl RecordingSegment {
- pub fn camera_meta(&self, base_path: &Path) -> Option<CameraMeta> {
- self.pipeline
- .camera_output_path
- .as_ref()
- .map(|path| CameraMeta {
- path: path.strip_prefix(base_path).unwrap().to_owned(),
- })
- }
-}
diff --git a/crates/recording/src/lib.rs b/crates/recording/src/lib.rs
index c3f1fed1b..8ba0158a1 100644
--- a/crates/recording/src/lib.rs
+++ b/crates/recording/src/lib.rs
@@ -1,5 +1,4 @@
-pub mod actor;
-mod cursor;
+pub mod cursor;
pub mod segmented_actor;
pub use segmented_actor::{spawn_recording_actor, ActorHandle, CompletedRecording, RecordingError};
diff --git a/crates/rendering/Cargo.toml b/crates/rendering/Cargo.toml
index 81f67f86f..5e59df415 100644
--- a/crates/rendering/Cargo.toml
+++ b/crates/rendering/Cargo.toml
@@ -13,6 +13,7 @@ wgpu.workspace = true
image = "0.25.2"
cap-project = { path = "../project" }
cap-flags = { path = "../flags" }
+cap-recording = { path = "../recording" }
ffmpeg-hw-device = { path = "../ffmpeg-hw-device" }
tokio.workspace = true
ffmpeg.workspace = true
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs
index 9124f11e0..18f21128e 100644
--- a/crates/rendering/src/lib.rs
+++ b/crates/rendering/src/lib.rs
@@ -8,6 +8,7 @@ use cap_project::{
FAST_VELOCITY_THRESHOLD, REGULAR_SMOOTHING_SAMPLES, REGULAR_VELOCITY_THRESHOLD,
SLOW_SMOOTHING_SAMPLES, SLOW_VELOCITY_THRESHOLD, XY,
};
+use cap_recording::segmented_actor::RecordingSegment;
use core::f64;
use decoder::{AsyncVideoDecoder, AsyncVideoDecoderHandle};
use futures::future::OptionFuture;