The probe armed a window film B does not have
Browse files at this commit2ebcc2c13a27529a8c664b805d6995b2cf5c4a88Parent: 5918fdb- fix
- the probe armed a window film B does not have
5 changed files +275 -89
- crates/ec-av1/examples/enc_probe.rs +32 -35
- crates/ec-av1/src/encode.rs +100 -54
- crates/ec-av1/src/lib.rs +1 -0
- crates/ec-av1/src/probe.rs +86 -0
- lanes/census-longgop-v2.md +56 -0
crates/ec-av1/examples/enc_probe.rsmodified+32 -35
| @@ -3,48 +3,45 @@ | |||
| 3 | //! our encoder. Also the byte-exactness gate for encoder-internal rewrites: | 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. | 4 | //! it prints each point's stream length and a hash of its bytes. |
| 5 | //! | 5 | //! |
| 6 | -//! Usage: `enc_probe <clip> <width> <height> <frames> [q,q,..]` | 6 | +//! Usage: `enc_probe <clip> <width|gate> <height> <frames> [q,q,..]` |
| 7 | - | 7 | +//! |
| 8 | -use std::process::Command; | 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. | ||
| 9 | 13 | ||
| 10 | fn main() { | 14 | fn main() { |
| 11 | let a: Vec<String> = std::env::args().skip(1).collect(); | 15 | let a: Vec<String> = std::env::args().skip(1).collect(); |
| 12 | - let (clip, width, height, frames) = ( | 16 | + let clip = a[0].clone(); |
| 13 | - a[0].clone(), | 17 | + let frames: usize = a[3].parse().unwrap(); |
| 14 | - a[1].parse::<usize>().unwrap(), | 18 | + let gate = a[1] == "gate"; |
| 15 | - a[2].parse::<usize>().unwrap(), | 19 | + let (width, height) = match gate { |
| 16 | - a[3].parse::<usize>().unwrap(), | 20 | + true => (0, 0), |
| 17 | - ); | 21 | + false => (a[1].parse().unwrap(), a[2].parse().unwrap()), |
| 22 | + }; | ||
| 18 | let qs: Vec<u8> = a | 23 | let qs: Vec<u8> = a |
| 19 | .get(4) | 24 | .get(4) |
| 20 | .map_or_else(|| vec![150, 120, 90, 60], |s| s.split(',').map(|q| q.parse().unwrap()).collect()); | 25 | .map_or_else(|| vec![150, 120, 90, 60], |s| s.split(',').map(|q| q.parse().unwrap()).collect()); |
| 21 | 26 | ||
| 22 | - let out = Command::new("ffmpeg") | 27 | + // lane-census/lane-probe: the BD gate's native rows CROP (`EC_ENC_VF`) and |
| 23 | - .args(["-v", "error", "-i", &clip, "-frames:v", &frames.to_string()]) | 28 | + // SEEK (`EC_ENC_SS`) -- without the seek this probe read film B's black |
| 24 | - // lane-census: the BD gate's native rows CROP, they do not scale, so | 29 | + // leader and every census off it was probe-relative. |
| 25 | - // the census can ask for the gate's own recipe (`EC_ENC_VF`). | 30 | + let (vf, width, height) = match gate { |
| 26 | - .args([ | 31 | + true => ec_av1::probe::gate_crop(&clip), |
| 27 | - "-vf", | 32 | + false => ( |
| 28 | - &std::env::var("EC_ENC_VF").unwrap_or_else(|_| format!("scale={width}:{height}")), | 33 | + std::env::var("EC_ENC_VF").unwrap_or_else(|_| format!("scale={width}:{height}")), |
| 29 | - ]) | 34 | + width, |
| 30 | - .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]) | 35 | + height, |
| 31 | - .output() | 36 | + ), |
| 32 | - .expect("ffmpeg failed to run"); | 37 | + }; |
| 33 | - assert!(out.status.success(), "ffmpeg: {}", String::from_utf8_lossy(&out.stderr)); | 38 | + let vf = match gate { |
| 34 | - let (luma, chroma) = (width * height, width * height / 4); | 39 | + true => std::env::var("EC_ENC_VF").unwrap_or(vf), |
| 35 | - let frame_len = luma + 2 * chroma; | 40 | + false => vf, |
| 36 | - let source: Vec<ec_av1::encode::Picture> = (0..frames) | 41 | + }; |
| 37 | - .map(|i| { | 42 | + eprintln!("probe: {width}x{height} vf={vf}"); |
| 38 | - let b = &out.stdout[i * frame_len..][..frame_len]; | 43 | + let skip = std::env::var("EC_ENC_SS").unwrap_or_else(|_| "0".into()); |
| 39 | - ec_av1::encode::Picture { | 44 | + let source = ec_av1::probe::source(&clip, &skip, &vf, width, height, frames); |
| 40 | - width, | ||
| 41 | - height, | ||
| 42 | - y: b[..luma].iter().map(|&v| u16::from(v)).collect(), | ||
| 43 | - u: b[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), | ||
| 44 | - v: b[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), | ||
| 45 | - } | ||
| 46 | - }) | ||
| 47 | - .collect(); | ||
| 48 | 45 | ||
| 49 | let start = std::time::Instant::now(); | 46 | let start = std::time::Instant::now(); |
| 50 | for q in qs { | 47 | for q in qs { |
crates/ec-av1/src/encode.rsmodified+100 -54
| @@ -12996,37 +12996,11 @@ mod tests { | |||
| 12996 | height: usize, | 12996 | height: usize, |
| 12997 | frames: usize, | 12997 | frames: usize, |
| 12998 | ) -> Vec<Picture> { | 12998 | ) -> Vec<Picture> { |
| 12999 | - let out = Command::new("ffmpeg") | 12999 | + // ONE definition of the gate's loader recipe, shared with |
| 13000 | - .args(["-v", "error", "-ss", skip, "-i", clip]) | 13000 | + // `examples/enc_probe` so the instrument cannot arm a different source |
| 13001 | - .args(["-frames:v", &frames.to_string()]) | 13001 | + // than the gate it reports on (class `instrument disagrees with the |
| 13002 | - .args(["-vf", vf]) | 13002 | + // gate`; lane-probe). |
| 13003 | - .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]) | 13003 | + crate::probe::source(clip, skip, vf, width, height, frames) |
| 13004 | - .output() | ||
| 13005 | - .expect("ffmpeg failed to run"); | ||
| 13006 | - assert!( | ||
| 13007 | - out.status.success(), | ||
| 13008 | - "ffmpeg: {}", | ||
| 13009 | - String::from_utf8_lossy(&out.stderr) | ||
| 13010 | - ); | ||
| 13011 | - let (luma, chroma) = (width * height, width * height / 4); | ||
| 13012 | - let frame_len = luma + 2 * chroma; | ||
| 13013 | - assert_eq!( | ||
| 13014 | - out.stdout.len(), | ||
| 13015 | - frame_len * frames, | ||
| 13016 | - "expected {frames} 4:2:0 frames" | ||
| 13017 | - ); | ||
| 13018 | - (0..frames) | ||
| 13019 | - .map(|i| { | ||
| 13020 | - let bytes = &out.stdout[i * frame_len..][..frame_len]; | ||
| 13021 | - Picture { | ||
| 13022 | - width, | ||
| 13023 | - height, | ||
| 13024 | - y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), | ||
| 13025 | - u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), | ||
| 13026 | - v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), | ||
| 13027 | - } | ||
| 13028 | - }) | ||
| 13029 | - .collect() | ||
| 13030 | } | 13004 | } |
| 13031 | 13005 | ||
| 13032 | /// The standing regression gate on real content: 12 frames of a real | 13006 | /// The standing regression gate on real content: 12 frames of a real |
| @@ -14507,15 +14481,7 @@ mod tests { | |||
| 14507 | 14481 | ||
| 14508 | /// The video stream's coded size, from ffprobe. | 14482 | /// The video stream's coded size, from ffprobe. |
| 14509 | fn probe_dims(clip: &str) -> Option<(usize, usize)> { | 14483 | fn probe_dims(clip: &str) -> Option<(usize, usize)> { |
| 14510 | - let out = Command::new("ffprobe") | 14484 | + crate::probe::dims(clip) |
| 14511 | - .args(["-v", "error", "-select_streams", "v:0"]) | ||
| 14512 | - .args(["-show_entries", "stream=width,height", "-of", "csv=p=0"]) | ||
| 14513 | - .arg(clip) | ||
| 14514 | - .output() | ||
| 14515 | - .ok()?; | ||
| 14516 | - let text = String::from_utf8_lossy(&out.stdout); | ||
| 14517 | - let mut f = text.trim().split(','); | ||
| 14518 | - Some((f.next()?.trim().parse().ok()?, f.next()?.trim().parse().ok()?)) | ||
| 14519 | } | 14485 | } |
| 14520 | 14486 | ||
| 14521 | /// The rows of [`bd_rate_screen_native`] -- (label, path, seek) -- shared | 14487 | /// The rows of [`bd_rate_screen_native`] -- (label, path, seek) -- shared |
| @@ -14777,24 +14743,16 @@ mod tests { | |||
| 14777 | println!("|---|---|---|---|---|"); | 14743 | println!("|---|---|---|---|---|"); |
| 14778 | for (name, path, seek) in &clips { | 14744 | for (name, path, seek) in &clips { |
| 14779 | let fctx = &crate::decode::FrameCtx::new(); | 14745 | let fctx = &crate::decode::FrameCtx::new(); |
| 14780 | - let Some((nw, nh)) = probe_dims(path) else { | 14746 | + if probe_dims(path).is_none() { |
| 14781 | eprintln!("SKIP {name}: ffprobe gave no size"); | 14747 | eprintln!("SKIP {name}: ffprobe gave no size"); |
| 14782 | continue; | 14748 | continue; |
| 14783 | - }; | 14749 | + } |
| 14784 | // A whole number of 128-wide superblocks, at most 1920x1024, out | 14750 | // A whole number of 128-wide superblocks, at most 1920x1024, out |
| 14785 | // of the middle of the frame; the offsets stay even for 4:2:0. | 14751 | // of the middle of the frame; the offsets stay even for 4:2:0. |
| 14786 | - let cw = nw.min(1920) / 128 * 128; | 14752 | + // ONE definition, shared with `examples/enc_probe` so the probe |
| 14787 | - let ch = nh.min(1024) / 128 * 128; | 14753 | + // cannot measure a different window than this gate (lane-probe). |
| 14788 | - assert!(cw >= 128 && ch >= 128, "{name}: {nw}x{nh} is smaller than a superblock"); | 14754 | + let (vf, cw, ch) = crate::probe::gate_crop(path); |
| 14789 | - let (x, y) = ((nw - cw) / 2 & !1, (nh - ch) / 2 & !1); | 14755 | + let source = clip_frames_vf(path, seek, &vf, cw, ch, frames); |
| 14790 | - let source = clip_frames_vf( | ||
| 14791 | - path, | ||
| 14792 | - seek, | ||
| 14793 | - &format!("crop={cw}:{ch}:{x}:{y}"), | ||
| 14794 | - cw, | ||
| 14795 | - ch, | ||
| 14796 | - frames, | ||
| 14797 | - ); | ||
| 14798 | SCREEN_FRAMES.iter().for_each(|c| { | 14756 | SCREEN_FRAMES.iter().for_each(|c| { |
| 14799 | c.store(0, std::sync::atomic::Ordering::Relaxed); | 14757 | c.store(0, std::sync::atomic::Ordering::Relaxed); |
| 14800 | }); | 14758 | }); |
| @@ -14951,4 +14909,92 @@ mod tests { | |||
| 14951 | ); | 14909 | ); |
| 14952 | } | 14910 | } |
| 14953 | } | 14911 | } |
| 14912 | + | ||
| 14913 | + /// The probe arms the gate's source (lane-probe, class `instrument | ||
| 14914 | + /// disagrees with the gate`). `examples/enc_probe` built its own ffmpeg | ||
| 14915 | + /// command line and had no `-ss`, so it read film B from frame 0 -- a | ||
| 14916 | + /// black leader -- and coded 59 kB where the gate's own ladder point | ||
| 14917 | + /// coded 89 kB of the same title; every census taken through it was | ||
| 14918 | + /// probe-relative. Both now call [`crate::probe::source`]; this pins that | ||
| 14919 | + /// the shared loader honours the seek (arming the probe's way and the | ||
| 14920 | + /// gate's way gives byte-identical streams, and dropping the seek does | ||
| 14921 | + /// not), on a synthetic clip whose content moves over time. | ||
| 14922 | + #[test] | ||
| 14923 | + fn the_probe_arms_the_gates_source() { | ||
| 14924 | + let _knobs = crate::speed::knob_write(); | ||
| 14925 | + if !have_ffmpeg() { | ||
| 14926 | + eprintln!("SKIP the_probe_arms_the_gates_source: no ffmpeg"); | ||
| 14927 | + return; | ||
| 14928 | + } | ||
| 14929 | + let dir = std::env::temp_dir().join(format!("ec-av1-probe-{}", std::process::id())); | ||
| 14930 | + std::fs::create_dir_all(&dir).unwrap(); | ||
| 14931 | + let clip = dir.join("testsrc2.y4m"); | ||
| 14932 | + // 384x202: neither side is a multiple of 128, so the gate's centre | ||
| 14933 | + // window is a real derivation and not the frame itself -- exactly the | ||
| 14934 | + // shape film B has (3840x1608, never 3840x2160). | ||
| 14935 | + let ok = Command::new("ffmpeg") | ||
| 14936 | + .args(["-v", "error", "-y", "-f", "lavfi", "-i", "testsrc2=size=384x202:rate=10"]) | ||
| 14937 | + .args(["-frames:v", "20", "-pix_fmt", "yuv420p"]) | ||
| 14938 | + .arg(&clip) | ||
| 14939 | + .status() | ||
| 14940 | + .expect("ffmpeg failed to run") | ||
| 14941 | + .success(); | ||
| 14942 | + assert!(ok, "ffmpeg could not write the synthetic clip"); | ||
| 14943 | + let path = clip.to_str().unwrap(); | ||
| 14944 | + | ||
| 14945 | + // The window: superblock-aligned, centred, even offsets. | ||
| 14946 | + let (vf, w, h) = crate::probe::gate_crop(path); | ||
| 14947 | + assert_eq!((vf.as_str(), w, h), ("crop=384:128:0:36", 384, 128)); | ||
| 14948 | + | ||
| 14949 | + let (seek, q) = ("00:00:01", 150u8); | ||
| 14950 | + let gate = clip_frames_vf(path, seek, &vf, w, h, 6); | ||
| 14951 | + let probe = crate::probe::source(path, seek, &vf, w, h, 6); | ||
| 14952 | + assert!( | ||
| 14953 | + gate.iter().zip(&probe).all(|(a, b)| a.y == b.y && a.u == b.u && a.v == b.v), | ||
| 14954 | + "the probe's source differs from the gate's at the same window" | ||
| 14955 | + ); | ||
| 14956 | + let bytes = |src: &[Picture]| { | ||
| 14957 | + encode_sequence_with_ctx(src, q, 0.5, &crate::decode::FrameCtx::new()) | ||
| 14958 | + .unwrap() | ||
| 14959 | + .stream | ||
| 14960 | + }; | ||
| 14961 | + assert_eq!(bytes(&gate), bytes(&probe), "probe and gate code different bytes"); | ||
| 14962 | + // The two witnesses that both halves of the arming reach ffmpeg: the | ||
| 14963 | + // seek, and the crop's own offset (the film-B defect in miniature -- | ||
| 14964 | + // the probe was reading `crop=..:568` of a 1608-high frame). | ||
| 14965 | + let unseeked = crate::probe::source(path, "0", &vf, w, h, 6); | ||
| 14966 | + assert_ne!( | ||
| 14967 | + bytes(&gate), | ||
| 14968 | + bytes(&unseeked), | ||
| 14969 | + "seeked and unseeked arming coded the same bytes -- the seek is inert" | ||
| 14970 | + ); | ||
| 14971 | + let offset = crate::probe::source(path, seek, "crop=384:128:0:0", w, h, 6); | ||
| 14972 | + assert_ne!( | ||
| 14973 | + bytes(&gate), | ||
| 14974 | + bytes(&offset), | ||
| 14975 | + "centred and top-aligned windows coded the same bytes -- the crop is inert" | ||
| 14976 | + ); | ||
| 14977 | + std::fs::remove_dir_all(&dir).ok(); | ||
| 14978 | + } | ||
| 14979 | + | ||
| 14980 | + /// lane-probe diagnostic: the gate's own loader + ladder call for ONE | ||
| 14981 | + /// point inside the test binary, to compare against `examples/enc_probe`. | ||
| 14982 | + #[test] | ||
| 14983 | + #[ignore = "diagnostic: needs ffmpeg and a clip"] | ||
| 14984 | + fn probe_parity_point() { | ||
| 14985 | + let _knobs = crate::speed::knob_write(); | ||
| 14986 | + let g = |k: &str| std::env::var(k).unwrap(); | ||
| 14987 | + let (w, h) = g("EC_PARITY_DIMS").split_once(':').map(|(a, b)| (a.parse::<usize>().unwrap(), b.parse::<usize>().unwrap())).unwrap(); | ||
| 14988 | + let frames: usize = g("EC_PARITY_FRAMES").parse().unwrap(); | ||
| 14989 | + let q: u8 = g("EC_PARITY_Q").parse().unwrap(); | ||
| 14990 | + let source = clip_frames_vf(&g("EC_PARITY_CLIP"), &g("EC_PARITY_SS"), &g("EC_PARITY_VF"), w, h, frames); | ||
| 14991 | + let fctx = &crate::decode::FrameCtx::new(); | ||
| 14992 | + let e = encode_sequence_with_ctx(&source, q, 0.5, fctx).unwrap(); | ||
| 14993 | + let mut hash: u64 = 0xcbf2_9ce4_8422_2325; | ||
| 14994 | + for &b in &e.stream { | ||
| 14995 | + hash = (hash ^ u64::from(b)).wrapping_mul(0x0000_0100_0000_01b3); | ||
| 14996 | + } | ||
| 14997 | + eprintln!("PARITY q={q} bytes={} fnv1a={hash:016x} speed={} pyramid {:?} effective {:?}", | ||
| 14998 | + e.stream.len(), crate::speed::speed(), crate::encoder::Pyramid::from_env(), last_sequence_pyramid()); | ||
| 14999 | + } | ||
| 14954 | } | 15000 | } |
crates/ec-av1/src/lib.rsmodified+1 -0
| @@ -45,6 +45,7 @@ pub mod msac; | |||
| 45 | pub mod mvstack; | 45 | pub mod mvstack; |
| 46 | pub mod obu; | 46 | pub mod obu; |
| 47 | mod par; | 47 | mod par; |
| 48 | +pub mod probe; | ||
| 48 | pub mod quant; | 49 | pub mod quant; |
| 49 | mod refusal_inventory; | 50 | mod refusal_inventory; |
| 50 | pub mod speed; | 51 | pub mod speed; |
crates/ec-av1/src/probe.rsadded+86 -0
| @@ -0,0 +1,86 @@ | |||
| 1 | +//! The BD gate's source arming, shared with `examples/enc_probe` (lane-probe). | ||
| 2 | +//! | ||
| 3 | +//! The probe used to build its own ffmpeg command line and dropped the gate's | ||
| 4 | +//! `-ss` seek, so it read film B's black leader and every census taken through | ||
| 5 | +//! it was probe-relative (59 kB where the gate's own ladder point coded 89 kB | ||
| 6 | +//! of the same title). One definition now serves both: the gate's | ||
| 7 | +//! `clip_frames_vf` and the probe both call [`source`], so the two can only | ||
| 8 | +//! differ in the arguments they pass, which | ||
| 9 | +//! `encode::tests::the_probe_arms_the_gates_source` pins. | ||
| 10 | + | ||
| 11 | +use crate::encode::Picture; | ||
| 12 | +use std::process::Command; | ||
| 13 | + | ||
| 14 | +/// The video stream's coded size, from ffprobe. | ||
| 15 | +#[must_use] | ||
| 16 | +pub fn dims(clip: &str) -> Option<(usize, usize)> { | ||
| 17 | + let out = Command::new("ffprobe") | ||
| 18 | + .args(["-v", "error", "-select_streams", "v:0"]) | ||
| 19 | + .args(["-show_entries", "stream=width,height", "-of", "csv=p=0"]) | ||
| 20 | + .arg(clip) | ||
| 21 | + .output() | ||
| 22 | + .ok()?; | ||
| 23 | + let text = String::from_utf8_lossy(&out.stdout); | ||
| 24 | + let mut f = text.trim().split(','); | ||
| 25 | + Some((f.next()?.trim().parse().ok()?, f.next()?.trim().parse().ok()?)) | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +/// The native BD gate's window on `clip`: a whole number of 128-wide | ||
| 29 | +/// superblocks, at most 1920x1024, out of the MIDDLE of the coded frame, with | ||
| 30 | +/// even offsets for 4:2:0 -- as an ffmpeg `crop` filter plus its size. | ||
| 31 | +/// | ||
| 32 | +/// This lives here because the probe used to be handed the crop by hand, and | ||
| 33 | +/// a hand-written `crop=1920:1024:960:568` (a 2160-high frame that film B, | ||
| 34 | +/// coded 3840x1608, is not) put the instrument on different pixels than the | ||
| 35 | +/// gate: 60 kB where the gate's own q=150 point coded 90 kB. | ||
| 36 | +/// | ||
| 37 | +/// # Panics | ||
| 38 | +/// When ffprobe cannot read the size, or the frame is under one superblock. | ||
| 39 | +#[must_use] | ||
| 40 | +pub fn gate_crop(clip: &str) -> (String, usize, usize) { | ||
| 41 | + let (nw, nh) = dims(clip).expect("ffprobe gave no size"); | ||
| 42 | + let cw = nw.min(1920) / 128 * 128; | ||
| 43 | + let ch = nh.min(1024) / 128 * 128; | ||
| 44 | + assert!(cw >= 128 && ch >= 128, "{nw}x{nh} is smaller than a superblock"); | ||
| 45 | + let (x, y) = ((nw - cw) / 2 & !1, (nh - ch) / 2 & !1); | ||
| 46 | + (format!("crop={cw}:{ch}:{x}:{y}"), cw, ch) | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +/// `frames` pictures of `clip` from `skip` through the filter chain `vf`, as | ||
| 50 | +/// planar 8-bit 4:2:0 at `width`x`height` -- the BD gate's loader recipe. | ||
| 51 | +/// | ||
| 52 | +/// # Panics | ||
| 53 | +/// When ffmpeg cannot be run, fails, or delivers a different number of frames. | ||
| 54 | +#[must_use] | ||
| 55 | +pub fn source( | ||
| 56 | + clip: &str, | ||
| 57 | + skip: &str, | ||
| 58 | + vf: &str, | ||
| 59 | + width: usize, | ||
| 60 | + height: usize, | ||
| 61 | + frames: usize, | ||
| 62 | +) -> Vec<Picture> { | ||
| 63 | + let out = Command::new("ffmpeg") | ||
| 64 | + .args(["-v", "error", "-ss", skip, "-i", clip]) | ||
| 65 | + .args(["-frames:v", &frames.to_string()]) | ||
| 66 | + .args(["-vf", vf]) | ||
| 67 | + .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]) | ||
| 68 | + .output() | ||
| 69 | + .expect("ffmpeg failed to run"); | ||
| 70 | + assert!(out.status.success(), "ffmpeg: {}", String::from_utf8_lossy(&out.stderr)); | ||
| 71 | + let (luma, chroma) = (width * height, width * height / 4); | ||
| 72 | + let frame_len = luma + 2 * chroma; | ||
| 73 | + assert_eq!(out.stdout.len(), frame_len * frames, "expected {frames} 4:2:0 frames"); | ||
| 74 | + (0..frames) | ||
| 75 | + .map(|i| { | ||
| 76 | + let b = &out.stdout[i * frame_len..][..frame_len]; | ||
| 77 | + Picture { | ||
| 78 | + width, | ||
| 79 | + height, | ||
| 80 | + y: b[..luma].iter().map(|&v| u16::from(v)).collect(), | ||
| 81 | + u: b[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), | ||
| 82 | + v: b[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), | ||
| 83 | + } | ||
| 84 | + }) | ||
| 85 | + .collect() | ||
| 86 | +} | ||
lanes/census-longgop-v2.mdadded+56 -0
| @@ -0,0 +1,56 @@ | |||
| 1 | +# Long-GOP census v2 — film B, 48 frames, q=150 (lane-probe) | ||
| 2 | + | ||
| 3 | +The v1 census (and every "probe-relative" number quoted from it) measured the | ||
| 4 | +WRONG PIXELS. `examples/enc_probe` was handed its window by hand as | ||
| 5 | +`crop=1920:1024:960:568`, i.e. the centre of a 3840x**2160** frame — film B is | ||
| 6 | +coded **3840x1608**, so the gate's own window is `crop=1920:1024:960:292`. Same | ||
| 7 | +q, same source file, different picture: 60466 B (v1) vs **90674 B** (v2). | ||
| 8 | + | ||
| 9 | +Arming, now derived by one shared function (`ec_av1::probe::gate_crop`, called | ||
| 10 | +by both the probe and `encode::tests::native_bd_arm`): | ||
| 11 | + | ||
| 12 | + EC_ENC_SS=00:40:00 EC_ENC_OUT=<dir> EC_AV1_BITCENSUS=1 \ | ||
| 13 | + enc_probe <film B> gate 0 48 150 # -> 90674 bytes | ||
| 14 | + EC_AV1_BITCENSUS=1 syntax_census <dir>/ours-q150.obu <dir>/source.yuv | ||
| 15 | + | ||
| 16 | +90674 B is **byte-exact with `encode::tests::bd_rate_film_long_gop`'s own | ||
| 17 | +q=150 ladder point** (gate row: `46.76 dB/90674 B`). Every number below is | ||
| 18 | +therefore the gate's stream. | ||
| 19 | + | ||
| 20 | +Pyramid: default `mini_gop 8, arf -32, leaf +12, mid -8, key -48` (requested = | ||
| 21 | +effective; the content gate leaves this clip on the pyramid). 48 pictures = | ||
| 22 | +1 key + 6 ARF + 6 mid + 35 leaf. | ||
| 23 | + | ||
| 24 | +## Per level (payload bytes as the decoder censuses them; 89514 B of the | ||
| 25 | +## 90674 B stream, the rest is sequence/frame OBU overhead) | ||
| 26 | + | ||
| 27 | +| level | frames | qindex | bytes | share | bytes/frame | PSNR-Y (display) | | ||
| 28 | +|---|---|---|---|---|---|---| | ||
| 29 | +| key | 1 | 102 | 19321 | 21.6% | 19321 | 47.67 dB | | ||
| 30 | +| ARF | 6 | 118 | 48126 | 53.8% | 8021 | 46.01 dB | | ||
| 31 | +| mid | 6 | 142 | 10331 | 11.5% | 1722 | 45.79 dB | | ||
| 32 | +| leaf | 35 | 162 | 11736 | 13.1% | 335 | 45.27 dB | | ||
| 33 | +| ALL | 48 | - | 89514 | 100% | 1865 | 45.47 dB | | ||
| 34 | + | ||
| 35 | +Where the bits go (census bits, per level): | ||
| 36 | + | ||
| 37 | +| level | coeff | literal | mode | mv | partition | tx size/type | | ||
| 38 | +|---|---|---|---|---|---|---| | ||
| 39 | +| key | 66.6% | 22.0% | 9.4% | – | 0.8% | 1.3% | | ||
| 40 | +| ALL | 53.6% | 17.1% | 17.6% | 8.0% | 2.9% | 0.7% | | ||
| 41 | + | ||
| 42 | +Structure: ALL = intra 3.0% / single-ref 93.0% / compound 4.0% area, skip | ||
| 43 | +85.7%; refs LAST 95.9%, GOLDEN 0.8%, ALTREF 0.3%; blocks 64x64 54.3%, 32x32 | ||
| 44 | +26.3%, 16x16 14.7%, 8x8 4.8%. The ARF level carries the group (53.8% of the | ||
| 45 | +bytes on 12.5% of the frames, skip 66.4%); the leaf level is 94.8% skip area | ||
| 46 | +and 335 B a picture. | ||
| 47 | + | ||
| 48 | +## For the allocation lanes | ||
| 49 | + | ||
| 50 | +- Quote THIS table, not v1: the level shares moved (ARF 49.3% -> 53.8%, key | ||
| 51 | + 25.6% -> 21.6%) because the v1 window was a different, flatter part of the | ||
| 52 | + frame. | ||
| 53 | +- Any probe run on a real film must pass `gate` as the width argument and set | ||
| 54 | + `EC_ENC_SS` to the gate's pinned seek (film A `00:35:00`, film B `00:40:00`); | ||
| 55 | + a hand-written `crop=` is how v1 went wrong. | ||
| 56 | +- Regression cover: `encode::tests::the_probe_arms_the_gates_source`. | ||