forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

enc_probe.rs93 lines, 4.2 KiBHistoryRawDownload
1//! Encode-side profiling driver: the BD gate's own ladder, without ffmpeg's
2//! decode side or the reference encoders, so `perf record` attributes only
3//! our encoder. Also the byte-exactness gate for encoder-internal rewrites:
4//! it prints each point's stream length and a hash of its bytes.
5//!
6//! Usage: `enc_probe <clip> <width|gate> <height> <frames> [q,q,..]`
7//!
8//! `gate` as the width takes the native BD gate's own window on the clip
9//! (`probe::gate_crop`, superblock-aligned centre crop) and ignores the height
10//! argument; `EC_ENC_SS` is the gate's seek and `EC_ENC_VF` overrides the
11//! filter chain. Without both of those the probe measures different pixels
12//! than the gate it reports on.
13
14fn 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 // lane-census/lane-probe: the BD gate's native rows CROP (`EC_ENC_VF`) and
29 // SEEK (`EC_ENC_SS`) -- without the seek this probe read film B's black
30 // leader and every census off it was probe-relative.
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 // FNV-1a over the stream: a byte-exactness witness, not a checksum
51 // with any other job.
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 // lane-census: keep the stream itself when asked, so `syntax_census`
58 // can read the very bytes this point measured.
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 // lane-arfmode: the engagement counter of the top ARF's offer-set
81 // lever, taken once per point so an armed run PRINTS a non-zero count
82 // (class gate-blind-to-feature; a BD number over a counter of zero
83 // proves nothing). Zeros when `EC_AV1_ARFMODE` is unset, which is the
84 // control's own expectation.
85 let hits = ec_av1::encode::take_arfmode_hits();
86 println!(" arfmode hits: {} {} {}", hits[0], hits[1], hits[2]);
87 // lane-av1recipehunt: the gate's own precondition number -- how many
88 // blocks this point's search picked a DRL index the write-time stack
89 // could not carry.
90 println!(" drl_clamp: {}", ec_av1::tile::drl_clamp_hits());
91 }
92 println!("wall {:.3}s", start.elapsed().as_secs_f64());
93}