From 3dfe45d40b7e92039b75e7f5c5e43117c95d819e Mon Sep 17 00:00:00 2001 From: ykong1337 Date: Tue, 27 Jun 2023 16:41:20 +0800 Subject: [PATCH] successfully merged --- src/utils.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index f36b27c..48f1cc2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -54,25 +54,18 @@ pub fn ffmpeg_merge(audio: Option, image: Option, subtitle: Op thread::spawn(move || { MERGE.store(true, Ordering::Relaxed); let mut cmd = Command::new("ffmpeg"); - if let Some(ref image) = image { + if let (Some(ref image), Some(ref audio), Some(ref subtitle)) = (image, audio, subtitle) { + let output = audio.with_extension("mp4"); cmd.args([ "-loop", "1", - "-y", "-i", image.to_str().unwrap(), - ]); - } - if let (Some(ref audio), Some(ref subtitle)) = (audio, subtitle) { - let output = audio.with_extension("mp4"); - if output.exists() { - fs::remove_file(&output).unwrap_or(()); - } - cmd.args([ "-i", audio.to_str().unwrap(), "-vf", - &format!("subtitles={}", subtitle.to_str().unwrap()), + &format!("subtitles={}", subtitle.file_name().unwrap().to_str().unwrap()), + "-y", "-shortest", output.to_str().unwrap(), ]); @@ -86,7 +79,6 @@ pub fn ffmpeg_merge(audio: Option, image: Option, subtitle: Op return; } } - MERGE.store(false, Ordering::Relaxed); }); } \ No newline at end of file