From c97adb3ce7c5175b54eab9183a4c8743f6b1b168 Mon Sep 17 00:00:00 2001 From: ByteDream Date: Thu, 23 Mar 2023 17:17:55 +0100 Subject: [PATCH] Remove duplicated subtitles on archive audio merge --- crunchy-cli-core/src/archive/filter.rs | 10 +++++++++- crunchy-cli-core/src/utils/ffmpeg.rs | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/crunchy-cli-core/src/archive/filter.rs b/crunchy-cli-core/src/archive/filter.rs index abf2759..c1d1c4a 100644 --- a/crunchy-cli-core/src/archive/filter.rs +++ b/crunchy-cli-core/src/archive/filter.rs @@ -446,7 +446,15 @@ impl Filter for ArchiveFilter { .iter() .map(|d| (d.audio.clone(), d.format.audio.clone())) .collect(), - subtitles: data.iter().map(|d| d.subtitles.clone()).flatten().collect(), + // mix all subtitles together and then reduce them via a map so that only one + // subtitle per language exists + subtitles: data + .iter() + .flat_map(|d| d.subtitles.clone()) + .map(|s| (s.locale.clone(), s)) + .collect::>() + .into_values() + .collect(), }), MergeBehavior::Auto => { let mut download_formats: HashMap = HashMap::new(); diff --git a/crunchy-cli-core/src/utils/ffmpeg.rs b/crunchy-cli-core/src/utils/ffmpeg.rs index 54ededd..3336fca 100644 --- a/crunchy-cli-core/src/utils/ffmpeg.rs +++ b/crunchy-cli-core/src/utils/ffmpeg.rs @@ -285,7 +285,14 @@ impl FFmpegPreset { if let Some(hwaccel) = hwaccel_opt { match hwaccel { FFmpegHwAccel::Nvidia => { - input.extend(["-hwaccel", "cuda", "-hwaccel_output_format", "cuda", "-c:v", "h264_cuvid"]); + input.extend([ + "-hwaccel", + "cuda", + "-hwaccel_output_format", + "cuda", + "-c:v", + "h264_cuvid", + ]); output.extend(["-c:v", "h264_nvenc", "-c:a", "copy"]) } } @@ -303,7 +310,14 @@ impl FFmpegPreset { if let Some(hwaccel) = hwaccel_opt { match hwaccel { FFmpegHwAccel::Nvidia => { - input.extend(["-hwaccel", "cuda", "-hwaccel_output_format", "cuda", "-c:v", "h264_cuvid"]); + input.extend([ + "-hwaccel", + "cuda", + "-hwaccel_output_format", + "cuda", + "-c:v", + "h264_cuvid", + ]); output.extend(["-c:v", "hevc_nvenc", "-c:a", "copy"]) } }