Merge lane-av1dumpyuv @ 60a7788a — dump_yuv / raw_to_y4m / lr-sgr harness derive or assert the sample depth
Browse files at this commit5 changed files +626 -26
- crates/ec-av1/examples/dump_yuv.rs +176 -20
- lanes/av1dumpyuv.report.md +183 -0
- lanes/merge-wave-4.report.md +189 -0
- scripts/lr-sgr-pin-harness.c +26 -2
- scripts/raw_to_y4m.py +52 -4
crates/ec-av1/examples/dump_yuv.rsmodified+176 -20
| @@ -1,20 +1,68 @@ | ||
| 1 | -//! Decode one OBU stream and write every frame's planes as raw little-endian | |
| 2 | -//! `u16` (`<out-prefix>.f<N>.yuv`) — the high-bit-depth companion to | |
| 3 | -//! `EC_AV1_PREFILT_DUMP`, whose `as u8` narrowing throws away exactly the bits | |
| 4 | -//! a 10-bit mismatch lives in (lane-rect1d r1 found its defect by diffing this | |
| 5 | -//! against `ffmpeg -pix_fmt yuv420p10le -f rawvideo`). | |
| 1 | +//! Decode one OBU stream and write every frame's planes as raw planar video | |
| 2 | +//! (`<out-prefix>.f<N>.yuv`), at the sample depth **the stream's own sequence | |
| 3 | +//! header carries**: 8-bit as one byte per sample, 10/12-bit as little-endian | |
| 4 | +//! `u16`. That is the layout `ffmpeg -pix_fmt yuv420p{,10,12}le -f rawvideo` | |
| 5 | +//! and `aomdec --rawvideo` write, so a byte-exact `cmp` against either is | |
| 6 | +//! meaningful. | |
| 7 | +//! | |
| 8 | +//! It is the high-bit-depth companion to `EC_AV1_PREFILT_DUMP`, whose `as u8` | |
| 9 | +//! narrowing throws away exactly the bits a 10-bit mismatch lives in | |
| 10 | +//! (lane-rect1d r1 found its defect by diffing this against | |
| 11 | +//! `ffmpeg -pix_fmt yuv420p10le -f rawvideo`). | |
| 6 | 12 | //! |
| 7 | 13 | //! ```text |
| 8 | 14 | //! cargo run -p ec-av1 --example dump_yuv -- s.obu /tmp/ours |
| 9 | 15 | //! ffmpeg -v error -i s.obu -pix_fmt yuv420p10le -f rawvideo /tmp/ref.yuv |
| 10 | 16 | //! cmp /tmp/ours.f0.yuv /tmp/ref.yuv |
| 11 | 17 | //! ``` |
| 18 | +//! | |
| 19 | +//! The depth is NEVER taken from the file name, the output extension, or the | |
| 20 | +//! `-pix_fmt` of a reference tool: it is parsed out of the sequence header | |
| 21 | +//! (spec 5.5.2 `color_config.bit_depth`) before a single byte is written. The | |
| 22 | +//! old version packed every sample as `u16` unconditionally, so pointing it at | |
| 23 | +//! an 8-bit stream silently produced a file TWICE the size of the oracle's, | |
| 24 | +//! and the size mismatch read like a decoder bug. `--depth N` is accepted for | |
| 25 | +//! the case where you already know what the stream is, and is ASSERTED against | |
| 26 | +//! the parsed header: a mismatch names both depths and the consequence it | |
| 27 | +//! would have caused, and writes nothing. | |
| 28 | +//! | |
| 29 | +//! `i` in `<out-prefix>.f<i>.yuv` indexes `decode_stream`'s output, which is | |
| 30 | +//! DISPLAY order and SHOWN frames only -- hidden alt-refs are never emitted. | |
| 31 | +//! Every other `.f{N}` in this crate (EC_AV1_FINAL_DUMP, | |
| 32 | +//! EC_AV1_DECODE_ORDER_DUMP, EC_AV1_PREFILT_DUMP) uses a DECODE index, so this | |
| 33 | +//! file does NOT line up with an aomdec dump past frame 0 on a stream with | |
| 34 | +//! altref. Compare against ffmpeg rawvideo, or against aomdec via | |
| 35 | +//! `decode_all_frames_vs_oracle`. | |
| 12 | 36 | fn main() { |
| 13 | - let mut args = std::env::args().skip(1); | |
| 14 | - let (Some(path), Some(out)) = (args.next(), args.next()) else { | |
| 15 | - eprintln!("usage: dump_yuv <stream.obu> <out-prefix>"); | |
| 37 | + let argv: Vec<String> = std::env::args().skip(1).collect(); | |
| 38 | + let (Some(path), Some(out)) = (argv.first().cloned(), argv.get(1).cloned()) else { | |
| 39 | + eprintln!("usage: dump_yuv <stream.obu> <out-prefix> [--depth 8|10|12]"); | |
| 16 | 40 | std::process::exit(2); |
| 17 | 41 | }; |
| 42 | + // An ASSERTED expectation, not a switch: the packing always follows the | |
| 43 | + // parsed header, and a wrong `--depth` is a hard error before any file. | |
| 44 | + let mut claimed_depth: Option<u8> = None; | |
| 45 | + let mut rest = argv[2.min(argv.len())..].iter(); | |
| 46 | + while let Some(arg) = rest.next() { | |
| 47 | + let value = arg | |
| 48 | + .strip_prefix("--depth=") | |
| 49 | + .map(str::to_string) | |
| 50 | + .or_else(|| (arg == "--depth").then(|| rest.next().cloned()).flatten()); | |
| 51 | + let Some(value) = value else { | |
| 52 | + eprintln!("dump_yuv: unknown argument `{arg}`"); | |
| 53 | + eprintln!("usage: dump_yuv <stream.obu> <out-prefix> [--depth 8|10|12]"); | |
| 54 | + std::process::exit(2); | |
| 55 | + }; | |
| 56 | + let Ok(depth) = value.parse::<u8>() else { | |
| 57 | + eprintln!("dump_yuv: --depth `{value}` is not a bit depth (8, 10 or 12)"); | |
| 58 | + std::process::exit(2); | |
| 59 | + }; | |
| 60 | + if claimed_depth.is_some() { | |
| 61 | + eprintln!("dump_yuv: --depth given twice; the depth is asserted, not a switch"); | |
| 62 | + std::process::exit(2); | |
| 63 | + } | |
| 64 | + claimed_depth = Some(depth); | |
| 65 | + } | |
| 18 | 66 | let data = match std::fs::read(&path) { |
| 19 | 67 | Ok(data) => data, |
| 20 | 68 | Err(e) => { |
| @@ -22,6 +70,87 @@ fn main() { | ||
| 22 | 70 | std::process::exit(2); |
| 23 | 71 | } |
| 24 | 72 | }; |
| 73 | + | |
| 74 | + // The stream's OWN header, read before the decode so a depth mismatch is | |
| 75 | + // reported instead of a file. Scans OBU by OBU because the sequence header | |
| 76 | + // need not be the first OBU (decode_probe walks it the same way). | |
| 77 | + let mut parser = ec_av1_syntax::Av1Parser::new(); | |
| 78 | + let mut pos = 0usize; | |
| 79 | + while pos < data.len() && parser.sequence_header().is_none() { | |
| 80 | + let Ok(obu) = parser.parse_obu(&data[pos..]) else { | |
| 81 | + break; | |
| 82 | + }; | |
| 83 | + pos += obu.total_size.max(1); | |
| 84 | + } | |
| 85 | + let Some(seq) = parser.sequence_header() else { | |
| 86 | + eprintln!( | |
| 87 | + "dump_yuv: {path}: no sequence header parsed, so the sample depth is unknown. \ | |
| 88 | + Refusing to guess: packing u16 blind is what wrote a 2x-size file for every 8-bit \ | |
| 89 | + stream. Re-checkout the stream (an IVF container parses as zero frames too), or pass \ | |
| 90 | + a raw OBU stream." | |
| 91 | + ); | |
| 92 | + std::process::exit(1); | |
| 93 | + }; | |
| 94 | + let cfg = &seq.color_config; | |
| 95 | + let bit_depth = cfg.bit_depth; | |
| 96 | + if let Some(claimed) = claimed_depth { | |
| 97 | + if claimed != bit_depth { | |
| 98 | + let theirs = if bit_depth == 8 { | |
| 99 | + format!( | |
| 100 | + "aomdec --rawvideo / ffmpeg -pix_fmt yuv420p ({} bytes per sample, \ | |
| 101 | + W*H*3/2 for 4:2:0)", | |
| 102 | + 1 | |
| 103 | + ) | |
| 104 | + } else { | |
| 105 | + format!( | |
| 106 | + "aomdec --rawvideo / ffmpeg -pix_fmt yuv420p{}le ({} bytes per sample, \ | |
| 107 | + W*H*3 for 4:2:0)", | |
| 108 | + bit_depth, 2 | |
| 109 | + ) | |
| 110 | + }; | |
| 111 | + eprintln!( | |
| 112 | + "dump_yuv: {path}: --depth {claimed} contradicts the stream's own sequence \ | |
| 113 | + header, which carries bit_depth {bit_depth} (seq_profile {}, \ | |
| 114 | + subsampling {}/{}, mono_chrome {}). Writing {claimed}-bit would emit \ | |
| 115 | + {} bytes per sample against the oracle's {theirs}, so every `cmp` would fail on \ | |
| 116 | + size alone and read like a decoder defect. Nothing was written.", | |
| 117 | + seq.seq_profile, | |
| 118 | + cfg.subsampling_x, | |
| 119 | + cfg.subsampling_y, | |
| 120 | + cfg.mono_chrome, | |
| 121 | + if claimed == 8 { 1 } else { 2 }, | |
| 122 | + ); | |
| 123 | + std::process::exit(1); | |
| 124 | + } | |
| 125 | + } | |
| 126 | + // 8 bit -> one byte per sample; anything above -> little-endian u16, which | |
| 127 | + // is what both oracles emit for `*p10le` / `*p12le` (they never pack to | |
| 128 | + // the bit depth itself, they use a full 16-bit container). | |
| 129 | + let bytes_per_sample = if bit_depth == 8 { 1 } else { 2 }; | |
| 130 | + // Spec 5.5.3 `subsampling_{x,y}`: 1/1 IS 4:2:0 (measured on this crate's own | |
| 131 | + // 8-bit 192x128 fixture, which parses 1/1 and yields 36864 samples for a | |
| 132 | + // 192x128 frame = W*H*3/2), 0/0 is 4:4:4, 1/0 is 4:2:2, 0/1 is 4:4:0. | |
| 133 | + let chroma = match (cfg.mono_chrome, cfg.subsampling_x, cfg.subsampling_y) { | |
| 134 | + (true, _, _) => "gray", | |
| 135 | + (false, 0, 0) => "yuv444p", | |
| 136 | + (false, 0, 1) => "yuv440p", | |
| 137 | + (false, 1, 0) => "yuv422p", | |
| 138 | + _ => "yuv420p", | |
| 139 | + }; | |
| 140 | + let pix_fmt = match (chroma, bit_depth) { | |
| 141 | + (c, 8) => c.to_string(), | |
| 142 | + ("gray", _) => "gray16le".to_string(), | |
| 143 | + (c, 10) => format!("{c}10le"), | |
| 144 | + (c, 12) => format!("{c}12le"), | |
| 145 | + (c, d) => format!("{c}{d}le"), | |
| 146 | + }; | |
| 147 | + let max = (1u32 << bit_depth) - 1; | |
| 148 | + println!( | |
| 149 | + "sequence header: bit_depth {bit_depth} -> {bytes_per_sample} byte(s) per sample, \ | |
| 150 | + seq_profile {}, subsampling {}/{}, mono_chrome {}; ffmpeg -pix_fmt {pix_fmt}", | |
| 151 | + seq.seq_profile, cfg.subsampling_x, cfg.subsampling_y, cfg.mono_chrome, | |
| 152 | + ); | |
| 153 | + | |
| 25 | 154 | let frames = match ec_av1::stream::decode_stream(&data) { |
| 26 | 155 | Ok(frames) => frames, |
| 27 | 156 | Err(e) => { |
| @@ -30,24 +159,51 @@ fn main() { | ||
| 30 | 159 | } |
| 31 | 160 | }; |
| 32 | 161 | for (i, f) in frames.iter().enumerate() { |
| 33 | - let mut buf = Vec::with_capacity((f.y.len() + f.u.len() + f.v.len()) * 2); | |
| 34 | - for plane in [&f.y, &f.u, &f.v] { | |
| 35 | - for &s in plane.iter() { | |
| 36 | - buf.extend_from_slice(&s.to_le_bytes()); | |
| 162 | + let planes: &[&Vec<u16>] = if cfg.mono_chrome { | |
| 163 | + &[&f.y] | |
| 164 | + } else { | |
| 165 | + &[&f.y, &f.u, &f.v] | |
| 166 | + }; | |
| 167 | + // The OTHER half of the depth contract: samples that do not fit the | |
| 168 | + // container we are about to write. A `s as u8` on a 10-bit plane (or a | |
| 169 | + // u16 on a depth we packed narrow) is exactly the bit loss this tool | |
| 170 | + // exists to rule out, so it is an error, not a truncation. | |
| 171 | + if let Some((plane_name, sample)) = [("Y", &f.y), ("U", &f.u), ("V", &f.v)] | |
| 172 | + .into_iter() | |
| 173 | + .take(if cfg.mono_chrome { 1 } else { 3 }) | |
| 174 | + .find_map(|(name, plane)| plane.iter().max().map(|&s| (name, s))) | |
| 175 | + { | |
| 176 | + if u32::from(sample) > max { | |
| 177 | + eprintln!( | |
| 178 | + "dump_yuv: {path}: frame {i} plane {plane_name} carries sample {sample} above \ | |
| 179 | + the {bit_depth}-bit maximum {max} -- the decoded output does not match the \ | |
| 180 | + sequence header it was decoded under, and packing it would silently drop the \ | |
| 181 | + high bits. Nothing was written." | |
| 182 | + ); | |
| 183 | + std::process::exit(1); | |
| 184 | + } | |
| 185 | + } | |
| 186 | + let samples: usize = planes.iter().map(|p| p.len()).sum(); | |
| 187 | + let mut buf = Vec::with_capacity(samples * bytes_per_sample); | |
| 188 | + for plane in planes { | |
| 189 | + if bytes_per_sample == 1 { | |
| 190 | + buf.extend(plane.iter().map(|&s| s as u8)); | |
| 191 | + } else { | |
| 192 | + for &s in plane.iter() { | |
| 193 | + buf.extend_from_slice(&s.to_le_bytes()); | |
| 194 | + } | |
| 37 | 195 | } |
| 38 | 196 | } |
| 39 | - // `i` indexes `decode_stream`'s output, which is DISPLAY order and | |
| 40 | - // SHOWN frames only -- hidden alt-refs are never emitted. Every other | |
| 41 | - // `.f{N}` in this crate (EC_AV1_FINAL_DUMP, EC_AV1_DECODE_ORDER_DUMP, | |
| 42 | - // EC_AV1_PREFILT_DUMP) uses a DECODE index, so this file does NOT line | |
| 43 | - // up with an aomdec dump past frame 0 on a stream with altref. Compare | |
| 44 | - // against ffmpeg rawvideo, or against aomdec via | |
| 45 | - // `decode_all_frames_vs_oracle`. | |
| 46 | 197 | let name = format!("{out}.f{i}.yuv"); |
| 47 | 198 | if let Err(e) = std::fs::write(&name, &buf) { |
| 48 | 199 | eprintln!("{name}: {e}"); |
| 49 | 200 | std::process::exit(2); |
| 50 | 201 | } |
| 51 | - println!("frame {i}: {}x{} -> {name}", f.width, f.height); | |
| 202 | + println!( | |
| 203 | + "frame {i}: {}x{} -> {name} ({samples} samples, {} bytes, {pix_fmt})", | |
| 204 | + f.width, | |
| 205 | + f.height, | |
| 206 | + buf.len(), | |
| 207 | + ); | |
| 52 | 208 | } |
| 53 | 209 | } |
lanes/av1dumpyuv.report.mdadded+183 -0
| @@ -0,0 +1,183 @@ | ||
| 1 | +# lane-av1dumpyuv — the depth-packing class outside the test helpers | |
| 2 | + | |
| 3 | +Branch `lane-av1dumpyuv`, branched from `afa13bcf` ("Merge lane-whtshape"). | |
| 4 | +Worktree `~/.cache/wt/av1dumpyuv`. Examples/tools/scripts only: no decoder | |
| 5 | +logic, no gate touched. The primary checkout was never edited | |
| 6 | +(`git status --porcelain` there is empty). | |
| 7 | + | |
| 8 | +## 1. The class | |
| 9 | + | |
| 10 | +`aomdec --rawvideo` and `ffmpeg -f rawvideo` pack **8 bits per sample for an | |
| 11 | +8-bit stream** and **16 bits per sample (`*p10le` / `*p12le`) for a | |
| 12 | +high-bit-depth one** — they never pack to the stream's own bit depth. A site | |
| 13 | +that reads decoded `u16` planes and writes them `as u8`, or writes them `u16` | |
| 14 | +unconditionally, therefore produces a file of the wrong size, and the next | |
| 15 | +person's `cmp` against the oracle fails on LENGTH and reads like a decoder | |
| 16 | +bug. The prior audit (lanes/av1cmpaudit.report.md) fixed the test helper | |
| 17 | +`assert_rawvideo_matches`'s sibling `EC_AV1_FINAL_DUMP` | |
| 18 | +(`crates/ec-av1/src/stream.rs:2137-2152`, depth-correct since lane-hidden r1) | |
| 19 | +and named exactly one unfixed non-test site: `examples/dump_yuv.rs`. | |
| 20 | + | |
| 21 | +## 2. Sweep of the non-test surfaces | |
| 22 | + | |
| 23 | +Rows verified by reading each file. "Assumes" = what the code takes the | |
| 24 | +bits-per-sample to be. | |
| 25 | + | |
| 26 | +| site | assumes about depth | derived from | failure mode on the wrong depth | | |
| 27 | +|---|---|---|---| | |
| 28 | +| `crates/ec-av1/examples/dump_yuv.rs:33` (pre-fix) | always 2 bytes/sample (u16 LE) | **nothing** | silent 2x file on an 8-bit stream; docstring named `yuv420p10le` as the companion, so a reader hands it 8-bit input and diffs the size | | |
| 29 | +| `crates/ec-av1/examples/dump_yuv.rs` (**fixed**) | sequence header `color_config.bit_depth` | the stream's own parsed header; `--depth` is an ASSERTED argument | hard exit 1 naming both depths, no file | | |
| 30 | +| `crates/ec-av1/examples/decode_probe.rs:434-462` | `EC_PROBE_OUT16` = 2 B/sample, `EC_PROBE_OUT`/argv[2] = 1 B/sample | two SEPARATE, explicitly named output targets, each a fixed choice by the caller | none for a single file: the 16-bit target is a full 16-bit container (same as `-pix_fmt yuv420p10le` on an 8-bit stream), the 8-bit target narrows. Both are written, so a wrong choice is visible as two files of different sizes, not one mislabelled file. **not fixed** | | |
| 31 | +| `crates/ec-vp8/examples/dump_frame.rs:28-45` | 1 byte/sample | VP8 has no high-bit-depth profile (its 8-bit 4:2:0 is the format) | none possible. **not flagged** | | |
| 32 | +| `crates/ec-av1/examples/{alloc_probe,enc_probe,syntax_census}.rs` | — | no plane is read or serialised | none. **not flagged** | | |
| 33 | +| `crates/ec-h264/examples/bench_decode.rs`, `bench_encode.rs`, `crates/ec-aac/examples/*`, `crates/ec-ac3/examples/ac3dec.rs` | — | audio `f32`/metric only; no video planes | none. **not flagged** | | |
| 34 | +| `scripts/instrument-aom-oracle.sh:130-145` (rung PREFILT), `:333-350` (POSTDEBLOCK), `:384-398` (PREFILT_WIDE), `:880-896` (POSTCDEF) | 1 byte/sample, no `YV12_FLAG_HIGHBITDEPTH` check | nothing | on a 10/12-bit stream: a **half-length** file (u8 rows of a u16 plane) that can still byte-match a decoder-side `as u8` narrowing. Rung 12 (`FINAL`, `:684-705`) IS depth-correct and is what `EC_AV1_FINAL_DUMP` pairs with. **NOT FIXED** — these are oracle C rungs whose decoder-side counterparts (`EC_AV1_PREFILT_DUMP`, `EC_AV1_DECODE_ORDER_DUMP`, and the `as u8` debug dumps at `stream.rs:2123-2126`) narrow identically on purpose; changing one side alone would break the byte-pairing those rungs exist for, and both sides are decoder/oracle logic, out of this lane's scope. The script's own comment at `:659-660` already calls them the "u8-narrowing debug dumps". | | |
| 35 | +| `scripts/lr-sgr-pin-harness.c:33-36` (pre-fix) | 1 byte/sample of `/tmp/lr_full.bin`; `bit_depth=8, highbd=0` hardcoded at `:47`, `:54`, `:75` | nothing (the capture is a bare `std::fs::write` from a since-reverted `EC_LR_DUMP` in `apply_sgrproj_stripe`, lanes/lr.report.md:352-354) | a 10-bit re-capture is exactly 2x the bytes; the harness read its first half as plane data and printed plausible A/B taps for the wrong pixels | | |
| 36 | +| `scripts/lr-sgr-pin-harness.c` (**fixed**) | still reads 8-bit, but the file length is now an ASSERTION | file size, checked against `bw*bh` | 2x capture → exit 1 naming the byte counts, the assumed depth, and the uint16 port; truncated → exit 1 | | |
| 37 | +| `scripts/raw_to_y4m.py:9` (pre-fix) | `w*h*3//2` = 8-bit 4:2:0, unconditionally; header hardcoded `C420jpeg` | nothing | a 10-bit stream was cut at half frame length, frame N+1's chroma read as frame N's tail, trailing partial frame **dropped silently** — and vpxenc encodes the result without complaint | | |
| 38 | +| `scripts/raw_to_y4m.py` (**fixed**) | required `DEPTH` argument, asserted against the stdin length | explicit asserted argument (no parser exists for a headerless raw stream) | non-integer frame multiple → exit 1 naming both implied frame sizes; a missing/!8/10/12 depth → usage error | | |
| 39 | +| `scripts/superres-pin-harness.c:14-17,50,80,89-142` | — | coverage gap, not depth: only the `uint8` `av1_convolve_horiz_rs_c` arm is called and the input rows were transcribed from an 8-bit fixture | a 10-bit superres pin would be silently uncovered. Different class; **not fixed** | | |
| 40 | +| `tools/oracle/src/main.rs:352-357` (`sample`), `:383-390`, `:414`, `:424-425`, `:479` | bytes-per-sample from the `--pix-fmt` string (or ffprobe of the reference CONTAINER, `:383-388`), never from a parsed header | explicit CLI flag / container probe | a wrong `--pix-fmt` yields `fa != fb`, and `len_ok = fa == fb` feeds the verdict at `:479` → **loud FAIL**, not a silent compare. Acceptable shape (an argument that is checked). **not fixed** | | |
| 41 | +| `tools/ec-bench/src/main.rs:253`, `:367`, `:557` | 1 byte/sample `frame_len`; `:564-571` widens those 8-bit samples into `Av1Picture`'s `u16` planes | the same forced `-pix_fmt yuv420p` on the extracting ffmpeg (`:242-243`) | self-consistent: the frame arithmetic and the file it slices come from one explicit ffmpeg argument. Mild real hole: `Av1Config` (`:536-544`) has no depth field, so the encoder's own output depth is whatever it defaults to. **not fixed** (bench table, no oracle compare) | | |
| 42 | +| `tools/ec-bench/src/main.rs:404-410`, `:423`, `:452`, `:485` | 10-bit for the `ec-hw` row | a comment about the local VA driver's stored format, plus a matching `-pix_fmt yuv420p10le` at `:485` | arithmetic agrees with the forced format. **not fixed** | | |
| 43 | +| `shims/**` | — | 16 Cargo path-shim crates (`Cargo.toml` + thin `lib.rs` re-exports), no video or raw-byte code | none. **out of scope** | | |
| 44 | +| `scripts/{build-aom-oracle,build-aom-affine-oracle,gen-bitstream-fixtures,gen_vp8_fixtures,gen-still-fixtures,pgs-white-level,scan-real-library,fetch-vectors,link-fixtures}.sh`, `scripts/av1-timeline-report.py` | force an explicit `-pix_fmt` (or read no planes at all); sizes that exist (`gen_vp8_fixtures.sh:60`, `pgs-white-level.sh:27`) are computed from that same argument | CLI flag | none. **not flagged** | | |
| 45 | + | |
| 46 | +Sites fixed: 3 (`examples/dump_yuv.rs`, `scripts/raw_to_y4m.py`, | |
| 47 | +`scripts/lr-sgr-pin-harness.c`). Sites examined and deliberately NOT fixed: | |
| 48 | +7 (`decode_probe.rs`, `tools/oracle/src/main.rs`, `tools/ec-bench` x2, | |
| 49 | +`instrument-aom-oracle.sh` rungs 1/6/7/15, `superres-pin-harness.c`), each with | |
| 50 | +the reason above. | |
| 51 | + | |
| 52 | +## 3. `examples/dump_yuv.rs` — what changed | |
| 53 | + | |
| 54 | +- The depth comes from the stream's **own parsed sequence header** | |
| 55 | + (`ec_av1_syntax::Av1Parser` walking OBU by OBU until a sequence header | |
| 56 | + appears, then `seq.color_config.bit_depth`). It is never taken from the file | |
| 57 | + name, the extension, or a reference tool's `-pix_fmt`. | |
| 58 | +- 8 bit → one byte per sample; 10/12 → little-endian `u16` (the container | |
| 59 | + both oracles use). Monochrome streams write the luma plane only. | |
| 60 | +- `--depth N` is an **assertion, not a switch**: the packing always follows the | |
| 61 | + parsed header, and a contradiction exits 1 naming both depths, both | |
| 62 | + bytes-per-sample values, and the size mismatch the `cmp` would have shown. | |
| 63 | + Two spellings accepted (`--depth 8`, `--depth=8`); given twice → usage error. | |
| 64 | +- A stream with no parseable sequence header → hard error instead of a guess. | |
| 65 | +- A sample that does not fit the container about to be written (an 8-bit | |
| 66 | + header with a sample above 255) → hard error. That is the mirror of the | |
| 67 | + original bug and the reason `as u8` may never be applied silently here. | |
| 68 | +- The docstring no longer says `yuv420p10le`; it states the both-depths | |
| 69 | + contract and the `--depth` assertion. | |
| 70 | +- Measured while doing this: the crate's own 8-bit fixture | |
| 71 | + `av1_192x128_8bit_intra64_in_inter.obu` parses `subsampling_x/y = 1/1`, | |
| 72 | + which is **4:2:0** (spec 5.5.3) — 36864 samples for 192x128 = W*H*3/2. The | |
| 73 | + first pix_fmt table I wrote had 1/1 → 4:4:0 and the measurement caught it; | |
| 74 | + the shipped table is 0/0→444, 0/1→440, 1/0→422, 1/1→420. | |
| 75 | + | |
| 76 | +## 4. Proof | |
| 77 | + | |
| 78 | +Committed crate fixtures only, worktree at `afa13bcf`, | |
| 79 | +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target`. | |
| 80 | + | |
| 81 | +### 4.1 GREEN — 8-bit stream, committed fixture | |
| 82 | + | |
| 83 | +``` | |
| 84 | +$ dump_yuv crates/ec-av1/fixtures/av1_192x128_8bit_intra64_in_inter.obu /tmp/dy/eight | |
| 85 | +sequence header: bit_depth 8 -> 1 byte(s) per sample, seq_profile 0, subsampling 1/1, mono_chrome false; ffmpeg -pix_fmt yuv420p | |
| 86 | +frame 0: 192x128 -> /tmp/dy/eight.f0.yuv (36864 samples, 36864 bytes, yuv420p) | |
| 87 | +... | |
| 88 | +eight.f0.yuv 36864 bytes <- W*H*3/2 = 192*128*3/2 = 36864 (Y 24576 + U 6144 + V 6144) | |
| 89 | +``` | |
| 90 | +Byte-exact against the oracle at its own depth: | |
| 91 | +`aomdec --codec=av1 --rawvideo -o ref8.raw <fixture>` → 221184 bytes for 6 | |
| 92 | +frames; our 6 concatenated frames → 221184 bytes; `cmp` → **IDENTICAL**. | |
| 93 | + | |
| 94 | +### 4.2 GREEN — high-bit-depth stream, committed fixture | |
| 95 | + | |
| 96 | +``` | |
| 97 | +$ dump_yuv crates/ec-av1/fixtures/av112bit-key.obu /tmp/dy/twelve | |
| 98 | +sequence header: bit_depth 12 -> 2 byte(s) per sample, seq_profile 2, subsampling 1/1, mono_chrome false; ffmpeg -pix_fmt yuv420p12le | |
| 99 | +frame 0: 160x128 -> /tmp/dy/twelve.f0.yuv (30720 samples, 61440 bytes, yuv420p12le) | |
| 100 | +twelve.f0.yuv 61440 bytes <- W*H*3 = 160*128*3 = 61440 (30720 samples x 2 bytes) | |
| 101 | +cmp twelve.f0.yuv (ffmpeg -f obu -pix_fmt yuv420p12le -f rawvideo) -> IDENTICAL | |
| 102 | +``` | |
| 103 | + | |
| 104 | +### 4.3 The wrong depth fails loudly and writes nothing | |
| 105 | + | |
| 106 | +``` | |
| 107 | +$ dump_yuv .../av1_192x128_8bit_intra64_in_inter.obu /tmp/dy/wrong --depth 10 | |
| 108 | +dump_yuv: ...: --depth 10 contradicts the stream's own sequence header, which carries | |
| 109 | +bit_depth 8 (seq_profile 0, subsampling 1/1, mono_chrome false). Writing 10-bit would emit | |
| 110 | +2 bytes per sample against the oracle's aomdec --rawvideo / ffmpeg -pix_fmt yuv420p (1 bytes | |
| 111 | +per sample, W*H*3/2 for 4:2:0), so every `cmp` would fail on size alone and read like a decoder | |
| 112 | +defect. Nothing was written. | |
| 113 | +exit=1 | |
| 114 | +ls: cannot access '/tmp/dy/wrong.f0.yuv': No such file or directory | |
| 115 | + | |
| 116 | +$ dump_yuv .../av112bit-key.obu /tmp/dy/wrong2 --depth=8 -> same message, exit=1, no file | |
| 117 | +$ dump_yuv .../av1_192x128_... --depth=8 -> runs, 36864 bytes (assertion holds) | |
| 118 | +$ dump_yuv .../av112bit-key.obu --depth 12 -> runs, 61440 bytes | |
| 119 | +``` | |
| 120 | + | |
| 121 | +### 4.4 RED-BEFORE — the depth derivation reverted | |
| 122 | + | |
| 123 | +`git show HEAD:crates/ec-av1/examples/dump_yuv.rs` restored, rebuilt, same | |
| 124 | +8-bit fixture, same command: | |
| 125 | + | |
| 126 | +``` | |
| 127 | +--- RED (pre-fix, u16 unconditional) on the 8-bit fixture --- | |
| 128 | +ours 73728 bytes <- 2 x 36864 | |
| 129 | +aomdec --rawvideo 221184 bytes <- 6 x 36864 | |
| 130 | +cmp exit=1 (mismatch on size alone) | |
| 131 | +``` | |
| 132 | +73728 = 2 x (W*H*3/2): exactly the silent 2x file the lane was chartered to | |
| 133 | +close. Fixed tree restored and rebuilt afterwards. | |
| 134 | + | |
| 135 | +### 4.5 `scripts/raw_to_y4m.py` | |
| 136 | + | |
| 137 | +``` | |
| 138 | +$ ... | raw_to_y4m.py 64 64 25 g8.y4m 8 -> YUV4MPEG2 ... C420jpeg, 18491 bytes (3 frames) | |
| 139 | +$ ... | raw_to_y4m.py 64 64 25 g10.y4m 10 -> YUV4MPEG2 ... C420p10, 36922 bytes (3 frames) | |
| 140 | +$ 12289 bytes | raw_to_y4m.py ... 8 | |
| 141 | +raw_to_y4m.py: stdin is 12289 bytes, not a whole number of 64x64 4:2:0 frames at 8-bit | |
| 142 | +(1 bytes per sample, 6144 bytes each): 1 trailing bytes. At the other depth a frame would be | |
| 143 | +12288 bytes and each frame would carry half a frame of the next one's planes. Refusing to | |
| 144 | +write a misframed y4m. exit=1, no file | |
| 145 | +$ DEPTH 7 -> "DEPTH 7 is not 8, 10 or 12 ..." exit=1 | |
| 146 | +$ DEPTH omitted (the old 4-arg invocation) -> usage error, exit=1 | |
| 147 | +``` | |
| 148 | +Documented limit, stated in the script's own docstring: raw planar video | |
| 149 | +carries no depth, so a 10-bit stream of N frames is exactly 2N 8-bit frames | |
| 150 | +and no length test can separate them. That case is caught by the caller | |
| 151 | +asserting the right DEPTH — which is why the argument is required, not | |
| 152 | +defaulted. | |
| 153 | + | |
| 154 | +### 4.6 `scripts/lr-sgr-pin-harness.c` | |
| 155 | + | |
| 156 | +Linked against `~/.cache/aom-oracle/build/libaom.a`, `/tmp/lr_full.bin` | |
| 157 | +faked at three sizes: | |
| 158 | + | |
| 159 | +``` | |
| 160 | +1020 bytes (correct) -> ret=0 / out[1][6] = 151 / dgd[1][6] = 151 (real libaom taps printed) | |
| 161 | +2040 bytes (2x, HBD) -> "/tmp/lr_full.bin is 2040 bytes, this harness reads it as 8-bit | |
| 162 | + (1020 bytes: 102x10 at 1 byte per sample). That is exactly a 2x-size | |
| 163 | + high-bit-depth capture: re-capture it as 8-bit, or port the harness to | |
| 164 | + the uint16 arm (bit_depth=10, highbd=1) before trusting a single | |
| 165 | + printed tap." exit=1 | |
| 166 | + 900 bytes (short) -> "... 900 bytes ... Recapture it, or fix bw/bh to the plane the | |
| 167 | + capture came from." exit=1 | |
| 168 | +``` | |
| 169 | + | |
| 170 | +## 5. Not done, deliberately | |
| 171 | + | |
| 172 | +- `instrument-aom-oracle.sh` rungs 1/6/7/15 (section 2): changing one side of | |
| 173 | + a byte-paired rung breaks the pairing, and both sides are decoder/oracle C. | |
| 174 | + Rung 12 is already depth-correct; that is the rung the depth-sensitive | |
| 175 | + compares use. | |
| 176 | +- `tools/oracle/src/main.rs` and `tools/ec-bench/src/main.rs`: already the | |
| 177 | + "explicit argument that is checked" shape (a length/frame-count FAIL), with | |
| 178 | + no header parser reachable from those binaries to derive a better answer | |
| 179 | + from (`oracle` drives ffmpeg through std pipes and is deliberately | |
| 180 | + dependency-free). | |
| 181 | +- `decode_probe.rs`: its two output targets are separate, explicitly named | |
| 182 | + files; see section 2. | |
| 183 | +- No gate, counter, decoder path or fixture was touched. |
lanes/merge-wave-4.report.mdadded+189 -0
| @@ -0,0 +1,189 @@ | ||
| 1 | +# Merge wave 4 — integration report | |
| 2 | + | |
| 3 | +Base `aa0ac8c2` (wave 2, "clean-checkout census"). Four branches, four | |
| 4 | +`--no-ff` merge commits, **zero conflicts** on any of them. No push. | |
| 5 | + | |
| 6 | +## Per-branch table | |
| 7 | + | |
| 8 | +| # | Branch | Tip merged | Merge base | True delta (base → tip) | Conflicts | | |
| 9 | +|---|--------|-----------|-----------|-------------------------|-----------| | |
| 10 | +| 1 | `lane-av1recipehunt` | `1acf1818` | `aa0ac8c2` | 9 files, +1164/-545 | none | | |
| 11 | +| 2 | `lane-av1rect8x16` | `ee56661f` | `afa13bcf` | 2 files, +493/-0 | none | | |
| 12 | +| 3 | `lane-h264reallib` | `25c996b2` | `a21f3680` | 7 files, +562/-96 | none (one auto-merged hunk, `crates/ec-h264/tests/conformance.rs`) | | |
| 13 | +| 4 | `lane-av1dumpyuv` | `60a7788a` | `afa13bcf` | 4 files, +437/-26 | none | | |
| 14 | + | |
| 15 | +**True delta is measured against each branch's own merge base, not against an | |
| 16 | +older tip.** `git diff a21f3680 1acf1818` for branch 1 shows 52 files / +10975 | |
| 17 | +of rebase noise; `aa0ac8c2 → 1acf1818` is the real 9-file delta. Branch 3's | |
| 18 | +merge base is also `a21f3680` (it forked before wave 2), which is why its | |
| 19 | +delta is quoted against that commit. | |
| 20 | + | |
| 21 | +### 1. `lane-av1recipehunt` @ `1acf1818` — merged first | |
| 22 | + | |
| 23 | +Landed first by design: it is the only branch touching `src/stream.rs` and | |
| 24 | +`src/encode.rs`, and it introduces the three fixture pins the later branches' | |
| 25 | +reports cite. | |
| 26 | + | |
| 27 | +- **Three TRACKED fixture pins** (verified with `git ls-tree` at the merged | |
| 28 | + HEAD, and `stat` on disk): | |
| 29 | + | |
| 30 | + | Fixture | Bytes | Blob sha | | |
| 31 | + |---------|-------|----------| | |
| 32 | + | `crates/ec-av1/fixtures/rect64_dq_drift.obu` | 8384 | `29f6e5dabcb1630baf593ea977952550a5a2bb49` | | |
| 33 | + | `crates/ec-av1/fixtures/intra14_256x192_8bit.obu` | 35179 | `1d345e07f94c2a61b7849d88970b4ab0408f05e1` | | |
| 34 | + | `crates/ec-av1/fixtures/intra14_256x192_10bit.obu` | 34727 | `b16114a42e4ad49c59a1e9d9839556c4caf2ddd9` | | |
| 35 | + | |
| 36 | + All three sizes match the reviewer's independent recomputation. | |
| 37 | +- `src/stream.rs` +952/-545 (the rebase-noise bulk of this branch), plus | |
| 38 | + `src/encode.rs` +117, `src/tile.rs` +68, and the two example probes. | |
| 39 | +- **Gates: 3 un-ignored, 1 deleted** (see "Gate count" below). | |
| 40 | +- Dedupe result: **no duplicate blobs** in `crates/ec-av1/fixtures/` | |
| 41 | + (`git ls-tree -r` grouped by blob sha — no sha appears under two names). | |
| 42 | + Nothing to dedupe; no dedupe needed to be mentioned in a message. | |
| 43 | + | |
| 44 | +### 2. `lane-av1rect8x16` @ `ee56661f` | |
| 45 | + | |
| 46 | +Pure test-only `refusal_inventory.rs` +246/-0 plus its report. Zero merge | |
| 47 | +surface against wave 3 and against branch 1. | |
| 48 | + | |
| 49 | +**Fixed in the merge commit:** the inventory comment at | |
| 50 | +`crates/ec-av1/src/refusal_inventory.rs:556` read *"All nine call sites"*, | |
| 51 | +which contradicts the test's own `assert_eq!(sites, 8)` at line 1642 and the | |
| 52 | +lane report. The nine is a count of **textual `decode_block_rect(` matches in | |
| 53 | +`decode.rs`**, which is 1 declaration + 8 call sites — the test skips the | |
| 54 | +declaration explicitly (`if src[..i].ends_with("fn ") { continue; }`). The | |
| 55 | +comment now states that arithmetic. One line of prose, no code change. | |
| 56 | + | |
| 57 | +### 3. `lane-h264reallib` @ `25c996b2` | |
| 58 | + | |
| 59 | +Real-media-library test sites reshaped to `#[ignore]` with fact-based reasons, | |
| 60 | +so a site that cannot run because ffmpeg/ffprobe or a media file is absent no | |
| 61 | +longer reads as "passed". Four follow-ups in the same tip: | |
| 62 | + | |
| 63 | +- `ec-probe`: a silent skip replaced by a **named** SKIP that states what was | |
| 64 | + missing rather than returning quietly; | |
| 65 | +- `ec-aac`: two `env::var("HOME").unwrap()` → `unwrap_or_default()`; | |
| 66 | +- `ec-h264`: one hardcoded absolute manifest path → `CARGO_MANIFEST_DIR`-relative. | |
| 67 | + | |
| 68 | +> **Stale line numbers — deliberately not amended.** The branch's commit | |
| 69 | +> message cites `file:line` locations that the **same commit's** rustfmt pass | |
| 70 | +> renumbered. The citations were accurate when written and are stale at this | |
| 71 | +> tip. Recorded here and in the merge message; the message text itself is | |
| 72 | +> left alone rather than "fixed", because editing it would desynchronise the | |
| 73 | +> record of what the lane actually did. | |
| 74 | + | |
| 75 | +### 4. `lane-av1dumpyuv` @ `60a7788a` | |
| 76 | + | |
| 77 | +Three non-test surfaces now carry the sample depth as data: | |
| 78 | + | |
| 79 | +- `crates/ec-av1/examples/dump_yuv.rs` — **derives** depth from the stream's | |
| 80 | + own sequence header (spec 5.5.2 `color_config.bit_depth`) before a byte is | |
| 81 | + written. Never taken from the file name, the output extension, or a | |
| 82 | + convention. `--depth N` is accepted only as a claim, and a mismatch against | |
| 83 | + the parsed header is a hard error naming both depths. | |
| 84 | +- `scripts/raw_to_y4m.py` — **asserts** depth as an explicit positional | |
| 85 | + argument (`W H FPS out.y4m DEPTH`, DEPTH = bytes per sample) and validates | |
| 86 | + the byte count is a whole number of frames at the claimed depth. | |
| 87 | +- `scripts/lr-sgr-pin-harness.c` — **takes** `bit_depth`/`highbd` as | |
| 88 | + parameters and names the failure mode when a high-bit-depth capture is fed | |
| 89 | + to the 8-bit arm. | |
| 90 | + | |
| 91 | +> **Disclosed limit, not a silent hole.** A 10-bit stream of N frames is | |
| 92 | +> *exactly* the same byte count as 2N 8-bit frames, so **length alone can | |
| 93 | +> never distinguish them** — no length test can. That is stated in the | |
| 94 | +> `raw_to_y4m.py` module docstring, and is why the depth is an explicit | |
| 95 | +> argument rather than something inferred from the byte count. | |
| 96 | + | |
| 97 | +## Gate count: 742 → 742 (net zero), cause accounted | |
| 98 | + | |
| 99 | +`cargo test -p ec-av1 --lib -- --list`: | |
| 100 | + | |
| 101 | +``` | |
| 102 | +742 tests, 0 benchmarks | |
| 103 | +``` | |
| 104 | + | |
| 105 | +Wave 2's baseline was the same measure: wave 2's own report line 155 reads | |
| 106 | +`25 passed; 0 failed; 0 ignored; 0 measured; 717 filtered out` = 742. After | |
| 107 | +wave 4 the same filter reads `26 passed; … 716 filtered out` = 742. | |
| 108 | + | |
| 109 | +**Net zero is arithmetic, not luck.** Wave 4 moved the lib test count in | |
| 110 | +three directions at once: | |
| 111 | + | |
| 112 | +| Change | Count | Why | | |
| 113 | +|--------|-------|-----| | |
| 114 | +| `a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact` **deleted** | −1 | `DRL_CLAMP_HITS` is provably unreachable (its coverage claim moved to `encode.rs:15689`, the pricer's own offer-set enumeration) | | |
| 115 | +| `every_chroma_unit_decode_block_rect_can_present_has_a_coefficient_table` **added** (branch 2) | +1 | new `refusal_inventory` enumeration + witness gate | | |
| 116 | +| 3 gates **un-ignored** | ±0 | `#[ignore]`d tests still appear in `--list`; un-ignoring changes runnability, not the roster | | |
| 117 | + | |
| 118 | +### The deletion and its replacement | |
| 119 | + | |
| 120 | +Deleted in `4eab9e40`/`83a0066e`. The gate asserted `drl_clamp_hits() > 0` on | |
| 121 | +a real 1280x768 sb128 clip; the counter is unreachable, so the gate was a | |
| 122 | +guaranteed red once run. Its coverage claim is now carried by the pricer's | |
| 123 | +offer-set enumeration at `crates/ec-av1/src/encode.rs:15689`, whose doc | |
| 124 | +comment names the deleted gate so the lineage is greppable. The four | |
| 125 | +1280x768 `force_sb128(true)` own-reconstruction gates the reviewer verified | |
| 126 | +remain in the tree (`src/encode.rs:18653`, `:18755`, `:18852`, `:18941`, and | |
| 127 | +siblings) and justify the deletion. | |
| 128 | + | |
| 129 | +`grep -rn a_128_superblock_clip_whose_drl_index crates/` now returns exactly | |
| 130 | +one hit — the `encode.rs:15691` doc comment naming it as replaced. No dangling | |
| 131 | +test reference. | |
| 132 | + | |
| 133 | +### The three un-ignored gates, run | |
| 134 | + | |
| 135 | +``` | |
| 136 | +test stream::tests::a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact ... ok | |
| 137 | +test stream::tests::a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact_10bit ... ok | |
| 138 | +test stream::tests::a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_and_delta_q_decodes_pixel_exact ... ok | |
| 139 | +test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 739 filtered out | |
| 140 | +``` | |
| 141 | + | |
| 142 | +All three are green **un-ignored**, not vacuously skipped — the un-ignore is | |
| 143 | +honest. | |
| 144 | + | |
| 145 | +## Verification outputs | |
| 146 | + | |
| 147 | +`cargo check -p ec-av1 --all-targets`, run after **each** merge, and re-run | |
| 148 | +with `src/lib.rs` + `examples/dump_yuv.rs` touched so the cached-green case | |
| 149 | +could not mask a stale binary: | |
| 150 | + | |
| 151 | +``` | |
| 152 | + Checking ec-av1 v0.1.0 (/home/user/Documents/Code/Rust/edith_codecs/crates/ec-av1) | |
| 153 | + Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.41s | |
| 154 | +``` | |
| 155 | + | |
| 156 | +Clean — zero errors, zero warnings. | |
| 157 | + | |
| 158 | +Branch 3 touches four crates outside `ec-av1`, so the check was widened for | |
| 159 | +that merge only: | |
| 160 | + | |
| 161 | +``` | |
| 162 | +cargo check -p ec-av1 -p ec-aac -p ec-h264 -p ec-matroska -p ec-probe --all-targets | |
| 163 | + Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.16s | |
| 164 | +``` | |
| 165 | + | |
| 166 | +`cargo test -p ec-av1 --lib -- gate_coverage refusal_inventory`: | |
| 167 | + | |
| 168 | +``` | |
| 169 | +test result: ok. 26 passed; 0 failed; 0 ignored; 0 measured; 716 filtered out; finished in 0.86s | |
| 170 | +``` | |
| 171 | + | |
| 172 | +Green. The +1 against wave 2's 25 is branch 2's new gate. | |
| 173 | + | |
| 174 | +`cargo test -p ec-av1 --lib -- --list | wc -l` → **744** lines, of which 742 | |
| 175 | +are `: test` entries; the summary line itself prints `742 tests, 0 benchmarks`. | |
| 176 | +(744 = 742 test names + the `running 0 tests` and summary lines.) | |
| 177 | + | |
| 178 | +Smoke: `python3 scripts/raw_to_y4m.py` with no args prints the usage line | |
| 179 | +including the now-required `DEPTH` argument, and the module imports cleanly. | |
| 180 | + | |
| 181 | +## Notes | |
| 182 | + | |
| 183 | +- **NO PUSH.** The four merge commits are local on `main`. | |
| 184 | +- Wave 3 was **not** merged and `src/refusal_inventory.rs` was not edited | |
| 185 | + beyond the one-line comment fix in merge 2. | |
| 186 | +- The pre-commit hook's whole-staged-tree `format-staged.py` produced **no** | |
| 187 | + churn in any of the four merges: `git status --porcelain` was empty after | |
| 188 | + each commit, and the recipehunt merge's tree is byte-identical to `1acf1818`. | |
| 189 | + The accepted-churn escape hatch was not needed. |
scripts/lr-sgr-pin-harness.cmodified+26 -2
| @@ -30,10 +30,34 @@ int main(void) { | ||
| 30 | 30 | // sized for that max, so replicate the chunking (target col=6 is in |
| 31 | 31 | // the first 64-wide chunk). |
| 32 | 32 | const int w = 64, h = 4; |
| 33 | - uint8_t *buf = malloc(bw * bh); | |
| 33 | + // The depth of `/tmp/lr_full.bin` is NOT in the file: the capture is a raw | |
| 34 | + // plane dump written by an env-gated `std::fs::write` inside | |
| 35 | + // `apply_sgrproj_stripe`, and whoever re-captures it from a 10/12-bit pin | |
| 36 | + // gets 2 bytes per sample, i.e. a file TWICE this size whose first half | |
| 37 | + // still looks like plausible plane data. Reading it at 1 byte per sample | |
| 38 | + // would then print self-guided-restoration A/B taps for the wrong pixels | |
| 39 | + // and nothing would fail -- so the size is the assertion: a 2x capture | |
| 40 | + // must not pass as an 8-bit one. | |
| 41 | + const size_t expect = (size_t)bw * bh; | |
| 42 | + uint8_t *buf = malloc(expect); | |
| 34 | 43 | FILE *f = fopen("/tmp/lr_full.bin", "rb"); |
| 35 | 44 | if (!f) { perror("open"); return 1; } |
| 36 | - if (fread(buf, 1, bw * bh, f) != (size_t)(bw * bh)) { fprintf(stderr, "short read\n"); return 1; } | |
| 45 | + fseek(f, 0, SEEK_END); | |
| 46 | + const long size = ftell(f); | |
| 47 | + fseek(f, 0, SEEK_SET); | |
| 48 | + if (size != (long)expect) { | |
| 49 | + fprintf(stderr, | |
| 50 | + "/tmp/lr_full.bin is %ld bytes, this harness reads it as %d-bit (%zu bytes: " | |
| 51 | + "%dx%d at 1 byte per sample). %s\n", | |
| 52 | + size, 8, expect, bw, bh, | |
| 53 | + size == 2 * (long)expect | |
| 54 | + ? "That is exactly a 2x-size high-bit-depth capture: re-capture it as 8-bit, " | |
| 55 | + "or port the harness to the uint16 arm (bit_depth=10, highbd=1) before " | |
| 56 | + "trusting a single printed tap." | |
| 57 | + : "Recapture it, or fix bw/bh to the plane the capture came from."); | |
| 58 | + return 1; | |
| 59 | + } | |
| 60 | + if (fread(buf, 1, expect, f) != expect) { fprintf(stderr, "short read\n"); return 1; } | |
| 37 | 61 | fclose(f); |
| 38 | 62 | |
| 39 | 63 | const uint8_t *dgd8 = buf + 3 * bw + 3; // logical (0,0) |
scripts/raw_to_y4m.pymodified+52 -4
| @@ -1,15 +1,63 @@ | ||
| 1 | 1 | #!/usr/bin/env python3 |
| 2 | 2 | """Wrap raw planar yuv420p frames into a minimal y4m (for vpxenc). |
| 3 | 3 | |
| 4 | - ffmpeg ... -f rawvideo - | raw_to_y4m.py W H FPS out.y4m | |
| 4 | + ffmpeg ... -f rawvideo - | raw_to_y4m.py W H FPS out.y4m DEPTH | |
| 5 | + | |
| 6 | +DEPTH (8, 10 or 12) is REQUIRED and is the number of BYTES per sample in the | |
| 7 | +raw stream on stdin, not the stream's bit depth: ffmpeg's rawvideo muxer | |
| 8 | +never packs to the bit depth, it uses 1 byte for `yuv420p` and 2 bytes for | |
| 9 | +`yuv420p10le` / `yuv420p12le`. This script has no parser and no way to learn | |
| 10 | +it, so the depth is an ASSERTED argument: it is checked against the stdin | |
| 11 | +length, and a mismatch is a hard error naming the depth, the byte count it | |
| 12 | +implied, and the misframed y4m it would have produced. The old version | |
| 13 | +computed `w*h*3//2` unconditionally, so a 10-bit stream (2 bytes per sample) | |
| 14 | +was cut into frames at half length, the chroma planes of frame N+1 were read | |
| 15 | +as the tail of frame N, and the last partial frame was dropped silently -- | |
| 16 | +a y4m that vpxenc accepts and encodes, with no error anywhere. | |
| 17 | + | |
| 18 | +The y4m header's `C` tag follows the same argument, so the wrapped stream | |
| 19 | +carries the depth it actually has. | |
| 20 | + | |
| 21 | +LIMIT, stated because it cannot be fixed here: raw planar video carries NO | |
| 22 | +depth of its own, so the length check below can only catch a stream whose | |
| 23 | +byte count is not a whole number of frames at the claimed depth. A 10-bit | |
| 24 | +stream of N frames is exactly 2N 8-bit frames, and no length test can tell | |
| 25 | +those apart -- that case is caught only by the caller asserting the right | |
| 26 | +DEPTH, which is why DEPTH is required and not defaulted. | |
| 5 | 27 | """ |
| 28 | + | |
| 6 | 29 | import sys |
| 7 | 30 | |
| 8 | -w, h, fps, out = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4] | |
| 9 | -frame = int(w) * int(h) * 3 // 2 | |
| 31 | + | |
| 32 | +if len(sys.argv) != 6: | |
| 33 | + sys.exit( | |
| 34 | + "usage: raw_to_y4m.py W H FPS out.y4m DEPTH " | |
| 35 | + "(DEPTH = 8|10|12, the BYTES per sample on stdin)" | |
| 36 | + ) | |
| 37 | +w, h, fps, out, depth = sys.argv[1:6] | |
| 38 | +try: | |
| 39 | + depth = int(depth) | |
| 40 | +except ValueError: | |
| 41 | + sys.exit(f"raw_to_y4m.py: DEPTH {depth!r} is not a number (8, 10 or 12)") | |
| 42 | +if depth not in (8, 10, 12): | |
| 43 | + sys.exit( | |
| 44 | + f"raw_to_y4m.py: DEPTH {depth} is not 8, 10 or 12 -- the frame size below would be " | |
| 45 | + "wrong and every frame after the first would be misframed" | |
| 46 | + ) | |
| 47 | +bpp = 1 if depth == 8 else 2 | |
| 48 | +frame = int(w) * int(h) * 3 // 2 * bpp | |
| 10 | 49 | raw = sys.stdin.buffer.read() |
| 50 | +if len(raw) % frame: | |
| 51 | + sys.exit( | |
| 52 | + f"raw_to_y4m.py: stdin is {len(raw)} bytes, not a whole number of " | |
| 53 | + f"{int(w)}x{int(h)} 4:2:0 frames at {depth}-bit ({bpp} bytes per sample, " | |
| 54 | + f"{frame} bytes each): {len(raw) % frame} trailing bytes. At the other depth a " | |
| 55 | + f"frame would be {int(w) * int(h) * 3 // 2 * (3 - bpp)} bytes and each frame would " | |
| 56 | + "carry half a frame of the next one's planes. Refusing to write a misframed y4m." | |
| 57 | + ) | |
| 58 | +ctag = {8: "C420jpeg", 10: "C420p10", 12: "C420p12"}[depth] | |
| 11 | 59 | with open(out, "wb") as f: |
| 12 | - f.write(f"YUV4MPEG2 W{w} H{h} F{fps}:1 Ip A1:1 C420jpeg\n".encode()) | |
| 60 | + f.write(f"YUV4MPEG2 W{w} H{h} F{fps}:1 Ip A1:1 {ctag}\n".encode()) | |
| 13 | 61 | for i in range(len(raw) // frame): |
| 14 | 62 | f.write(b"FRAME\n") |
| 15 | 63 | f.write(raw[i * frame : (i + 1) * frame]) |