forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

scratch_pixdump.rs78 lines, 2.7 KiBHistoryRawDownload
1//! Scratch: dump every shown frame's planes for the pixel comparator.
2//!
3//! `INTER_IVF=<path> EC_VP9_PIXDUMP=<out> cargo test -p ec-vp9 --test scratch_pixdump`
4//!
5//! Layout matches the oracle: per shown frame, Y (w*h), U and V each
6//! (((w+1)/2)*((h+1)/2)) (chroma ceils, so odd extents keep the last column/
7//! row), rows packed to the visible width.
8
9use ec_vp9::decode::Decoder;
10
11#[test]
12fn pixdump() {
13 let (Ok(ivf), Ok(out)) = (std::env::var("INTER_IVF"), std::env::var("EC_VP9_PIXDUMP")) else {
14 eprintln!("SKIP scratch_pixdump: set INTER_IVF and EC_VP9_PIXDUMP");
15 return;
16 };
17 let bytes = std::fs::read(&ivf).expect("read ivf");
18 let (_, w, h, frames) = parse_ivf(&bytes);
19 let mut decoder = Decoder::new();
20 let mut dump = Vec::new();
21 let mut shown = 0usize;
22 for (i, f) in frames.iter().enumerate() {
23 match decoder.decode(&f.data) {
24 Ok(Some(pic)) => {
25 for &v in pic.y.iter().chain(pic.u.iter()).chain(pic.v.iter()) {
26 if pic.bit_depth == 8 {
27 dump.push(v as u8);
28 } else {
29 dump.extend_from_slice(&v.to_le_bytes());
30 }
31 }
32 eprintln!(
33 "PIXFRAME input={i} shown={shown} {w}x{h} {}x{}",
34 pic.width, pic.height
35 );
36 shown += 1;
37 }
38 Ok(None) => eprintln!("PIXFRAME input={i} hidden"),
39 Err(e) => {
40 eprintln!("PIXERR input={i}: {e}");
41 break;
42 }
43 }
44 }
45 std::fs::write(&out, &dump).expect("write dump");
46 eprintln!("wrote {} bytes ({shown} shown frames)", dump.len());
47}
48
49fn parse_ivf(bytes: &[u8]) -> (&str, u16, u16, Vec<IvfFrame>) {
50 assert_eq!(&bytes[0..4], b"DKIF", "not an IVF file");
51 let hdr_len = u16::from_le_bytes([bytes[6], bytes[7]]) as usize;
52 let fourcc = std::str::from_utf8(&bytes[8..12]).unwrap();
53 let width = u16::from_le_bytes([bytes[12], bytes[13]]);
54 let height = u16::from_le_bytes([bytes[14], bytes[15]]);
55 let mut pos = hdr_len;
56 let mut frames = Vec::new();
57 while pos + 12 <= bytes.len() {
58 let sz = u32::from_le_bytes([bytes[pos], bytes[pos + 1], bytes[pos + 2], bytes[pos + 3]])
59 as usize;
60 let pts = u64::from_le_bytes(bytes[pos + 4..pos + 12].try_into().unwrap());
61 pos += 12;
62 if pos + sz > bytes.len() {
63 break;
64 }
65 frames.push(IvfFrame {
66 pts,
67 data: bytes[pos..pos + sz].to_vec(),
68 });
69 pos += sz;
70 }
71 (fourcc, width, height, frames)
72}
73
74struct IvfFrame {
75 #[allow(dead_code)]
76 pts: u64,
77 data: Vec<u8>,
78}