Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

go back to uploading audio and video spearately

Brendan Allanf5bcab2fb828
diff --git a/apps/desktop/src-tauri/src/media.rs b/apps/desktop/src-tauri/src/media.rs
index baa90ae77..de6837fa0 100644
--- a/apps/desktop/src-tauri/src/media.rs
+++ b/apps/desktop/src-tauri/src/media.rs
@@ -61,9 +61,9 @@ impl MediaRecorder {
pub async fn start_media_recording(
&mut self,
options: RecordingOptions,
+ screenshot_dir: &Path,
audio_chunks_dir: &Path,
video_chunks_dir: &Path,
- screenshot_folder: &Path,
custom_device: Option<&str>,
max_screen_width: usize,
max_screen_height: usize,
@@ -306,7 +306,7 @@ impl MediaRecorder {
}
let video_start_time_clone = Arc::clone(&video_start_time);
- let screenshot_file_path = screenshot_folder.join("screen-capture.jpg");
+ let screenshot_file_path = screenshot_dir.join("screen-capture.jpg");
let capture_frame_at = Duration::from_secs(3);
std::thread::spawn(move || {
diff --git a/apps/desktop/src-tauri/src/recording.rs b/apps/desktop/src-tauri/src/recording.rs
index f52d02e70..414f596f1 100644
--- a/apps/desktop/src-tauri/src/recording.rs
+++ b/apps/desktop/src-tauri/src/recording.rs
@@ -79,9 +79,9 @@ pub async fn start_dual_recording(
let media_recording_preparation = prepare_media_recording(
&options,
+ &screenshot_dir,
&audio_chunks_dir,
&video_chunks_dir,
- &screenshot_dir,
audio_name,
state_guard.max_screen_width,
state_guard.max_screen_height,
@@ -102,32 +102,26 @@ pub async fn start_dual_recording(
};
if !is_local_mode {
- let screen_upload = start_upload_loop(
+ let video_upload = start_upload_loop(
video_chunks_dir.clone(),
options.clone(),
- "video".to_string(),
+ upload::FileType::Video,
shutdown_flag.clone(),
state_guard.video_uploading_finished.clone(),
);
let audio_upload = start_upload_loop(
audio_chunks_dir,
options.clone(),
- "audio".to_string(),
+ upload::FileType::Audio,
shutdown_flag.clone(),
state_guard.audio_uploading_finished.clone(),
);
- let upload = start_upload_loop(
- chunks_dir.clone(),
- options.clone(),
- shutdown_flag.clone(),
- state_guard.uploading_finished.clone(),
- );
drop(state_guard);
println!("Starting upload loops...");
- match upload.await {
+ match tokio::try_join!(video_upload, audio_upload) {
Ok(_) => {
println!("Both upload loops completed successfully.");
}
diff --git a/apps/web/app/api/upload/mux/create/route.ts b/apps/web/app/api/upload/mux/create/route.ts
index 4de99e9e5..bea163b5d 100644
--- a/apps/web/app/api/upload/mux/create/route.ts
+++ b/apps/web/app/api/upload/mux/create/route.ts
@@ -97,7 +97,8 @@ export async function GET(request: NextRequest) {
}
const bucket = process.env.CAP_AWS_BUCKET || "";
- const segmentsPrefix = `${userId}/${videoId}/segment/`;
+ const videoPrefix = `${userId}/${videoId}/video/`;
+ const audioPrefix = `${userId}/${videoId}/audio/`;
try {
const s3Client = new S3Client({
@@ -108,18 +109,24 @@ export async function GET(request: NextRequest) {
},
});
- const segmentsCommand = new ListObjectsV2Command({
+ const videoSegmentCommand = new ListObjectsV2Command({
Bucket: bucket,
- Prefix: segmentsPrefix,
+ Prefix: videoPrefix,
});
- const segments = await s3Client.send(segmentsCommand);
+ const audioSegmentCommand = new ListObjectsV2Command({
+ Bucket: bucket,
+ Prefix: audioPrefix,
+ });
+
+ const videoSegments = await s3Client.send(videoSegmentCommand);
+ const audioSegments = await s3Client.send(audioSegmentCommand);
- const segmentKeys = (segments.Contents || []).map(
+ const videoSegmentKeys = (videoSegments.Contents || []).map(
(object) => `s3://${bucket}/${object.Key}`
);
- if (segmentKeys.length > 149) {
+ if (videoSegmentKeys.length > 149) {
await db
.update(videos)
.set({ skipProcessing: true })
@@ -141,6 +148,10 @@ export async function GET(request: NextRequest) {
);
}
+ const audioSegmentKeys = (audioSegments.Contents || []).map(
+ (object) => `s3://${bucket}/${object.Key}`
+ );
+
const mediaConvertClient = new MediaConvertClient({
region: process.env.CAP_AWS_REGION || "",
credentials: {
@@ -154,14 +165,18 @@ export async function GET(request: NextRequest) {
const createJobCommand = new CreateJobCommand({
Role: process.env.CAP_AWS_MEDIACONVERT_ROLE_ARN || "",
Settings: {
- Inputs: segmentKeys.map((videoSegmentKey) => {
+ Inputs: videoSegmentKeys.map((videoSegmentKey, index) => {
+ const audioSegmentKey = audioSegmentKeys[index];
return {
FileInput: videoSegmentKey,
- AudioSelectors: {
- "Audio Selector 1": {
- DefaultSelection: "DEFAULT",
+ ...(audioSegmentKey && {
+ AudioSelectors: {
+ "Audio Selector 1": {
+ DefaultSelection: "DEFAULT",
+ ExternalAudioFileInput: audioSegmentKey,
+ },
},
- },
+ }),
VideoSelector: {},
TimecodeSource: "ZEROBASED",
};
@@ -203,19 +218,21 @@ export async function GET(request: NextRequest) {
},
},
},
- AudioDescriptions: [
- {
- AudioSourceName: "Audio Selector 1",
- CodecSettings: {
- Codec: "AAC",
- AacSettings: {
- Bitrate: 128000,
- CodingMode: "CODING_MODE_2_0",
- SampleRate: 48000,
+ ...(audioSegmentKeys.length > 0 && {
+ AudioDescriptions: [
+ {
+ AudioSourceName: "Audio Selector 1",
+ CodecSettings: {
+ Codec: "AAC",
+ AacSettings: {
+ Bitrate: 128000,
+ CodingMode: "CODING_MODE_2_0",
+ SampleRate: 48000,
+ },
},
},
- },
- ],
+ ],
+ }),
},
],
},