-
Notifications
You must be signed in to change notification settings - Fork 275
Fix two-pass encoding and create basic CLI tests #2209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| *.y4m binary |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| !small_input.y4m |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| #[cfg(feature = "binaries")] | ||
| mod binary { | ||
| use assert_cmd::Command; | ||
| use rand::distributions::Alphanumeric; | ||
| use rand::{thread_rng, Rng}; | ||
| use std::env::temp_dir; | ||
| use std::fs::File; | ||
| use std::io::Read; | ||
| use std::path::PathBuf; | ||
|
|
||
| fn get_y4m_input() -> Vec<u8> { | ||
| let mut input = File::open(&format!( | ||
| "{}/tests/small_input.y4m", | ||
| env!("CARGO_MANIFEST_DIR") | ||
| )) | ||
| .unwrap(); | ||
| let mut data = Vec::new(); | ||
| input.read_to_end(&mut data).unwrap(); | ||
| data | ||
| } | ||
|
|
||
| fn get_tempfile_path(extension: &str) -> PathBuf { | ||
| let mut path = temp_dir(); | ||
| let filename = | ||
| thread_rng().sample_iter(&Alphanumeric).take(12).collect::<String>(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be personal preference, but I think tests should avoid using random values. A second opinion would be nice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use non-random filenames, since the directory is already temporary |
||
| path.push(format!("{}.{}", filename, extension)); | ||
| path | ||
| } | ||
|
|
||
| #[test] | ||
| fn one_pass_qp_based() { | ||
| let mut cmd = Command::cargo_bin("rav1e").unwrap(); | ||
| let outfile = get_tempfile_path("ivf"); | ||
|
|
||
| cmd | ||
| .arg("--quantizer") | ||
| .arg("100") | ||
| .arg("-o") | ||
| .arg(&outfile) | ||
| .arg("-") | ||
| .write_stdin(get_y4m_input()) | ||
| .assert() | ||
| .success(); | ||
| } | ||
|
|
||
| #[test] | ||
| fn one_pass_bitrate_based() { | ||
| let mut cmd = Command::cargo_bin("rav1e").unwrap(); | ||
| let outfile = get_tempfile_path("ivf"); | ||
|
|
||
| cmd | ||
| .arg("--bitrate") | ||
| .arg("1000") | ||
| .arg("-o") | ||
| .arg(&outfile) | ||
| .arg("-") | ||
| .write_stdin(get_y4m_input()) | ||
| .assert() | ||
| .success(); | ||
| } | ||
|
|
||
| #[test] | ||
| fn two_pass_bitrate_based() { | ||
| let outfile = get_tempfile_path("ivf"); | ||
| let passfile = get_tempfile_path("pass"); | ||
|
|
||
| let mut cmd1 = Command::cargo_bin("rav1e").unwrap(); | ||
| cmd1 | ||
| .arg("--bitrate") | ||
| .arg("1000") | ||
| .arg("-o") | ||
| .arg(&outfile) | ||
| .arg("--first-pass") | ||
| .arg(&passfile) | ||
| .arg("-") | ||
| .write_stdin(get_y4m_input()) | ||
| .assert() | ||
| .success(); | ||
|
|
||
| let mut cmd2 = Command::cargo_bin("rav1e").unwrap(); | ||
| cmd2 | ||
| .arg("--bitrate") | ||
| .arg("1000") | ||
| .arg("-o") | ||
| .arg(&outfile) | ||
| .arg("--second-pass") | ||
| .arg(&passfile) | ||
| .arg("-") | ||
| .write_stdin(get_y4m_input()) | ||
| .assert() | ||
| .success(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may use tempfile maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into that, but tempfile doesn't have an option to just generate a filename--it also creates the file. For this, we just want a filename in the temp directory that rav1e can write to.