Skip to content

Commit

Permalink
Add a cli option to use the high_bitdepth codepath for 8bit content
Browse files Browse the repository at this point in the history
Useful mainly for debugging purposes
  • Loading branch information
lu-zero committed Dec 19, 2023
1 parent 1f4dd91 commit b9f4275
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
6 changes: 6 additions & 0 deletions src/bin/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ pub struct CliOptions {
help_heading = "ENCODE SETTINGS"
)]
pub film_grain_table: Option<PathBuf>,
/// 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")]
Expand Down Expand Up @@ -339,6 +343,7 @@ pub struct ParsedCliOptions {
pub photon_noise: u8,
#[cfg(feature = "unstable")]
pub slots: usize,
pub force_highbitdepth: bool,
}

#[cfg(feature = "serialize")]
Expand Down Expand Up @@ -484,6 +489,7 @@ pub fn parse_cli() -> Result<ParsedCliOptions, CliError> {
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,
})
Expand Down
2 changes: 1 addition & 1 deletion src/bin/rav1e-ch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u8, y4m::Decoder<Box<dyn Read + Send>>>(
cfg,
cli.verbose,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/rav1e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u8, y4m::Decoder<Box<dyn Read + Send>>>(
cfg,
cli.verbose,
Expand Down
63 changes: 39 additions & 24 deletions tests/binary.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -63,44 +72,48 @@ 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("-")
.write_stdin(get_y4m_input())
.assert()
.success();

get_common_cmd(&outfile)
get_common_cmd(&outfile, high_bitdepth)
.arg("--second-pass")
.arg(&passfile)
.arg("-")
.write_stdin(get_y4m_input())
.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)
Expand All @@ -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)
Expand All @@ -119,21 +132,23 @@ 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("-")
.write_stdin(get_y4m_input())
.assert()
.success();

get_common_cmd(&outfile)
get_common_cmd(&outfile, high_bitdepth)
.arg("--second-pass")
.arg(&pass1file)
.arg("--first-pass")
Expand All @@ -143,7 +158,7 @@ mod binary {
.assert()
.success();

get_common_cmd(&outfile)
get_common_cmd(&outfile, high_bitdepth)
.arg("--second-pass")
.arg(&pass2file)
.arg("-")
Expand Down

0 comments on commit b9f4275

Please sign in to comment.