Skip to content

Commit

Permalink
Use default .265, .264 image output extensions for libx265, libx264
Browse files Browse the repository at this point in the history
  • Loading branch information
alexheretic committed Oct 3, 2024
1 parent 859999b commit 4bc570b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 40 deletions.
75 changes: 42 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/command/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ impl Sample {
.max(1)
}

pub fn set_extension_from_input(&mut self, input: &Path, probe: &Ffprobe) {
self.extension = Some(default_output_ext(input, probe.is_image).into());
pub fn set_extension_from_input(&mut self, input: &Path, encoder: &Encoder, probe: &Ffprobe) {
self.extension = Some(default_output_ext(input, encoder, probe.is_image).into());
}

pub fn set_extension_from_output(&mut self, output: &Path) {
Expand Down
11 changes: 11 additions & 0 deletions src/command/args/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,17 @@ impl Encoder {
}
}

pub fn default_image_ext(&self) -> &'static str {
match self.as_str() {
// ffmpeg doesn't currently have good heif support,
// these raw formats allow crf-search to work
"libx264" => "264",
"libx265" => "265",
// otherwise assume av1
_ => "avif",
}
}

/// Additional encoder specific ffmpeg arg defaults.
fn default_ffmpeg_args(&self) -> &[(&'static str, &'static str)] {
match self.as_str() {
Expand Down
2 changes: 1 addition & 1 deletion src/command/crf_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub async fn crf_search(mut args: Args) -> anyhow::Result<()> {
let probe = ffprobe::probe(&args.args.input);
let input_is_image = probe.is_image;
args.sample
.set_extension_from_input(&args.args.input, &probe);
.set_extension_from_input(&args.args.input, &args.args.encoder, &probe);

let best = run(&args, probe.into(), bar.clone()).await;
bar.finish();
Expand Down
6 changes: 3 additions & 3 deletions src/command/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ pub async fn run(
/// * vid.mp4 -> "mp4"
/// * vid.??? -> "mkv"
/// * image.??? -> "avif"
pub fn default_output_ext(input: &Path, is_image: bool) -> &'static str {
pub fn default_output_ext(input: &Path, encoder: &Encoder, is_image: bool) -> &'static str {
if is_image {
return "avif";
return encoder.default_image_ext();
}
match input.extension().and_then(|e| e.to_str()) {
Some("mp4") => "mp4",
Expand All @@ -169,6 +169,6 @@ pub fn default_output_ext(input: &Path, is_image: bool) -> &'static str {
/// E.g. vid.mkv -> "vid.av1.mkv"
pub fn default_output_name(input: &Path, encoder: &Encoder, is_image: bool) -> PathBuf {
let pre = ffmpeg::pre_extension_name(encoder.as_str());
let ext = default_output_ext(input, is_image);
let ext = default_output_ext(input, encoder, is_image);
input.with_extension(format!("{pre}.{ext}"))
}
2 changes: 1 addition & 1 deletion src/command/sample_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub async fn sample_encode(mut args: Args) -> anyhow::Result<()> {

let probe = ffprobe::probe(&args.args.input);
args.sample
.set_extension_from_input(&args.args.input, &probe);
.set_extension_from_input(&args.args.input, &args.args.encoder, &probe);
run(args, probe.into(), bar, true).await?;
Ok(())
}
Expand Down

0 comments on commit 4bc570b

Please sign in to comment.