Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/desktop/src-tauri/src/editor_window.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, ops::Deref, sync::Arc};
use std::{collections::HashMap, ops::Deref, path::PathBuf, sync::Arc};

use cap_editor::EditorInstance;
use tauri::{ipc::CommandArg, Manager, Runtime, Window};
Expand Down Expand Up @@ -47,7 +47,7 @@ impl<'de, R: Runtime> CommandArg<'de, R> for WindowEditorInstance {
impl EditorInstances {
pub async fn get_or_create(
window: &Window,
video_id: &str,
path: PathBuf,
) -> Result<Arc<EditorInstance>, String> {
let instances = match window.try_state::<EditorInstances>() {
Some(s) => (*s).clone(),
Expand All @@ -64,7 +64,7 @@ impl EditorInstances {

match instances.entry(window.label().to_string()) {
Entry::Vacant(entry) => {
let instance = create_editor_instance_impl(window.app_handle(), video_id).await?;
let instance = create_editor_instance_impl(window.app_handle(), path).await?;
entry.insert(instance.clone());
Ok(instance)
}
Expand Down
74 changes: 26 additions & 48 deletions apps/desktop/src-tauri/src/export.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
create_editor_instance_impl, get_video_metadata, recordings_path, windows::ShowCapWindow,
AuthStore, RenderProgress, VideoType,
};
use crate::{create_editor_instance_impl, get_video_metadata, RenderProgress};
use cap_editor::EditorInstance;
use cap_project::{ProjectConfiguration, RecordingMeta, XY};
use std::path::PathBuf;
Expand All @@ -11,34 +8,25 @@ use tauri::AppHandle;
#[specta::specta]
pub async fn export_video(
app: AppHandle,
video_id: String,
path: PathBuf,
progress: tauri::ipc::Channel<RenderProgress>,
force: bool,
fps: u32,
resolution_base: XY<u32>,
) -> Result<PathBuf, String> {
let editor_instance = create_editor_instance_impl(&app, &video_id).await?;

let screen_metadata =
match get_video_metadata(app.clone(), video_id.clone(), Some(VideoType::Screen)).await {
Ok(meta) => meta,
Err(e) => {
sentry::capture_message(
&format!("Failed to get video metadata: {}", e),
sentry::Level::Error,
);
return Err(
"Failed to read video metadata. The recording may be from an incompatible version."
.to_string(),
);
}
};
let editor_instance = create_editor_instance_impl(&app, path.clone()).await?;

let screen_metadata = get_video_metadata(path.clone()).await.map_err(|e| {
sentry::capture_message(
&format!("Failed to get video metadata: {}", e),
sentry::Level::Error,
);
"Failed to read video metadata. The recording may be from an incompatible version."
.to_string()
})?;

// Get camera metadata if it exists
let camera_metadata =
get_video_metadata(app.clone(), video_id.clone(), Some(VideoType::Camera))
.await
.ok();
let camera_metadata = get_video_metadata(path.clone()).await.ok();

// Use the longer duration between screen and camera
let duration = screen_metadata.duration.max(
Expand Down Expand Up @@ -71,7 +59,7 @@ pub async fn export_video(
}
}

let exporter = cap_export::Exporter::new(
cap_export::Exporter::new(
modified_project,
output_path.clone(),
move |frame_index| {
Expand All @@ -82,7 +70,7 @@ pub async fn export_video(
.ok();
},
editor_instance.project_path.clone(),
editor_instance.meta(),
editor_instance.meta().clone(),
editor_instance.render_constants.clone(),
&editor_instance.segments,
fps,
Expand All @@ -93,17 +81,13 @@ pub async fn export_video(
.map_err(|e| {
sentry::capture_message(&e.to_string(), sentry::Level::Error);
e.to_string()
})?;

let result = exporter.export_with_custom_muxer().await;

match result {
Ok(_) => Ok(output_path),
Err(e) => {
sentry::capture_message(&e.to_string(), sentry::Level::Error);
Err(e.to_string())
}
}
})?
.export_with_custom_muxer()
.await
.map_err(|e| {
sentry::capture_message(&e.to_string(), sentry::Level::Error);
e.to_string()
})
}

#[derive(Debug, serde::Serialize, specta::Type)]
Expand All @@ -117,26 +101,20 @@ pub struct ExportEstimates {
#[tauri::command]
#[specta::specta]
pub async fn get_export_estimates(
app: AppHandle,
video_id: String,
path: PathBuf,
resolution: XY<u32>,
fps: u32,
) -> Result<ExportEstimates, String> {
let screen_metadata =
get_video_metadata(app.clone(), video_id.clone(), Some(VideoType::Screen)).await?;
let camera_metadata =
get_video_metadata(app.clone(), video_id.clone(), Some(VideoType::Camera))
.await
.ok();
let screen_metadata = get_video_metadata(path.clone()).await?;
let camera_metadata = get_video_metadata(path.clone()).await.ok();

let raw_duration = screen_metadata.duration.max(
camera_metadata
.map(|m| m.duration)
.unwrap_or(screen_metadata.duration),
);

let project_path = EditorInstance::project_path(&recordings_path(&app), &video_id);
let meta = RecordingMeta::load_for_project(&project_path).unwrap();
let meta = RecordingMeta::load_for_project(&path).unwrap();
let project_config = meta.project_config();
let duration_seconds = if let Some(timeline) = &project_config.timeline {
timeline
Expand Down
Loading