From b9f4275e0da18fe81c314831bfcb39867b47df14 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Tue, 19 Dec 2023 11:08:34 +0100 Subject: [PATCH] Add a cli option to use the high_bitdepth codepath for 8bit content Useful mainly for debugging purposes --- src/bin/common.rs | 6 +++++ src/bin/rav1e-ch.rs | 2 +- src/bin/rav1e.rs | 2 +- tests/binary.rs | 63 ++++++++++++++++++++++++++++----------------- 4 files changed, 47 insertions(+), 26 deletions(-) diff --git a/src/bin/common.rs b/src/bin/common.rs index 49f525b430..85394aa67a 100644 --- a/src/bin/common.rs +++ b/src/bin/common.rs @@ -195,6 +195,10 @@ pub struct CliOptions { help_heading = "ENCODE SETTINGS" )] pub film_grain_table: Option, + /// Force the high bitdepth codepath even for 8bit content. + /// Mainly for debugging purposes. + #[clap(long, help_heading = "ENCODE SETTINGS")] + pub high_bitdepth: bool, /// Pixel range #[clap(long, value_parser, help_heading = "VIDEO METADATA")] @@ -339,6 +343,7 @@ pub struct ParsedCliOptions { pub photon_noise: u8, #[cfg(feature = "unstable")] pub slots: usize, + pub force_highbitdepth: bool, } #[cfg(feature = "serialize")] @@ -484,6 +489,7 @@ pub fn parse_cli() -> Result { pass2file_name: matches.second_pass.clone(), save_config: save_config_path, photon_noise: matches.photon_noise, + force_highbitdepth: matches.high_bitdepth, #[cfg(feature = "unstable")] slots, }) diff --git a/src/bin/rav1e-ch.rs b/src/bin/rav1e-ch.rs index ebfd8c7803..d81401d4e2 100644 --- a/src/bin/rav1e-ch.rs +++ b/src/bin/rav1e-ch.rs @@ -641,7 +641,7 @@ fn run() -> Result<(), error::CliError> { let source = Source::new(cli.limit, y4m_dec); - if video_info.bit_depth == 8 { + if video_info.bit_depth == 8 && !cli.force_highbitdepth { do_encode::>>( cfg, cli.verbose, diff --git a/src/bin/rav1e.rs b/src/bin/rav1e.rs index 6698f68ad5..0ad691306e 100644 --- a/src/bin/rav1e.rs +++ b/src/bin/rav1e.rs @@ -625,7 +625,7 @@ fn run() -> Result<(), error::CliError> { let source = Source::new(cli.limit, y4m_dec); - if video_info.bit_depth == 8 { + if video_info.bit_depth == 8 && !cli.force_highbitdepth { do_encode::>>( cfg, cli.verbose, diff --git a/tests/binary.rs b/tests/binary.rs index a1cff3f6cc..39a68b6427 100644 --- a/tests/binary.rs +++ b/tests/binary.rs @@ -1,6 +1,7 @@ #[cfg(feature = "binaries")] mod binary { use assert_cmd::Command; + use interpolate_name::interpolate_test; use rand::distributions::Alphanumeric; use rand::{thread_rng, Rng}; use std::env::temp_dir; @@ -31,29 +32,37 @@ mod binary { } #[cfg(not(windows))] - fn get_rav1e_command() -> Command { + fn get_rav1e_command(high_bitdepth: bool) -> Command { let mut cmd = Command::cargo_bin("rav1e").unwrap(); + if high_bitdepth { + cmd.arg("--high-bitdepth"); + } cmd.env_clear(); cmd } #[cfg(windows)] // `env_clear` doesn't work on Windows: https://github.com/rust-lang/rust/issues/31259 - fn get_rav1e_command() -> Command { - Command::cargo_bin("rav1e").unwrap() + fn get_rav1e_command(high_bitdepth: bool) -> Command { + let mut cmd = Command::cargo_bin("rav1e").unwrap(); + if high_bitdepth { + cmd.arg("--high-bitdepth"); + } + cmd } - fn get_common_cmd(outfile: &Path) -> Command { - let mut cmd = get_rav1e_command(); + fn get_common_cmd(outfile: &Path, high_bitdepth: bool) -> Command { + let mut cmd = get_rav1e_command(high_bitdepth); cmd.args(["--bitrate", "1000"]).arg("-o").arg(outfile).arg("-y"); cmd } - #[test] - fn one_pass_qp_based() { + #[interpolate_test(low_bitdepth, false)] + #[interpolate_test(high_bitdepth, true)] + fn one_pass_qp_based(high_bitdepth: bool) { let outfile = get_tempfile_path("ivf"); - get_rav1e_command() + get_rav1e_command(high_bitdepth) .args(["--quantizer", "100"]) .arg("-o") .arg(&outfile) @@ -63,23 +72,25 @@ mod binary { .success(); } - #[test] - fn one_pass_bitrate_based() { + #[interpolate_test(low_bitdepth, false)] + #[interpolate_test(high_bitdepth, true)] + fn one_pass_bitrate_based(high_bitdepth: bool) { let outfile = get_tempfile_path("ivf"); - get_common_cmd(&outfile) + get_common_cmd(&outfile, high_bitdepth) .arg("-") .write_stdin(get_y4m_input()) .assert() .success(); } - #[test] - fn two_pass_bitrate_based() { + #[interpolate_test(low_bitdepth, false)] + #[interpolate_test(high_bitdepth, true)] + fn two_pass_bitrate_based(high_bitdepth: bool) { let outfile = get_tempfile_path("ivf"); let passfile = get_tempfile_path("pass"); - get_common_cmd(&outfile) + get_common_cmd(&outfile, high_bitdepth) .arg("--first-pass") .arg(&passfile) .arg("-") @@ -87,7 +98,7 @@ mod binary { .assert() .success(); - get_common_cmd(&outfile) + get_common_cmd(&outfile, high_bitdepth) .arg("--second-pass") .arg(&passfile) .arg("-") @@ -95,12 +106,14 @@ mod binary { .assert() .success(); } - #[test] - fn two_pass_bitrate_based_constrained() { + + #[interpolate_test(low_bitdepth, false)] + #[interpolate_test(high_bitdepth, true)] + fn two_pass_bitrate_based_constrained(high_bitdepth: bool) { let outfile = get_tempfile_path("ivf"); let passfile = get_tempfile_path("pass"); - get_common_cmd(&outfile) + get_common_cmd(&outfile, high_bitdepth) .args(["--reservoir-frame-delay", "14"]) .arg("--first-pass") .arg(&passfile) @@ -109,7 +122,7 @@ mod binary { .assert() .success(); - get_common_cmd(&outfile) + get_common_cmd(&outfile, high_bitdepth) .args(["--reservoir-frame-delay", "14"]) .arg("--second-pass") .arg(&passfile) @@ -119,13 +132,15 @@ mod binary { .success(); } - #[test] - fn three_pass_bitrate_based() { + #[interpolate_test(low_bitdepth, false)] + #[interpolate_test(high_bitdepth, true)] + + fn three_pass_bitrate_based(high_bitdepth: bool) { let outfile = get_tempfile_path("ivf"); let pass1file = get_tempfile_path("pass1"); let pass2file = get_tempfile_path("pass2"); - get_common_cmd(&outfile) + get_common_cmd(&outfile, high_bitdepth) .arg("--first-pass") .arg(&pass1file) .arg("-") @@ -133,7 +148,7 @@ mod binary { .assert() .success(); - get_common_cmd(&outfile) + get_common_cmd(&outfile, high_bitdepth) .arg("--second-pass") .arg(&pass1file) .arg("--first-pass") @@ -143,7 +158,7 @@ mod binary { .assert() .success(); - get_common_cmd(&outfile) + get_common_cmd(&outfile, high_bitdepth) .arg("--second-pass") .arg(&pass2file) .arg("-")