forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB84fa44cTahinli2 months ago3331 commits

vp9refsetup.report.md15.4 KiBHistoryRawDownload

lane-vp9-refsetup — intra-only frames + scaled references

Branch lane-vp9-refsetup, off main 79984549. Two named refusals removed:

  1. vp9 intra-only — an INTER frame with intra_only = 1, show_frame = 0 (decode.rs:233, :320).
  2. vp9 inter reference size change — an inter frame whose reference slot holds a picture of a different coded size (decode.rs:372).

Acceptance bar: byte-exact vs libvpx 1.15 (the frozen oracle drivers $HOME/.cache/vp9pix/drv_pix3, drv_err, statically linked to the 1.15 build) on real streams, plus the full 8-bit regression corpus unchanged.

What changed

path why
crates/ec-vp9/src/decode.rs decode_one / decode_syntax intra-only routes to the new decode_intra_only_frame instead of refusing
crates/ec-vp9/src/decode.rs decode_intra_only_frame new: keyframe body, storage-loaded frame context (reset only for reset_frame_context 2/3 / error-resilient), refresh_frame_flags-scoped reference refresh
crates/ec-vp9/src/decode.rs decode_block intra dispatch keys on frame_is_intra_only (keyframe OR intra-only), not frame_type == Key
crates/ec-vp9/src/decode.rs decode_inter_frame size-change refusal removed; slot-existence checks kept
crates/ec-vp9/src/decode.rs inter_predict_plane ScaleFactors::setup per reference (valid_ref_frame_size -> vp9 reference scale refusal where libvpx errors)
crates/ec-vp9/src/mc.rs ScaleFactors (vp9_setup_scale_factors_for_frame, vp9_scale_mv), step-aware convolve_horiz/convolve_vert, sf->predict kernel selection, scaled block/MV mapping in build_inter_predictors
crates/ec-vp9/src/header.rs FrameContext::use_key_partition (set_partition_probs)
crates/ec-vp9/tests/{intraonly,scaledref}_exact.rs + tests/data/*.ivf regression witnesses

Semantics ported (bug-for-bug, libvpx 1.15.0)

  • vp9_setup_past_independence (vp9/common/vp9_entropymode.c:424) is called for intra-only frames, but cm->frame_type != KEY_FRAME, so the stored contexts are reset only for reset_frame_context 2 (selected) / 3 (all) or error-resilient mode. The ACTIVE context is then *cm->fc = cm->frame_contexts[frame_context_idx] (vp9_decodeframe.c:3008) — storage, not the defaults.
  • Partitions for intra-only (and key) frames come from the const vp9_kf_partition_probs (set_partition_probs, onyxc_int.h:367), which is NOT a FRAME_CONTEXT field: the stored context's partition survives the frame untouched (restored before storing).
  • Reference refresh is refresh_frame_flags-scoped; show_frame stays 0 (an intra-only frame is never displayable — the parser only reads intra_only when show_frame == 0).
  • Scaling: x_scale_fp = (other << 14) / this, x_step_q4 = scaled_x(16); the block maps with scale_value_x/y, the MV with vp9_scale_mv (vp9_scale.c:29), and sf->predict[subpel_x != 0][subpel_y != 0] picks the kernel (vpx_scaled_horiz/vert/2d == the step-aware convolve helpers). The tap-padding branch is subpel || step != 16; the direct read keeps the pre-padding coordinates.

Fixtures and generators (reproducibility)

None of these can be produced by an ffmpeg invocation:

  • intra-only: libvpx's encoder emits intra-only frames only through its SVC path (set_intra_only_frame, vp9_ratectrl.c:2211), which ffmpeg does not expose. Generated by lanes/vp9refsetup/gen_intraonly.py from a plain ffmpeg keyframe GOP:
    ffmpeg -v error -y -f lavfi -i testsrc2=size=320x240:rate=24:duration=0.4 \
      -c:v libvpx-vp9 -g 999 -auto-alt-ref 0 -crf 32 -deadline good -cpu-used 4 \
      -pix_fmt yuv420p -f ivf S.ivf
    python3 lanes/vp9refsetup/gen_intraonly.py S.ivf intraonly.ivf
    
    The generator reproduces the committed tests/data/intraonly.ivf byte for byte (cmp verified). 11 frames: keyframe, hidden intra-only twin, 9 inter.
  • size change: libvpx's encoder resizes only through rate control (vp9_resize_one_pass_cbr, vp9_ratectrl.c:2728); ffmpeg exposes neither rc_resize_allowed nor SVC, and ffmpeg's rawvideo output size is locked to the first decoded frame (see the oracle caveat), so a two-size stream cannot be dumped in one pass. Generated by lanes/vp9refsetup/gen_scaledref.c (links the pristine libvpx 1.15.0 encoder):
    gcc -I<libvpx> -I<libvpx>/vpx gen_scaledref.c <libvpx>/libvpx.a -o enc -lm -lpthread
    ./enc scaledref.ivf 1280 720 10 200      # one-pass CBR, 200 kbps, lag 0
    
    libvpx's force-downsize rule (>= 1280x720 input and avg_frame_bandwidth < 300000/30) downscales frame 1 to 640x360 against the 1280x720 keyframe — a genuine 2x reference scale (x_step_q4 == 32).
  • odd variant: scaledref_odd.ivf is scaledref.ivf with the keyframe's size fields patched 1280x720 -> 1279x719 (mi-grid invariant, so the tile data stays valid) — the reference is then an odd coded extent and its chroma crop ceils. Patch with the existing $HOME/.cache/vp9pix/patch_kf_size.py <in> <out> 1279 719, which rewrites the IVF container size as well (sha256 af289a0f8dd91bfa854adeac1814dc77644ad87b9df0af884d33abaae2595413).

Gates

CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9ref

  1. Suite: cargo test -p ec-vp9 — every binary green, 0 failed, 0 ignored. Warning parity: exactly the 5 pre-existing (TM_PRED, read_partition, partition_probs, x_mis, y_mis).
  2. New witnesses (byte-exact vs ffmpeg's libvpx-backed rawvideo):
    • intra_only_frame_and_its_successors_match_ffmpeg — 10/10 shown frames identical; the fixture is asserted to carry exactly one intra-only frame.
    • size_changing_reference_decodes_byte_exact — 10/10 identical.
    • size_changing_odd_reference_decodes_byte_exact — 10/10 identical.
  3. Crate-level oracle (my dump vs libvpx's drv_pix3, per-shown-frame native dims + ceil chroma, compared with cmp): scaledref.ivf IDENTICAL (4,492,800 bytes, 10 frames); scaledref_odd.ivf IDENTICAL (4,490,801 bytes, 10 frames); intraonly.ivf IDENTICAL via drv_pix (all 10 output frames match the source GOP's, i.e. the intra-only frame reconstructs exactly like the keyframe it replaced).
  4. Fail-pre-fix (throwaway base worktree at 79984549, tests+fixtures copied in, private target dir):
    • intra-only: Unsupported { what: "vp9 intra-only", why: "this lane decodes inter frames and keyframes only" } at intraonly_exact.rs:72.
    • scaled: Unsupported { what: "vp9 inter reference size change", why: "reference last in slot 0 is 1280x720 but this frame is 640x360; reference-frame scaling is not ported" } (and the 1279x719 twin) at scaledref_exact.rs:107.
  5. Regression corpus ($HOME/.cache/vp9ref-sweep.sh = drv_pix3 vs scratch_pixdump, byte cmp) — all IDENTICAL:
stream oracle frames bytes
vp9-1080p-23.976-8bit.ivf 48 149,299,200
vp9-1080p-60-8bit.ivf (120 frames, the frame-72 witness) 120 373,248,000
vp9-2160p-23.976-8bit.ivf 48 597,196,800
vp9-tiles-1280.ivf 30 41,472,000
vp9-superframe-altref.ivf 60 6,912,000
$HOME/.cache/vp9pix/inter.ivf 3 9,331,200
$HOME/.cache/vp9pix/inter1.ivf 3 9,331,200
odd testsrc2 321x241 (322x242 encode + patch_kf_size.py) 12 1,395,876
  1. Interaction (size change x odd dims): scaledref_odd.ivf covers it — the scaled reference is an odd extent (1279x719, chroma (w+1)/2) and the result is byte-identical to libvpx. Not deferred.

Oracle caveat (why the committed tests skip frame 1)

ffmpeg locks its rawvideo output size to the FIRST decoded frame's, so a two-size stream cannot be dumped in one pass: frames 1..N come out upscaled to 1280x720. The tests decode frame 0 alone (-frames:v 1, identity) and frames 2..N with select=gte(n,1) at the small size, where the filtergraph has re-initialised and every frame passes through unchanged. The size-change frame (file frame 1) is the one ffmpeg mangles during that re-initialisation, so it is covered INDIRECTLY: every later frame predicts from its reconstruction (a wrong scaler fails frames 2..N). Frame 1 itself is covered directly by the crate-level drv_pix3 comparison in gate 3.

Deferred / accepted

  • accepted: profile 2 / 4:4:4 still refused by name (decode.rs:211/217, and vp9 reference scale for a colour-format mismatch) — out of scope, owned by the sibling lane.
  • accepted: vp9 reference scale (the valid_ref_frame_size ratio bound) stays a named refusal; libvpx errors the same way (Reference frame has invalid dimensions). Reaching it needs an adversarial 2x+ ratio that no encoder emits.
  • noted, not touched: the existing inter path resets stored frame contexts for reset_frame_context 2/3 even though libvpx only does that via vp9_setup_past_independence (i.e. only for intra-only / error-resilient frames). Pre-existing, unreachable on the corpus (which codes reset = 0), and outside this lane's scope.
  • noted: scratch_pixdump/drv_pix3 are per-inter_pixdump-style scratch harnesses; the new drv_pix3 (per-frame native dims) lives only in $HOME/.cache/vp9pix.

Test scope actually run

  • cargo test -p ec-vp9 (whole crate) — green, 0 failed, 5 warnings.
  • cargo test -p ec-vp9 --test intraonly_exact --test scaledref_exact — 3 passed.
  • corpus sweep above — 8 streams IDENTICAL.
  • base-worktree fail-pre-fix — 3 failures with the named refusals.

MERGE-SIDE FOLLOW-UPS (2026-09-19)

  • Doc nit dropped on the lane before the merge (commit 2129be51): the "scale=...:eval=frame exits 139 with a 0-byte file (ffmpeg 8.1.2)" sentence is gone from this report and from scaledref_exact.rs. The reviewer cannot reproduce the exit-139 shape; the builder can — environment-dependent, so it is not load-bearing. Kept: ffmpeg's rawvideo output size is locked to the first decoded frame, hence the two-pass dump recipe (frame 0 alone with -frames:v 1, frames 2..N with select=gte(n,1)).
  • Merge: 33904e74 — parents ccc5a836 (main) and 2129be51 (lane), so a real merge, not a fast-forward. Between this lane's base 79984549 and the merge, main absorbed lane-vp9-hbd, which converted every ec-vp9 plane to u16 (ec_vp9::Sample) and threaded bd through every pixel kernel. The lane wrote its scaling against the u8 kernels, so the merge was resolved by porting the lane's semantics onto the u16 substrate.
  • Conflict regions and resolution (both sides read from the index :2:/:3:; the working-tree markers elide lines):
    • crates/ec-vp9/src/decode.rs — one conflict, the capability doc block. Combined: both the profile-2 10-bit clause and the intra-only / scaled-reference clauses in one paragraph. The auto-merged remainder was verified by diff: everything the lane changed (intra-only dispatch + decode_intra_only_frame, frame_is_intra_only routing in decode_block, ScaleFactors::setup + valid_ref_frame_size refusal, the removed size-change refusal) is present; the only deltas vs the lane side are u16/bd/profile-2 mechanics.
    • crates/ec-vp9/src/mc.rs — four conflicts (the two 1D convolve calls in inter_predictor, the convolve_vert call inside the avg branch, and the build_inter_predictors signature + coordinate head). Resolved by COMBINING: main's Sample/bd kernels stay the substrate and the lane's scaling is ported onto them — convolve_horiz(.., x0_q4, x_step, w, rows, avg, bd), convolve_vert(.., y0_q4, y_step, w, h, avg, bd) (both default SUBPEL_SHIFTS), the scaled dispatch at the top of inter_predictor, the lane's extracted convolve_2d ported to Sample + bd, and sf: &ScaleFactors in build_inter_predictors with the lane's scaled block/MV mapping. The scale arithmetic (scale_value, vp9_scale_mv, step derivation) is depth-independent and kept verbatim. Because both sides rewrote these functions, the file was re-composed rather than marker-resolved; the result was proof-read in both directions (diff vs each side shows only the other side's delta).
    • crates/ec-vp9/src/header.rs — clean auto-merge (use_key_partition).
    • crates/ec-vp9/tests/{intraonly,scaledref}_exact.rs — not a git conflict, but the lane's u8-era comparison had to be re-expressed: the pictures are Vec<Sample> (u16) now, so the byte comparison goes through got.extend(pic.y.iter().map(|&v| v as u8)) (the crate's convention in odd_dimensions_exact.rs / inter_pixels_exact.rs).
  • Create-list audit: exactly the expected creates — the three TRACKED fixtures under crates/ec-vp9/tests/data/ (they are committed, not gitignored, so no fixture-copy step), intraonly_exact.rs, scaledref_exact.rs, this report, lanes/vp9refsetup/gen_intraonly.py and gen_scaledref.c. No junk files, no target artifacts.
  • Gates on the MERGED tree (CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9refmerge): cargo test -p ec-vp9 → 25 binaries, 40 passed / 0 failed / 0 ignored; the non-skipped named gates: scaledref_exact 2/2, intraonly_exact 1/1, odd_dimensions_exact 3/3, hbd_exact 2/2, inter_pixels_exact 3/3, keyframe_exact 4/4, lib 9/9. Warning parity: cargo check -p ec-vp9 --all-targets → exactly the 5 pre-existing (TM_PRED, read_partition, partition_probs, x_mis, y_mis). No crate in the repo depends on ec-vp9 (only on ec-vp9-syntax), so there is no cross-crate suite to run.
  • Merged-tree corpus re-sweep (both lanes touched the prediction path; EVERY stream regenerated from the merged build and cmped against the libvpx 1.15.0 oracle) — all BYTE-IDENTICAL, with the frame count derived arithmetically (dump_bytes / (w*h + 2*ceil(w/2)*ceil(h/2)), ×2 for u16):
stream frames oracle bytes
tests/data/scaledref.ivf (1x 1280x720 + 9x 640x360) 10 drv_pix3 4,492,800
tests/data/scaledref_odd.ivf (1x 1279x719 + 9x 640x360) 10 drv_pix3 4,490,801
tests/data/intraonly.ivf (11 coded, 10 shown) 10 drv_pix3 1,152,000
vp9-1080p-23.976-8bit 48 drv_pix3 149,299,200
vp9-1080p-60-8bit 120 drv_pix3 373,248,000
vp9-superframe-altref 60 drv_pix3 6,912,000
vp9-tiles-1280 30 drv_pix3 41,472,000
vp9-1080p-23.976-10bit 48 drv_pix10 (u16-LE) 298,598,400
vp9-1080p-60-10bit 120 drv_pix10 (u16-LE) 746,496,000
odd testsrc2 patched 321x241 12 drv_pix2 + pixcmp2.py 1,395,876
  • Push: ccc5a836..33904e74 main -> main; git ls-remote origin refs/heads/main == 33904e747ab7881b4e97d518f68cd03d3afa6c6b == local HEAD.
  • Cleanup: lane worktree ../edith_codecs-vp9ref removed (branch lane-vp9-refsetup kept as history); rm -rf $HOME/.cache/cargo-target-vp9ref{,merge,verify} and the builder/verify dirs. EDITH_FINDINGS.md (untracked, sibling session) left untouched.
  • Instruments kept: tests/scratch_pixdump{,10}.rs + the EC_VP9_* trace hooks stay in tree — they are the next lane's comparators, not throwaways.
  • Still open (unchanged from the lane): the valid_ref_frame_size ratio bound stays a named refusal (libvpx errors the same way), and profile-2 intra-only / scaled-reference interaction has no corpus stream — the scaled path is exercised only at profile 0 (the odd fixture covers odd x scaled).