forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-av1native' (288a7963): a native-resolution BD arm (bd_rate_screen_native, 1920x1024 crop, no downscale)

Browse files at this commit

4a3f924f3af5bfed401b892e17da0e06906759d2Ahmet Kaan GümüşParent: 107329ccd2c183
At native the screen capture is +59.3 vs libaom and -10.0 vs rav1e, the
1080p film crop +18.9 / +1.5: the 640x384 recipe measures content 4x
further from libaom than the real files. No default moved; intrabc loses
at native too (11499 RD wins cannot pay the key frame's filter loss).
crates/ec-av1/src/encode.rsmodified+183 -1
@@ -9717,11 +9717,26 @@ mod tests {
97179717 width: usize,
97189718 height: usize,
97199719 frames: usize,
9720+ ) -> Vec<Picture> {
9721+ clip_frames_vf(clip, skip, &format!("scale={width}:{height}"), width, height, frames)
9722+ }
9723+
9724+ /// [`clip_frames`] with the filter chain spelled out, so a caller can ask
9725+ /// for a native-resolution CROP instead of a downscale (the downscale is
9726+ /// what destroys a screen capture's exact repeats -- class
9727+ /// `gate-recipe-confound`). `width`/`height` must be what `vf` produces.
9728+ fn clip_frames_vf(
9729+ clip: &str,
9730+ skip: &str,
9731+ vf: &str,
9732+ width: usize,
9733+ height: usize,
9734+ frames: usize,
97209735 ) -> Vec<Picture> {
97219736 let out = Command::new("ffmpeg")
97229737 .args(["-v", "error", "-ss", skip, "-i", clip])
97239738 .args(["-frames:v", &frames.to_string()])
9724- .args(["-vf", &format!("scale={width}:{height}")])
9739+ .args(["-vf", vf])
97259740 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"])
97269741 .output()
97279742 .expect("ffmpeg failed to run");
@@ -10713,4 +10728,171 @@ mod tests {
1071310728 );
1071410729 }
1071510730 }
10731+ /// The video stream's coded size, from ffprobe.
10732+ fn probe_dims(clip: &str) -> Option<(usize, usize)> {
10733+ let out = Command::new("ffprobe")
10734+ .args(["-v", "error", "-select_streams", "v:0"])
10735+ .args(["-show_entries", "stream=width,height", "-of", "csv=p=0"])
10736+ .arg(clip)
10737+ .output()
10738+ .ok()?;
10739+ let text = String::from_utf8_lossy(&out.stdout);
10740+ let mut f = text.trim().split(',');
10741+ Some((f.next()?.trim().parse().ok()?, f.next()?.trim().parse().ok()?))
10742+ }
10743+
10744+ /// The NATIVE-resolution screen arm of the BD gate. The default gate
10745+ /// downscales the OBS capture to 640x384, which destroys exactly the
10746+ /// pixel-identical 16x16 repeats intrabc and (part of) the palette exist
10747+ /// for (class `gate-recipe-confound`), so every screen-tool decision taken
10748+ /// on that recipe is taken on content the tool cannot serve. This arm
10749+ /// crops -- never scales -- a superblock-aligned window out of the middle
10750+ /// of the capture at its own resolution (at most 1920x1024, so the wall
10751+ /// stays in the minutes) and runs the same 12-frame, four-quantizer
10752+ /// ladder against libaom `cpu-used 6` and rav1e `speed=6`, one tile, one
10753+ /// thread, with the same three-way (encoder / ffmpeg / our decoder)
10754+ /// sample-exactness assertion `our_ladder` makes.
10755+ ///
10756+ /// It is its own `--ignored` test so the default gate's wall does not
10757+ /// grow. Every variant is an environment knob, and each of those is a
10758+ /// `OnceLock` read once per process, so a variant is a separate run:
10759+ ///
10760+ /// cargo test -p ec-av1 --release --lib -- --ignored \
10761+ /// bd_rate_screen_native --nocapture # baseline
10762+ /// EC_AV1_INTRABC=1 ... same command # intra block copy
10763+ /// EC_AV1_PAL_MAXCOLORS=256 ... same command # palette bound
10764+ /// EC_AV1_TILES=1:1 EC_AV1_TILE_THREADS=4 ... # 2x2 tiles
10765+ /// EC_AV1_NATIVE_FILM=1 ... same command # + a film crop row
10766+ #[test]
10767+ #[ignore = "the native-resolution screen BD arm: minutes per row, needs ffmpeg"]
10768+ fn bd_rate_screen_native() {
10769+ if !have_ffmpeg() {
10770+ eprintln!("SKIP bd_rate_screen_native: no ffmpeg");
10771+ return;
10772+ }
10773+ let fixtures = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures");
10774+ let mut clips: Vec<(String, String)> = Vec::new();
10775+ match std::fs::read_to_string(fixtures.join("real-library-manifest.tsv")) {
10776+ Ok(manifest) => match manifest
10777+ .lines()
10778+ .skip(1)
10779+ .filter_map(|l| l.split('\t').next())
10780+ .find(|p| p.contains("/OBS/") && p.ends_with(".mkv") && std::path::Path::new(p).exists())
10781+ {
10782+ Some(p) => clips.push((
10783+ format!("screen capture ({})", p.rsplit('/').next().unwrap_or(p)),
10784+ p.to_string(),
10785+ )),
10786+ None => eprintln!("SKIP screen capture: no OBS recording in the manifest exists"),
10787+ },
10788+ Err(e) => eprintln!("SKIP bd_rate_screen_native: no real-library manifest ({e})"),
10789+ }
10790+ // The film crop is an extra row, not a default-moving measurement.
10791+ if std::env::var("EC_AV1_NATIVE_FILM").ok().as_deref() == Some("1") {
10792+ let path = fixtures.join("video").join("h264-1080p-23.976-8bit.mp4");
10793+ if path.exists() {
10794+ clips.push((
10795+ "film 1080p (native crop)".to_string(),
10796+ path.to_str().unwrap().to_string(),
10797+ ));
10798+ }
10799+ }
10800+ if clips.is_empty() {
10801+ eprintln!("SKIP bd_rate_screen_native: no clip");
10802+ return;
10803+ }
10804+
10805+ let frames = 12usize;
10806+ let aom_points: Vec<Vec<String>> = [5, 20, 35, 45]
10807+ .iter()
10808+ .map(|q| {
10809+ ["-cpu-used", "6", "-b:v", "0", "-crf", &q.to_string()]
10810+ .map(String::from)
10811+ .to_vec()
10812+ })
10813+ .collect();
10814+ let rav1e_points: Vec<Vec<String>> = [50, 100, 150, 200]
10815+ .iter()
10816+ .map(|q| {
10817+ vec![
10818+ "-rav1e-params".to_string(),
10819+ format!("speed=6:quantizer={q}:tile_cols=1:tile_rows=1:threads=1"),
10820+ ]
10821+ })
10822+ .collect();
10823+ println!(
10824+ "\nnative crop, {frames} frames, gop={frames}; tiles {:?}, tile threads {}, \
10825+ intrabc {}, palette maxcolors {}",
10826+ armed_tiles(),
10827+ crate::par::tile_threads(),
10828+ intrabc_enabled(),
10829+ palette_max_colors(),
10830+ );
10831+ println!("| clip | size | ours PSNR/bytes per point | BD-rate vs libaom | BD-rate vs rav1e | wall ours:libaom:rav1e |");
10832+ println!("|---|---|---|---|---|---|");
10833+ for (name, path) in &clips {
10834+ let fctx = &crate::decode::FrameCtx::new();
10835+ let Some((nw, nh)) = probe_dims(path) else {
10836+ eprintln!("SKIP {name}: ffprobe gave no size");
10837+ continue;
10838+ };
10839+ // A whole number of 128-wide superblocks, at most 1920x1024, out
10840+ // of the middle of the frame; the offsets stay even for 4:2:0.
10841+ let cw = nw.min(1920) / 128 * 128;
10842+ let ch = nh.min(1024) / 128 * 128;
10843+ assert!(cw >= 128 && ch >= 128, "{name}: {nw}x{nh} is smaller than a superblock");
10844+ let (x, y) = ((nw - cw) / 2 & !1, (nh - ch) / 2 & !1);
10845+ let source = clip_frames_vf(
10846+ path,
10847+ "0",
10848+ &format!("crop={cw}:{ch}:{x}:{y}"),
10849+ cw,
10850+ ch,
10851+ frames,
10852+ );
10853+ SCREEN_FRAMES.iter().for_each(|c| {
10854+ c.store(0, std::sync::atomic::Ordering::Relaxed);
10855+ });
10856+ let _ = crate::tile::take_palette_hits();
10857+ let _ = crate::tile::take_palette_uv_hits();
10858+ let _ = crate::tile::take_intrabc_hits();
10859+ let _ = take_intrabc_search();
10860+ let (ours, ours_wall) = our_ladder(name, &source, cw, ch, fctx);
10861+ // gate-blind-to-feature: what the screen tools actually did at
10862+ // native resolution, over this clip's four encodes.
10863+ let screen_on = SCREEN_FRAMES[1].load(std::sync::atomic::Ordering::Relaxed);
10864+ let screen_off = SCREEN_FRAMES[0].load(std::sync::atomic::Ordering::Relaxed);
10865+ let palette = crate::tile::take_palette_hits();
10866+ let palette_uv = crate::tile::take_palette_uv_hits();
10867+ let ibc = crate::tile::take_intrabc_hits();
10868+ let search = take_intrabc_search();
10869+ eprintln!(
10870+ "{name}: screen frames on={screen_on} off={screen_off} ({:.1}% on); \
10871+ palette blocks luma {} chroma {}; intrabc blocks {} (searched {} / valid {} / \
10872+ won {})",
10873+ 100.0 * screen_on as f64 / (screen_on + screen_off).max(1) as f64,
10874+ palette[0],
10875+ palette_uv[0],
10876+ ibc[0],
10877+ search[0],
10878+ search[1],
10879+ search[2],
10880+ );
10881+ let (aom, aom_wall) = external_ladder(&source, cw, ch, "libaom-av1", &aom_points);
10882+ let (rav1e, rav1e_wall) = external_ladder(&source, cw, ch, "librav1e", &rav1e_points);
10883+ assert_monotone(&format!("{name}: ours"), &ours);
10884+ assert_monotone(&format!("{name}: libaom"), &aom);
10885+ assert_monotone(&format!("{name}: rav1e"), &rav1e);
10886+ let points = ours
10887+ .iter()
10888+ .map(|(p, b)| format!("{p:.2} dB/{:.0} B", 10f64.powf(*b)))
10889+ .collect::<Vec<_>>()
10890+ .join(", ");
10891+ println!(
10892+ "| {name} | {cw}x{ch} | {points} | {:+.1}% | {:+.1}% | {ours_wall:.1}s:{aom_wall:.1}s:{rav1e_wall:.1}s |",
10893+ bd_rate(&aom, &ours) * 100.0,
10894+ bd_rate(&rav1e, &ours) * 100.0,
10895+ );
10896+ }
10897+ }
1071610898 }