|
| 1 | +#[cfg(feature = "binaries")] |
| 2 | +mod binary { |
| 3 | + use assert_cmd::Command; |
| 4 | + use rand::distributions::Alphanumeric; |
| 5 | + use rand::{thread_rng, Rng}; |
| 6 | + use std::env::temp_dir; |
| 7 | + use std::fs::File; |
| 8 | + use std::io::Read; |
| 9 | + use std::path::PathBuf; |
| 10 | + |
| 11 | + fn get_y4m_input() -> Vec<u8> { |
| 12 | + let mut input = File::open(&format!( |
| 13 | + "{}/tests/small_input.y4m", |
| 14 | + env!("CARGO_MANIFEST_DIR") |
| 15 | + )) |
| 16 | + .unwrap(); |
| 17 | + let mut data = Vec::new(); |
| 18 | + input.read_to_end(&mut data).unwrap(); |
| 19 | + data |
| 20 | + } |
| 21 | + |
| 22 | + fn get_tempfile_path(extension: &str) -> PathBuf { |
| 23 | + let mut path = temp_dir(); |
| 24 | + let filename = |
| 25 | + thread_rng().sample_iter(&Alphanumeric).take(12).collect::<String>(); |
| 26 | + path.push(format!("{}.{}", filename, extension)); |
| 27 | + path |
| 28 | + } |
| 29 | + |
| 30 | + #[test] |
| 31 | + fn one_pass_qp_based() { |
| 32 | + let mut cmd = Command::cargo_bin("rav1e").unwrap(); |
| 33 | + let outfile = get_tempfile_path("ivf"); |
| 34 | + |
| 35 | + cmd |
| 36 | + .arg("--quantizer") |
| 37 | + .arg("100") |
| 38 | + .arg("-o") |
| 39 | + .arg(&outfile) |
| 40 | + .arg("-") |
| 41 | + .write_stdin(get_y4m_input()) |
| 42 | + .assert() |
| 43 | + .success(); |
| 44 | + } |
| 45 | + |
| 46 | + #[test] |
| 47 | + fn one_pass_bitrate_based() { |
| 48 | + let mut cmd = Command::cargo_bin("rav1e").unwrap(); |
| 49 | + let outfile = get_tempfile_path("ivf"); |
| 50 | + |
| 51 | + cmd |
| 52 | + .arg("--bitrate") |
| 53 | + .arg("1000") |
| 54 | + .arg("-o") |
| 55 | + .arg(&outfile) |
| 56 | + .arg("-") |
| 57 | + .write_stdin(get_y4m_input()) |
| 58 | + .assert() |
| 59 | + .success(); |
| 60 | + } |
| 61 | + |
| 62 | + #[test] |
| 63 | + fn two_pass_bitrate_based() { |
| 64 | + let outfile = get_tempfile_path("ivf"); |
| 65 | + let passfile = get_tempfile_path("pass"); |
| 66 | + |
| 67 | + let mut cmd1 = Command::cargo_bin("rav1e").unwrap(); |
| 68 | + cmd1 |
| 69 | + .arg("--bitrate") |
| 70 | + .arg("1000") |
| 71 | + .arg("-o") |
| 72 | + .arg(&outfile) |
| 73 | + .arg("--first-pass") |
| 74 | + .arg(&passfile) |
| 75 | + .arg("-") |
| 76 | + .write_stdin(get_y4m_input()) |
| 77 | + .assert() |
| 78 | + .success(); |
| 79 | + |
| 80 | + let mut cmd2 = Command::cargo_bin("rav1e").unwrap(); |
| 81 | + cmd2 |
| 82 | + .arg("--bitrate") |
| 83 | + .arg("1000") |
| 84 | + .arg("-o") |
| 85 | + .arg(&outfile) |
| 86 | + .arg("--second-pass") |
| 87 | + .arg(&passfile) |
| 88 | + .arg("-") |
| 89 | + .write_stdin(get_y4m_input()) |
| 90 | + .assert() |
| 91 | + .success(); |
| 92 | + } |
| 93 | +} |
0 commit comments