| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | fn main() { |
| 15 | let a: Vec<String> = std::env::args().skip(1).collect(); |
| 16 | let clip = a[0].clone(); |
| 17 | let frames: usize = a[3].parse().unwrap(); |
| 18 | let gate = a[1] == "gate"; |
| 19 | let (width, height) = match gate { |
| 20 | true => (0, 0), |
| 21 | false => (a[1].parse().unwrap(), a[2].parse().unwrap()), |
| 22 | }; |
| 23 | let qs: Vec<u8> = a.get(4).map_or_else( |
| 24 | || vec![150, 120, 90, 60], |
| 25 | |s| s.split(',').map(|q| q.parse().unwrap()).collect(), |
| 26 | ); |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | let (vf, width, height) = match gate { |
| 32 | true => ec_av1::probe::gate_crop(&clip), |
| 33 | false => ( |
| 34 | std::env::var("EC_ENC_VF").unwrap_or_else(|_| format!("scale={width}:{height}")), |
| 35 | width, |
| 36 | height, |
| 37 | ), |
| 38 | }; |
| 39 | let vf = match gate { |
| 40 | true => std::env::var("EC_ENC_VF").unwrap_or(vf), |
| 41 | false => vf, |
| 42 | }; |
| 43 | eprintln!("probe: {width}x{height} vf={vf}"); |
| 44 | let skip = std::env::var("EC_ENC_SS").unwrap_or_else(|_| "0".into()); |
| 45 | let source = ec_av1::probe::source(&clip, &skip, &vf, width, height, frames); |
| 46 | |
| 47 | let start = std::time::Instant::now(); |
| 48 | for q in qs { |
| 49 | let e = ec_av1::encode::encode_sequence(&source, q, 0.5).unwrap(); |
| 50 | |
| 51 | |
| 52 | let mut h: u64 = 0xcbf2_9ce4_8422_2325; |
| 53 | for &b in &e.stream { |
| 54 | h = (h ^ u64::from(b)).wrapping_mul(0x0000_0100_0000_01b3); |
| 55 | } |
| 56 | println!("q={q} bytes={} fnv1a={h:016x}", e.stream.len()); |
| 57 | |
| 58 | |
| 59 | if let Ok(dir) = std::env::var("EC_ENC_OUT") { |
| 60 | std::fs::write(format!("{dir}/ours-q{q}.obu"), &e.stream).expect("stream out"); |
| 61 | } |
| 62 | if ec_av1::encode::census_on() { |
| 63 | let (kinds, luma_rank, chroma_rank) = ec_av1::encode::take_census(); |
| 64 | for (name, n) in ec_av1::encode::CENSUS_KINDS.iter().zip(kinds) { |
| 65 | println!(" census {name}: {n}"); |
| 66 | } |
| 67 | let pct = |h: &[usize]| { |
| 68 | let total: usize = h.iter().sum::<usize>().max(1); |
| 69 | h.iter() |
| 70 | .map(|n| format!("{:.1}%", 100.0 * *n as f64 / total as f64)) |
| 71 | .collect::<Vec<_>>() |
| 72 | .join(" ") |
| 73 | }; |
| 74 | println!(" census luma SAD rank of RD winner: {}", pct(&luma_rank)); |
| 75 | println!( |
| 76 | " census chroma SAD rank of RD winner: {}", |
| 77 | pct(&chroma_rank) |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | let hits = ec_av1::encode::take_arfmode_hits(); |
| 86 | println!(" arfmode hits: {} {} {}", hits[0], hits[1], hits[2]); |
| 87 | |
| 88 | |
| 89 | |
| 90 | println!(" drl_clamp: {}", ec_av1::tile::drl_clamp_hits()); |
| 91 | } |
| 92 | println!("wall {:.3}s", start.elapsed().as_secs_f64()); |
| 93 | } |