fix: address final review findings (clip reset, codecs, paths, timeline)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -25,6 +25,7 @@ pub async fn export_clips(
|
||||
on_event: Channel<ExportEvent>,
|
||||
) -> Result<Vec<String>, String> {
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let output_directory = clip_exporter::expand_tilde_path(&config.output_directory);
|
||||
let ext = clip_exporter::get_extension(&config.source_file_path, &config.cut_mode);
|
||||
|
||||
match config.export_scope {
|
||||
@@ -40,7 +41,7 @@ pub async fn export_clips(
|
||||
});
|
||||
|
||||
let output = clip_exporter::generate_output_path(
|
||||
&config.output_directory,
|
||||
&output_directory,
|
||||
&config.video_title,
|
||||
&clip.label,
|
||||
&ext,
|
||||
@@ -69,7 +70,7 @@ pub async fn export_clips(
|
||||
});
|
||||
|
||||
let output = clip_exporter::generate_output_path(
|
||||
&config.output_directory,
|
||||
&output_directory,
|
||||
&config.video_title,
|
||||
"Merged",
|
||||
&ext,
|
||||
|
||||
@@ -23,11 +23,20 @@ pub fn build_ffmpeg_args(
|
||||
args.extend(["-c".to_string(), "copy".to_string()]);
|
||||
}
|
||||
CutMode::Precise { format: _ } => {
|
||||
let ext = Path::new(output)
|
||||
.extension()
|
||||
.map(|e| e.to_string_lossy().to_ascii_lowercase())
|
||||
.unwrap_or_default();
|
||||
let (video_codec, audio_codec) = match ext.as_str() {
|
||||
"webm" => ("libvpx-vp9", "libopus"),
|
||||
"mp4" | "mkv" => ("libx264", "aac"),
|
||||
_ => ("libx264", "aac"),
|
||||
};
|
||||
args.extend([
|
||||
"-c:v".to_string(),
|
||||
"libx264".to_string(),
|
||||
video_codec.to_string(),
|
||||
"-c:a".to_string(),
|
||||
"aac".to_string(),
|
||||
audio_codec.to_string(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -36,6 +45,20 @@ pub fn build_ffmpeg_args(
|
||||
args
|
||||
}
|
||||
|
||||
pub fn expand_tilde_path(path: &str) -> String {
|
||||
if path == "~" {
|
||||
return dirs::home_dir()
|
||||
.map(|p| p.to_string_lossy().to_string())
|
||||
.unwrap_or_else(|| path.to_string());
|
||||
}
|
||||
if let Some(rest) = path.strip_prefix("~/") {
|
||||
if let Some(home) = dirs::home_dir() {
|
||||
return home.join(rest).to_string_lossy().to_string();
|
||||
}
|
||||
}
|
||||
path.to_string()
|
||||
}
|
||||
|
||||
pub fn generate_output_path(
|
||||
output_dir: &str,
|
||||
video_title: &str,
|
||||
@@ -206,6 +229,18 @@ mod tests {
|
||||
let args = build_ffmpeg_args(&clip, "input.mp4", "output.mp4", &mode);
|
||||
assert!(args.contains(&"-c:v".to_string()));
|
||||
assert!(args.contains(&"libx264".to_string()));
|
||||
assert!(args.contains(&"aac".to_string()));
|
||||
|
||||
let webm_args = build_ffmpeg_args(&clip, "input.mp4", "output.webm", &mode);
|
||||
assert!(webm_args.contains(&"libvpx-vp9".to_string()));
|
||||
assert!(webm_args.contains(&"libopus".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expand_tilde_path() {
|
||||
let expanded = expand_tilde_path("~/Videos");
|
||||
assert!(!expanded.starts_with("~/"));
|
||||
assert!(expanded.ends_with("Videos") || expanded.contains("Videos"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user