Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fmt
Richie McIlroy24be9bc19f49
diff --git a/Cargo.lock b/Cargo.lockindex 9460a261c..eb7ec932e 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1055,6 +1055,7 @@ dependencies = ["ffmpeg-next","serde","serde_json",+ "tempfile","tokio","tracing","workspace-hack",@@ -1531,6 +1532,7 @@ dependencies = ["cap-mediafoundation-ffmpeg","cap-mediafoundation-utils","cap-project",+ "cap-rendering","cap-timestamp","cap-utils","chrono",diff --git a/apps/desktop/src-tauri/src/recording.rs b/apps/desktop/src-tauri/src/recording.rsindex 54f83b878..870236911 100644--- a/apps/desktop/src-tauri/src/recording.rs+++ b/apps/desktop/src-tauri/src/recording.rs@@ -1213,6 +1213,7 @@ pub async fn take_screenshot(path: relative_path,fps: 0,start_time: Some(0.0),+ device_id: None,};let segment = cap_project::SingleSegment {diff --git a/apps/desktop/src-tauri/src/screenshot_editor.rs b/apps/desktop/src-tauri/src/screenshot_editor.rsindex 90bffe7b6..890142c56 100644--- a/apps/desktop/src-tauri/src/screenshot_editor.rs+++ b/apps/desktop/src-tauri/src/screenshot_editor.rs@@ -214,6 +214,7 @@ impl ScreenshotEditorInstances {path: relative_path.clone(),fps: 30,start_time: Some(0.0),+ device_id: None,};let segment = SingleSegment {display: video_meta.clone(),diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.tsindex 8b937880a..76ce95e4a 100644--- a/apps/desktop/src/utils/tauri.ts+++ b/apps/desktop/src/utils/tauri.ts@@ -374,7 +374,7 @@ export type AspectRatio = "wide" | "vertical" | "square" | "classic" | "tall"export type Audio = { duration: number; sample_rate: number; channels: number; start_time: number }export type AudioConfiguration = { mute: boolean; improve: boolean; micVolumeDb?: number; micStereoMode?: StereoMode; systemVolumeDb?: number }export type AudioInputLevelChange = number-export type AudioMeta = { path: string; start_time?: number | null }+export type AudioMeta = { path: string; start_time?: number | null; device_id?: string | null }export type AuthSecret = { api_key: string } | { token: string; expires: number }export type AuthStore = { secret: AuthSecret; user_id: string | null; plan: Plan | null; intercom_hash: string | null; organizations?: Organization[] }export type BackgroundConfiguration = { source: BackgroundSource; blur: number; padding: number; rounding: number; roundingType?: CornerStyle; inset: number; crop: Crop | null; shadow?: number; advancedShadow?: ShadowConfiguration | null; border?: BorderConfiguration | null }@@ -520,7 +520,7 @@ export type UploadProgress = { progress: number }export type UploadProgressEvent = { video_id: string; uploaded: string; total: string }export type UploadResult = { Success: string } | "NotAuthenticated" | "PlanCheckFailed" | "UpgradeRequired"export type Video = { duration: number; width: number; height: number; fps: number; start_time: number }-export type VideoMeta = { path: string; fps?: number; start_time?: number | null }+export type VideoMeta = { path: string; fps?: number; start_time?: number | null; device_id?: string | null }export type VideoRecordingMetadata = { duration: number; size: number }export type VideoUploadInfo = { id: string; link: string; config: S3UploadMeta }export type WindowExclusion = { bundleIdentifier?: string | null; ownerName?: string | null; windowTitle?: string | null }diff --git a/crates/audio/Cargo.toml b/crates/audio/Cargo.tomlindex 314bff935..3f27ef5cd 100644--- a/crates/audio/Cargo.toml+++ b/crates/audio/Cargo.toml@@ -16,5 +16,8 @@ workspace-hack = { version = "0.1", path = "../workspace-hack" }[target.'cfg(target_os = "macos")'.dependencies]cidre = { workspace = true }+[dev-dependencies]+tempfile = "3"+[lints]workspace = truediff --git a/crates/audio/src/calibration_store.rs b/crates/audio/src/calibration_store.rsindex 86eb5bcfe..0e84b691a 100644--- a/crates/audio/src/calibration_store.rs+++ b/crates/audio/src/calibration_store.rs@@ -1,7 +1,7 @@use crate::sync_analysis::DeviceSyncCalibration;use serde::{Deserialize, Serialize};use std::collections::HashMap;-use std::path::PathBuf;+use std::path::Path;#[derive(Debug, Clone, Serialize, Deserialize, Default)]pub struct CalibrationStore {@@ -32,7 +32,7 @@ impl CalibrationStore {}}- pub fn load(data_dir: &PathBuf) -> Self {+ pub fn load(data_dir: &Path) -> Self {let path = data_dir.join(Self::FILENAME);if !path.exists() {@@ -51,7 +51,7 @@ impl CalibrationStore {}}- pub fn save(&self, data_dir: &PathBuf) -> Result<(), std::io::Error> {+ pub fn save(&self, data_dir: &Path) -> Result<(), std::io::Error> {let path = data_dir.join(Self::FILENAME);if let Some(parent) = path.parent() {@@ -65,7 +65,7 @@ impl CalibrationStore {}fn make_key(camera_id: &str, microphone_id: &str) -> String {- format!("{}|{}", camera_id, microphone_id)+ format!("{camera_id}|{microphone_id}")}pub fn get_calibration(diff --git a/crates/audio/src/sync_analysis.rs b/crates/audio/src/sync_analysis.rsindex 2adc4aa30..1daef4183 100644--- a/crates/audio/src/sync_analysis.rs+++ b/crates/audio/src/sync_analysis.rs@@ -17,6 +17,7 @@ pub struct SyncEvent {pub struct SyncAnalyzer {sample_rate: u32,+ #[allow(dead_code)]fps: f64,audio_buffer: Vec<f32>,video_motion_scores: Vec<(f64, f64)>,@@ -34,7 +35,7 @@ impl SyncAnalyzer {}}- pub fn add_audio_samples(&mut self, samples: &[f32], start_time_secs: f64) {+ pub fn add_audio_samples(&mut self, samples: &[f32], _start_time_secs: f64) {self.audio_buffer.extend_from_slice(samples);}@@ -52,7 +53,6 @@ impl SyncAnalyzer {let window_size = (self.sample_rate as usize) / 100;let hop_size = window_size / 4;- let mut prev_energy = 0.0f64;let mut energies: VecDeque<f64> = VecDeque::with_capacity(10);for (i, chunk) in self.audio_buffer.chunks(hop_size).enumerate() {@@ -81,8 +81,6 @@ impl SyncAnalyzer {transients.push((time_secs, strength.min(3.0)));}}-- prev_energy = energy_db;}transientsdiff --git a/crates/editor/src/audio.rs b/crates/editor/src/audio.rsindex 133b8c550..8d6951247 100644--- a/crates/editor/src/audio.rs+++ b/crates/editor/src/audio.rs@@ -284,6 +284,24 @@ impl<T: FromSampleBytes> AudioPlaybackBuffer<T> {self.frame_buffer.elapsed_samples_to_playhead()}+ pub fn current_audible_playhead(+ &self,+ device_sample_rate: u32,+ device_latency_secs: f64,+ ) -> f64 {+ let generated_secs = self.frame_buffer.elapsed_samples_to_playhead();+ let channels = self.resampler.output.channels;+ let buffered_elements = self.resampled_buffer.occupied_len();+ let buffered_frames = buffered_elements / channels;+ let buffered_secs = buffered_frames as f64 / device_sample_rate as f64;+ let audible = generated_secs - buffered_secs - device_latency_secs.max(0.0);+ if audible.is_sign_negative() {+ 0.0+ } else {+ audible+ }+ }+pub fn buffer_reaching_limit(&self) -> bool {self.resampled_buffer.vacant_len()<= 2 * (Self::PROCESSING_SAMPLES_COUNT as usize) * self.resampler.output.channelsdiff --git a/crates/editor/src/playback.rs b/crates/editor/src/playback.rsindex 5ec4846bb..4c7016462 100644--- a/crates/editor/src/playback.rs+++ b/crates/editor/src/playback.rs@@ -903,6 +903,7 @@ impl AudioPlayback {let latency_config = LatencyCorrectionConfig::default();let mut latency_corrector = LatencyCorrector::new(static_latency_hint, latency_config);let initial_compensation_secs = latency_corrector.initial_compensation_secs();+ let device_sample_rate = sample_rate;{let project_snapshot = project.borrow();@@ -939,13 +940,14 @@ impl AudioPlayback {let stream_result = device.build_output_stream(&config,move |buffer: &mut [T], info| {- let _latency_secs = latency_corrector.update_from_callback(info);+ let latency_secs = latency_corrector.update_from_callback(info);let project = project_for_stream.borrow();if playhead_rx_for_stream.has_changed().unwrap_or(false) {let video_playhead = *playhead_rx_for_stream.borrow_and_update();- let audio_playhead = audio_renderer.current_playhead();+ let audio_playhead = audio_renderer+ .current_audible_playhead(device_sample_rate, latency_secs);let drift = (video_playhead - audio_playhead).abs();if drift > SYNC_THRESHOLD_SECSdiff --git a/crates/recording/Cargo.toml b/crates/recording/Cargo.tomlindex 6d395e96a..6d9d79646 100644--- a/crates/recording/Cargo.toml+++ b/crates/recording/Cargo.toml@@ -15,6 +15,7 @@ cap-audio = { path = "../audio" }cap-fail = { path = "../fail" }cap-project = { path = "../project" }cap-media = { path = "../media" }+cap-rendering = { path = "../rendering" }cap-flags = { path = "../flags" }cap-utils = { path = "../utils" }scap-targets = { path = "../scap-targets" }diff --git a/crates/recording/src/recovery.rs b/crates/recording/src/recovery.rsindex 7fa336898..28de283f1 100644--- a/crates/recording/src/recovery.rs+++ b/crates/recording/src/recovery.rs@@ -795,6 +795,7 @@ impl RecoveryManager {path: RelativePathBuf::from(format!("{segment_base}/display.mp4")),fps,start_time: original_segment.and_then(|s| s.display.start_time),+ device_id: original_segment.and_then(|s| s.display.device_id.clone()),},camera: if camera_path.exists() {Some(VideoMeta {@@ -806,6 +807,9 @@ impl RecoveryManager {start_time: original_segment.and_then(|s| s.camera.as_ref()).and_then(|c| c.start_time),+ device_id: original_segment+ .and_then(|s| s.camera.as_ref())+ .and_then(|c| c.device_id.clone()),})} else {None@@ -816,6 +820,9 @@ impl RecoveryManager {start_time: original_segment.and_then(|s| s.mic.as_ref()).and_then(|m| m.start_time),+ device_id: original_segment+ .and_then(|s| s.mic.as_ref())+ .and_then(|m| m.device_id.clone()),})} else {None@@ -826,6 +833,9 @@ impl RecoveryManager {start_time: original_segment.and_then(|s| s.system_audio.as_ref()).and_then(|a| a.start_time),+ device_id: original_segment+ .and_then(|s| s.system_audio.as_ref())+ .and_then(|a| a.device_id.clone()),})} else {Nonediff --git a/crates/recording/src/sources/audio_mixer.rs b/crates/recording/src/sources/audio_mixer.rsindex 4aa448c44..ea1ecb1b7 100644--- a/crates/recording/src/sources/audio_mixer.rs+++ b/crates/recording/src/sources/audio_mixer.rs@@ -359,7 +359,7 @@ impl AudioMixer {}}- fn tick(&mut self, start: Timestamps, now: Timestamp) -> Result<(), ()> {+ fn tick(&mut self, _start: Timestamps, now: Timestamp) -> Result<(), ()> {self.buffer_sources(now);let Some(start_timestamp) = self.start_timestamp else {@@ -383,7 +383,7 @@ impl AudioMixer {filtered.set_rate(output_rate_i32 as u32);let elapsed = Duration::from_secs_f64(self.samples_out as f64 / output_rate);- let output_timestamp = &start_timestamp + elapsed;+ let output_timestamp = start_timestamp + elapsed;let frame_samples = filtered.samples();let mut frame = AudioFrame::new(filtered, output_timestamp);diff --git a/crates/recording/src/sync_calibration.rs b/crates/recording/src/sync_calibration.rsindex f2af1f5d5..f27da19dc 100644--- a/crates/recording/src/sync_calibration.rs+++ b/crates/recording/src/sync_calibration.rs@@ -150,15 +150,5 @@ pub fn analyze_recording_for_sync(analyzer.process_audio_samples(chunk, time);}- let frame_count = (video.duration * fps).ceil() as u32;- let sample_interval = (frame_count / 100).max(1);-- for frame_idx in (0..frame_count).step_by(sample_interval as usize) {- let time = frame_idx as f64 / fps;- if let Some(frame) = video.get_frame(time as f32) {- analyzer.process_video_frame(&frame.data, time);- }- }-analyzer.finalize_and_save()}diff --git a/crates/recording/tests/recovery.rs b/crates/recording/tests/recovery.rsindex 6055099f1..3d15661f5 100644--- a/crates/recording/tests/recovery.rs+++ b/crates/recording/tests/recovery.rs@@ -110,6 +110,7 @@ impl TestRecording {path: RelativePathBuf::from("content/segments/segment-0/display.mp4"),fps: 30,start_time: None,+ device_id: None,},camera: None,mic: None,