forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB50503afTahinli3 months ago1344 commits

decode_probe.rs55 lines, 2.4 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 match ec_av1::stream::decode_stream(&data) {
32 Ok(frames) if frames.is_empty() => {
33 println!("OK but EMPTY: no frames -- is {path} an IVF rather than a raw OBU stream?");
34 }
35 Ok(frames) => {
36 // Optional second arg, or EC_PROBE_OUT=<path>: dump the decoded
37 // planes as raw yuv420p so a pixel diff against `ffmpeg -i s.obu
38 // -f rawvideo` needs no test harness.
39 let out = std::env::args().nth(2).or_else(|| std::env::var("EC_PROBE_OUT").ok());
40 if let Some(out) = out {
41 // 8-bit only: planes are u16, take the low byte.
42 let mut buf: Vec<u8> = Vec::new();
43 for f in &frames {
44 for p in [&f.y, &f.u, &f.v] {
45 buf.extend(p.iter().map(|&s| s as u8));
46 }
47 }
48 std::fs::write(&out, &buf).expect("writing raw planes");
49 println!("wrote {} bytes of yuv420p to {out}", buf.len());
50 }
51 println!("OK: {} frames decoded, {}x{}", frames.len(), frames[0].width, frames[0].height);
52 }
53 Err(e) => println!("REFUSED: {e}"),
54 }
55}