forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB5a2f5efTahinli3 months ago1409 commits

decode_probe.rs60 lines, 2.5 KiBHistoryRawDownload
1//! Where does a real stream stop? Decode one AV1 file and print the answer.
2//!
3//! The gates in [`ec_av1::stream`] each pin one capability against one encoder
4//! recipe. This asks the complementary question -- given a stream someone
5//! actually produced, which refusal comes first -- and it is how the refusal
6//! distribution in commit 2be815f was measured rather than reasoned about:
7//!
8//! ```text
9//! aomenc --codec=av1 --obu -o s.obu --passes=1 --cpu-used=4 --limit=4 in.y4m
10//! cargo run -p ec-av1 --example decode_probe -- s.obu
11//! ```
12//!
13//! Note `--obu`: [`ec_av1::stream::decode_stream`] takes a raw OBU stream, and
14//! an IVF file decodes as zero frames rather than as an error.
15//!
16//! That run is also what disproved three refusal strings claiming an encoder
17//! never writes a case it demonstrably writes, so this is a first-class
18//! instrument, not a scratch file.
19fn main() {
20 let Some(path) = std::env::args().nth(1) else {
21 eprintln!("usage: decode_probe <stream.obu>");
22 std::process::exit(2);
23 };
24 let data = match std::fs::read(&path) {
25 Ok(data) => data,
26 Err(e) => {
27 eprintln!("{path}: {e}");
28 std::process::exit(2);
29 }
30 };
31 let report = || {
32 let (h, v, c) = ec_av1::stream::rect4_32_counters();
33 println!("rect4_32: horz={h} vert={v} coded={c}");
34 };
35 match ec_av1::stream::decode_stream(&data) {
36 Ok(frames) if frames.is_empty() => {
37 println!("OK but EMPTY: no frames -- is {path} an IVF rather than a raw OBU stream?");
38 }
39 Ok(frames) => {
40 // Optional second arg, or EC_PROBE_OUT=<path>: dump the decoded
41 // planes as raw yuv420p so a pixel diff against `ffmpeg -i s.obu
42 // -f rawvideo` needs no test harness.
43 let out = std::env::args().nth(2).or_else(|| std::env::var("EC_PROBE_OUT").ok());
44 if let Some(out) = out {
45 // 8-bit only: planes are u16, take the low byte.
46 let mut buf: Vec<u8> = Vec::new();
47 for f in &frames {
48 for p in [&f.y, &f.u, &f.v] {
49 buf.extend(p.iter().map(|&s| s as u8));
50 }
51 }
52 std::fs::write(&out, &buf).expect("writing raw planes");
53 println!("wrote {} bytes of yuv420p to {out}", buf.len());
54 }
55 println!("OK: {} frames decoded, {}x{}", frames.len(), frames[0].width, frames[0].height);
56 }
57 Err(e) => println!("REFUSED: {e}"),
58 }
59 report();
60}