mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 04:02:00 -06:00
Add --ffmpeg-threads flag to control the ffmpeg thread number
This commit is contained in:
parent
6c7ab04b99
commit
b4057599a1
3 changed files with 38 additions and 4 deletions
|
|
@ -90,6 +90,16 @@ pub struct Archive {
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
#[arg(value_parser = FFmpegPreset::parse)]
|
#[arg(value_parser = FFmpegPreset::parse)]
|
||||||
pub(crate) ffmpeg_preset: Option<FFmpegPreset>,
|
pub(crate) ffmpeg_preset: Option<FFmpegPreset>,
|
||||||
|
#[arg(
|
||||||
|
help = "The number of threads used by ffmpeg to generate the output file. Does not work with every codec/preset"
|
||||||
|
)]
|
||||||
|
#[arg(
|
||||||
|
long_help = "The number of threads used by ffmpeg to generate the output file. \
|
||||||
|
Does not work with every codec/preset and is skipped entirely when specifying custom ffmpeg output arguments instead of a preset for `--ffmpeg-preset`. \
|
||||||
|
By default, ffmpeg chooses the thread count which works best for the output codec"
|
||||||
|
)]
|
||||||
|
#[arg(long)]
|
||||||
|
pub(crate) ffmpeg_threads: Option<usize>,
|
||||||
|
|
||||||
#[arg(
|
#[arg(
|
||||||
help = "Set which subtitle language should be set as default / auto shown when starting a video"
|
help = "Set which subtitle language should be set as default / auto shown when starting a video"
|
||||||
|
|
@ -182,6 +192,7 @@ impl Execute for Archive {
|
||||||
let download_builder = DownloadBuilder::new()
|
let download_builder = DownloadBuilder::new()
|
||||||
.default_subtitle(self.default_subtitle.clone())
|
.default_subtitle(self.default_subtitle.clone())
|
||||||
.ffmpeg_preset(self.ffmpeg_preset.clone().unwrap_or_default())
|
.ffmpeg_preset(self.ffmpeg_preset.clone().unwrap_or_default())
|
||||||
|
.ffmpeg_threads(self.ffmpeg_threads)
|
||||||
.output_format(Some("matroska".to_string()))
|
.output_format(Some("matroska".to_string()))
|
||||||
.audio_sort(Some(self.audio.clone()))
|
.audio_sort(Some(self.audio.clone()))
|
||||||
.subtitle_sort(Some(self.subtitle.clone()))
|
.subtitle_sort(Some(self.subtitle.clone()))
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,16 @@ pub struct Download {
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
#[arg(value_parser = FFmpegPreset::parse)]
|
#[arg(value_parser = FFmpegPreset::parse)]
|
||||||
pub(crate) ffmpeg_preset: Option<FFmpegPreset>,
|
pub(crate) ffmpeg_preset: Option<FFmpegPreset>,
|
||||||
|
#[arg(
|
||||||
|
help = "The number of threads used by ffmpeg to generate the output file. Does not work with every codec/preset"
|
||||||
|
)]
|
||||||
|
#[arg(
|
||||||
|
long_help = "The number of threads used by ffmpeg to generate the output file. \
|
||||||
|
Does not work with every codec/preset and is skipped entirely when specifying custom ffmpeg output arguments instead of a preset for `--ffmpeg-preset`. \
|
||||||
|
By default, ffmpeg chooses the thread count which works best for the output codec"
|
||||||
|
)]
|
||||||
|
#[arg(long)]
|
||||||
|
pub(crate) ffmpeg_threads: Option<usize>,
|
||||||
|
|
||||||
#[arg(help = "Skip files which are already existing")]
|
#[arg(help = "Skip files which are already existing")]
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
|
|
@ -203,6 +213,7 @@ impl Execute for Download {
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
.ffmpeg_preset(self.ffmpeg_preset.clone().unwrap_or_default())
|
.ffmpeg_preset(self.ffmpeg_preset.clone().unwrap_or_default())
|
||||||
|
.ffmpeg_threads(self.ffmpeg_threads)
|
||||||
.threads(self.threads);
|
.threads(self.threads);
|
||||||
|
|
||||||
for mut single_formats in single_format_collection.into_iter() {
|
for mut single_formats in single_format_collection.into_iter() {
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ pub struct DownloadBuilder {
|
||||||
subtitle_sort: Option<Vec<Locale>>,
|
subtitle_sort: Option<Vec<Locale>>,
|
||||||
force_hardsub: bool,
|
force_hardsub: bool,
|
||||||
threads: usize,
|
threads: usize,
|
||||||
|
ffmpeg_threads: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DownloadBuilder {
|
impl DownloadBuilder {
|
||||||
|
|
@ -63,6 +64,7 @@ impl DownloadBuilder {
|
||||||
subtitle_sort: None,
|
subtitle_sort: None,
|
||||||
force_hardsub: false,
|
force_hardsub: false,
|
||||||
threads: num_cpus::get(),
|
threads: num_cpus::get(),
|
||||||
|
ffmpeg_threads: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,7 +77,9 @@ impl DownloadBuilder {
|
||||||
subtitle_sort: self.subtitle_sort,
|
subtitle_sort: self.subtitle_sort,
|
||||||
|
|
||||||
force_hardsub: self.force_hardsub,
|
force_hardsub: self.force_hardsub,
|
||||||
threads: self.threads,
|
|
||||||
|
download_threads: self.threads,
|
||||||
|
ffmpeg_threads: self.ffmpeg_threads,
|
||||||
|
|
||||||
formats: vec![],
|
formats: vec![],
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +106,9 @@ pub struct Downloader {
|
||||||
subtitle_sort: Option<Vec<Locale>>,
|
subtitle_sort: Option<Vec<Locale>>,
|
||||||
|
|
||||||
force_hardsub: bool,
|
force_hardsub: bool,
|
||||||
threads: usize,
|
|
||||||
|
download_threads: usize,
|
||||||
|
ffmpeg_threads: Option<usize>,
|
||||||
|
|
||||||
formats: Vec<DownloadFormat>,
|
formats: Vec<DownloadFormat>,
|
||||||
}
|
}
|
||||||
|
|
@ -343,6 +349,7 @@ impl Downloader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let preset_custom = matches!(self.ffmpeg_preset, FFmpegPreset::Custom(_));
|
||||||
let (input_presets, mut output_presets) = self.ffmpeg_preset.into_input_output_args();
|
let (input_presets, mut output_presets) = self.ffmpeg_preset.into_input_output_args();
|
||||||
let fifo = temp_named_pipe()?;
|
let fifo = temp_named_pipe()?;
|
||||||
|
|
||||||
|
|
@ -356,6 +363,11 @@ impl Downloader {
|
||||||
command_args.extend(input);
|
command_args.extend(input);
|
||||||
command_args.extend(maps);
|
command_args.extend(maps);
|
||||||
command_args.extend(metadata);
|
command_args.extend(metadata);
|
||||||
|
if !preset_custom {
|
||||||
|
if let Some(ffmpeg_threads) = self.ffmpeg_threads {
|
||||||
|
command_args.extend(vec!["-threads".to_string(), ffmpeg_threads.to_string()])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set default subtitle
|
// set default subtitle
|
||||||
if let Some(default_subtitle) = self.default_subtitle {
|
if let Some(default_subtitle) = self.default_subtitle {
|
||||||
|
|
@ -618,7 +630,7 @@ impl Downloader {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let cpus = self.threads;
|
let cpus = self.download_threads;
|
||||||
let mut segs: Vec<Vec<VariantSegment>> = Vec::with_capacity(cpus);
|
let mut segs: Vec<Vec<VariantSegment>> = Vec::with_capacity(cpus);
|
||||||
for _ in 0..cpus {
|
for _ in 0..cpus {
|
||||||
segs.push(vec![])
|
segs.push(vec![])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue