Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat: Uploading improvements, higher FPS/res
Richie McIlroyc6f07ae8bb43
diff --git a/apps/desktop/src-tauri/Cargo.lock b/apps/desktop/src-tauri/Cargo.lockindex e7bd1c674..b72291cbe 100644--- a/apps/desktop/src-tauri/Cargo.lock+++ b/apps/desktop/src-tauri/Cargo.lock@@ -451,6 +451,7 @@ name = "cap"version = "0.0.0"dependencies = ["ffmpeg-sidecar",+ "futures","reqwest","serde","serde_json",@@ -459,6 +460,7 @@ dependencies = ["tauri-plugin-context-menu","tauri-plugin-positioner","tokio",+ "tokio-util","which",]@@ -1133,6 +1135,21 @@ dependencies = ["new_debug_unreachable",]+[[package]]+name = "futures"+version = "0.3.30"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0"+dependencies = [+ "futures-channel",+ "futures-core",+ "futures-executor",+ "futures-io",+ "futures-sink",+ "futures-task",+ "futures-util",+]+[[package]]name = "futures-channel"version = "0.3.30"@@ -1140,6 +1157,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78"dependencies = ["futures-core",+ "futures-sink",][[package]]@@ -1222,6 +1240,7 @@ version = "0.3.30"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"dependencies = [+ "futures-channel","futures-core","futures-io","futures-macro",diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.tomlindex 3f80ec9f4..bd33b451a 100644--- a/apps/desktop/src-tauri/Cargo.toml+++ b/apps/desktop/src-tauri/Cargo.toml@@ -20,8 +20,10 @@ tauri-plugin-context-menu = "0.5.0"tauri-plugin-positioner = { version = "1.0.4", features = ["system-tray"] }ffmpeg-sidecar = "0.5.1"which = "4.2.2"-tokio = { version = "1", features = ["full"] }-reqwest = { version = "0.11", features = ["json", "multipart"] }+tokio = { version = "1.35.1", features = ["full"] }+tokio-util = { version = "0.7.10", features = ["io"] }+futures = "0.3.30"+reqwest = { version = "0.11.23", features = ["json", "multipart", "stream"] }[features]# this feature is used for production builds or when `devPath` points to the filesystemdiff --git a/apps/desktop/src-tauri/src/recording.rs b/apps/desktop/src-tauri/src/recording.rsindex 431703bca..6570d7278 100644--- a/apps/desktop/src-tauri/src/recording.rs+++ b/apps/desktop/src-tauri/src/recording.rs@@ -22,6 +22,7 @@ pub struct RecordingOptions {pub video_id: String,pub screen_index: String,pub video_index: String,+ pub audio_index: String,pub aws_region: String,pub aws_bucket: String,pub framerate: String,@@ -50,8 +51,8 @@ pub async fn start_dual_recording(clean_and_create_dir(&screen_chunks_dir)?;clean_and_create_dir(&video_chunks_dir)?;- let ffmpeg_screen_args_future = construct_recording_args(&options, &screen_chunks_dir, "screen", &options.screen_index);- let ffmpeg_video_args_future = construct_recording_args(&options, &video_chunks_dir, "video", &options.video_index);+ let ffmpeg_screen_args_future = construct_recording_args(&options, &screen_chunks_dir, "screen", &options.screen_index, &options.video_index);+ let ffmpeg_video_args_future = construct_recording_args(&options, &video_chunks_dir, "video", &options.video_index, &options.audio_index);// Await the futures to get the argumentslet ffmpeg_screen_args = ffmpeg_screen_args_future.await.map_err(|e| e.to_string())?;@@ -131,6 +132,7 @@ async fn construct_recording_args(chunks_dir: &Path,video_type: &str,input_index: &str,+ audio_index: &str,) -> Result<Vec<String>, String> {let output_filename_pattern = format!("{}/recording_chunk_%03d.mkv", chunks_dir.display());let fps = if video_type == "screen" { "60" } else { &options.framerate };@@ -140,6 +142,9 @@ async fn construct_recording_args(let codec = "libx264".to_string();let gop = "60".to_string();let segment_time = "10".to_string();++ //Set the correct input index. If screen, just use the index. If video, use the index and the audio index+ let input_string = if video_type == "screen" { input_index.to_string() } else { format!("{}:{}", input_index, audio_index) };match std::env::consts::OS {"macos" => {@@ -165,8 +170,9 @@ async fn construct_recording_args("-f".to_string(), "avfoundation".to_string(),"-video_size".to_string(), options.resolution.to_string(),"-framerate".to_string(), fps.to_string(),- "-i".to_string(), format!("{}:none", input_index),+ "-i".to_string(), input_string.to_string(),"-c:v".to_string(), codec,+ "-c:a".to_string(), "aac".to_string(),"-preset".to_string(), preset,"-pix_fmt".to_string(), pix_fmt,"-fps_mode".to_string(), "vfr".to_string(),diff --git a/apps/desktop/src-tauri/src/upload.rs b/apps/desktop/src-tauri/src/upload.rsindex 930a6dabe..4df6b892e 100644--- a/apps/desktop/src-tauri/src/upload.rs+++ b/apps/desktop/src-tauri/src/upload.rs@@ -1,5 +1,7 @@use serde_json::Value as JsonValue;use std::path::{Path};+use futures::{TryStreamExt};+use tokio_util::codec::{BytesCodec, FramedRead};use reqwest;use crate::recording::RecordingOptions;@@ -61,14 +63,20 @@ pub async fn upload_video(println!("Uploading file: {}", file_path);- // Add the file content- let file_bytes = tokio::fs::read(&file_path).await.map_err(|e| format!("Failed to read file: {}", e))?;- let file_part = reqwest::multipart::Part::stream(reqwest::Body::from(file_bytes))- .file_name(format!("{}", file_name));+ let file = tokio::fs::File::open(&file_path).await.map_err(|e| format!("Failed to open file: {}", e))?;+ let metadata = file.metadata().await.map_err(|e| format!("Failed to extract file metadata: {}", e))?;+ let file_length = metadata.len();++ println!("Uploading file: {} with size: {}", file_path, file_length);++ let stream = FramedRead::new(file, BytesCodec::new()).map_ok(|bytes| bytes.freeze());+ let file_part = reqwest::multipart::Part::stream(reqwest::Body::wrap_stream(stream))+ .file_name(file_name.clone())+ .mime_str("application/octet-stream")+ .map_err(|e| format!("Error setting MIME type: {}", e))?;form = form.part("file", file_part);- // Extract the URL and send the form to the presigned URL for uploadlet post_url = presigned_post_data["presignedPostData"]["url"].as_str().ok_or("URL is missing or not a string")?;diff --git a/apps/desktop/src/components/windows/Camera.tsx b/apps/desktop/src/components/windows/Camera.tsxindex 6b2121ed0..00af7b161 100644--- a/apps/desktop/src/components/windows/Camera.tsx+++ b/apps/desktop/src/components/windows/Camera.tsx@@ -22,6 +22,9 @@ export const Camera = () => {navigator.mediaDevices.getUserMedia({video: {deviceId: deviceId,+ frameRate: { ideal: 30 },+ width: { ideal: 1920 },+ height: { ideal: 1080 },},}))@@ -29,10 +32,13 @@ export const Camera = () => {let video = videoRef.current;if (video) {video.srcObject = stream;- video.play();+ video.onplaying = () => {+ setIsLoading(false);+ };+ video.play().catch((error) => {+ console.error("Error attempting to play the video:", error);+ });}-- setIsLoading(false);}).catch((err) => {console.error(err);diff --git a/apps/desktop/src/components/windows/inner/Recorder.tsx b/apps/desktop/src/components/windows/inner/Recorder.tsxindex 899aac2cd..2a353732e 100644--- a/apps/desktop/src/components/windows/inner/Recorder.tsx+++ b/apps/desktop/src/components/windows/inner/Recorder.tsx@@ -126,7 +126,8 @@ export const Recorder = ({ session }: { session: AuthSession | null }) => {aws_region: videoData.aws_region,aws_bucket: videoData.aws_bucket,screen_index: "Capture screen 0",- video_index: "0",+ video_index: String(selectedVideoDevice?.index),+ audio_index: String(selectedAudioDevice?.index),...mediaSettings,},}).catch((error) => {