Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Add video metadata to thumbnail

Richie McIlroyaf4987ee4ce4
diff --git a/apps/desktop-solid/src-tauri/src/lib.rs b/apps/desktop-solid/src-tauri/src/lib.rs
index 2ab8788c8..5aa54e468 100644
--- a/apps/desktop-solid/src-tauri/src/lib.rs
+++ b/apps/desktop-solid/src-tauri/src/lib.rs
@@ -351,41 +351,40 @@ async fn copy_rendered_video_to_clipboard(
#[tauri::command]
#[specta::specta]
-async fn get_screen_video_metadata(
+async fn get_video_metadata(
app: AppHandle,
video_id: String,
state: MutableState<'_, App>,
) -> Result<(f64, f64), String> {
- let screen_video_path = {
- println!("Getting screen video metadata");
-
- let recordings_dir = app
- .path()
- .app_data_dir()
- .unwrap()
- .join("recordings")
- .join(format!("{video_id}.cap"));
- let screen_video_path = recordings_dir.join("content/display.mp4");
+ let video_dir = app
+ .path()
+ .app_data_dir()
+ .unwrap()
+ .join("recordings")
+ .join(format!("{video_id}"));
- println!("Screen video path: {:?}", screen_video_path);
+ let screen_video_path = video_dir.join("content/display.mp4");
+ let output_video_path = video_dir.join("output/result.mp4");
+ let video_path = if output_video_path.exists() {
+ println!("Using output video path: {:?}", output_video_path);
+ output_video_path
+ } else {
+ println!("Using screen video path: {:?}", screen_video_path);
if !screen_video_path.exists() {
return Err(format!(
"Screen video does not exist: {:?}",
screen_video_path
));
}
-
screen_video_path
};
- let file = File::open(&screen_video_path).map_err(|e| {
+ let file = File::open(&video_path).map_err(|e| {
println!("Failed to open video file: {}", e);
format!("Failed to open video file: {}", e)
})?;
- println!("File opened successfully: {:?}", file);
-
let size = (file
.metadata()
.map_err(|e| {
@@ -398,7 +397,7 @@ async fn get_screen_video_metadata(
println!("File size: {} MB", size);
let reader = BufReader::new(file);
- let file_size = screen_video_path
+ let file_size = video_path
.metadata()
.map_err(|e| {
println!("Failed to get file metadata: {}", e);
@@ -406,19 +405,15 @@ async fn get_screen_video_metadata(
})?
.len();
- println!("File size in bytes: {}", file_size);
-
let mp4 = Mp4Reader::read_header(reader, file_size).map_err(|e| {
println!("Failed to read MP4 header: {}", e);
format!("Failed to read MP4 header: {}", e)
})?;
- println!("MP4 header read successfully: {:?}", mp4);
-
let duration = mp4.duration().as_secs_f64();
- println!("Video duration: {} seconds", duration);
- println!("Video size: {} MB", size);
+ println!("Duration: {} seconds", duration);
+ println!("Size: {} MB", size);
Ok((duration, size))
}
@@ -631,7 +626,7 @@ pub fn run() {
render_video,
get_rendered_video,
copy_rendered_video_to_clipboard,
- get_screen_video_metadata
+ get_video_metadata
])
.events(tauri_specta::collect_events![
RecordingOptionsChanged,
diff --git a/apps/desktop-solid/src-tauri/src/recording.rs b/apps/desktop-solid/src-tauri/src/recording.rs
index 34db470e6..46ca23003 100644
--- a/apps/desktop-solid/src-tauri/src/recording.rs
+++ b/apps/desktop-solid/src-tauri/src/recording.rs
@@ -33,15 +33,17 @@ pub struct InProgressRecording {
impl InProgressRecording {
pub async fn stop(&mut self) {
+ self.ffmpeg_process.stop();
+
+ if let Err(e) = self.ffmpeg_process.wait() {
+ eprintln!("Failed to wait for ffmpeg process: {:?}", e);
+ }
+
self.display.capture.stop();
if let Some(camera) = &self.camera {
camera.capture.stop();
}
- self.ffmpeg_process.stop();
-
- self.ffmpeg_process.wait();
-
// let render_options = RenderOptions {
// screen_recording_path: self.display.output_path.clone(),
// webcam_recording_path: self
diff --git a/apps/desktop-solid/src/routes/prev-recordings.tsx b/apps/desktop-solid/src/routes/prev-recordings.tsx
index 0aff48b0f..734d2b274 100644
--- a/apps/desktop-solid/src/routes/prev-recordings.tsx
+++ b/apps/desktop-solid/src/routes/prev-recordings.tsx
@@ -44,14 +44,31 @@ export default function () {
const [exiting, setExiting] = createSignal(false);
const [isLoading, setIsLoading] = createSignal(false);
const [isSuccess, setIsSuccess] = createSignal(false);
+ const [metadata, setMetadata] = createSignal({
+ duration: 0,
+ size: 0,
+ });
const { present } = createPresence({
show: () => !exiting(),
element: ref,
});
- commands.getScreenVideoMetadata(recording).then((metadata) => {
- console.log(metadata);
+ createEffect(() => {
+ commands.getVideoMetadata(recording).then((result) => {
+ if (result.status === "ok") {
+ const [duration, size] = result.data;
+ console.log(
+ `Metadata for ${recording}: duration=${duration}, size=${size}`
+ );
+ setMetadata({
+ duration,
+ size,
+ });
+ } else {
+ console.error(`Failed to get metadata: ${result.error}`);
+ }
+ });
});
createEffect(
@@ -91,7 +108,7 @@ export default function () {
// }}
class={cx(
- "w-[300px] h-[172px] rounded-xl overflow-hidden shadow border border-gray-100/20 relative flex flex-col items-center justify-center border-[5px] border-gray-500 ring-[1px]ring-white shadow-[0px 2px 4px rgba(18, 22, 31, 0.12)]",
+ "w-[300px] h-[172px] rounded-xl overflow-hidden shadow border border-gray-100/20 relative flex flex-col items-center justify-center border-[5px] border-gray-500 ring-[1px]ring-white shadow-[0px 2px 4px rgba(18, 22, 31, 0.12)] group transition-all",
"transition-[transform,opacity] duration-300",
exiting()
? "animate-out slide-out-to-left-32 fade-out"
@@ -103,7 +120,7 @@ export default function () {
alt="screenshot"
src={convertFileSrc(`${recording}/screenshots/display.jpg`)}
/>
- <div class="w-full h-full absolute inset-0 transition-all opacity-0 hover:opacity-100 backdrop-blur hover:backdrop-blur bg-gray-500/80 text-white p-4">
+ <div class="w-full h-full absolute inset-0 transition-all opacity-0 group-hover:opacity-100 backdrop-blur group-hover:backdrop-blur bg-gray-500/80 text-white p-4">
<TooltipIconButton
class="absolute left-3 top-3"
tooltipText="Close"
@@ -193,6 +210,19 @@ export default function () {
Save
</IconButton>
</div>
+ <div
+ style={{ color: "white", "font-size": "14px" }}
+ class="absolute bottom-0 left-0 right-0 font-medium bg-gray-500/40 backdrop-blur p-2 flex justify-between items-center group-hover:opacity-0 pointer-events-none transition-all"
+ >
+ <p class="flex items-center">
+ <IconCapCamera class="w-[20px] h-[20px] mr-1" />
+ {Math.floor(metadata().duration / 60)}:
+ {Math.floor(metadata().duration % 60)
+ .toString()
+ .padStart(2, "0")}
+ </p>
+ <p>{metadata().size.toFixed(2)} MB</p>
+ </div>
</div>
</Show>
);
diff --git a/apps/desktop-solid/src/utils/tauri.ts b/apps/desktop-solid/src/utils/tauri.ts
index 2aa03704a..8ca717687 100644
--- a/apps/desktop-solid/src/utils/tauri.ts
+++ b/apps/desktop-solid/src/utils/tauri.ts
@@ -108,9 +108,9 @@ async copyRenderedVideoToClipboard(videoId: string, project: ProjectConfiguratio
else return { status: "error", error: e as any };
}
},
-async getScreenVideoMetadata(videoId: string) : Promise<Result<[number, number], string>> {
+async getVideoMetadata(videoId: string) : Promise<Result<[number, number], string>> {
try {
- return { status: "ok", data: await TAURI_INVOKE("get_screen_video_metadata", { videoId }) };
+ return { status: "ok", data: await TAURI_INVOKE("get_video_metadata", { videoId }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };