open-standards/wai/wai-rs/tests/int_video_keyframe.rs
Transaction Science 5982801cae wai.video.int_hyper: neural-keyframe video — learned int_hyper I-frame + integer P-frames
The endorsed design: the I-frame is the LEARNED integer image codec int_hyper
(wai.neural.int_hyper), decoded byte-exact, and the P-frames are integer block-MC
residuals on top — so the whole video decode is integer and byte-identical on every
machine. A learned keyframe you can put in a receipt, plus integer inter-frames.

- int_video::decode_pframes(i_frame, h, w, bs): the P-frame loop seeded with ANY
  decoded I-frame (integer MC from the previous reconstructed frame + quantized
  residual over rANS). Decouples the inter-frame codec from the keyframe source.
- The NEURAL-KEYFRAME path = int_hyper_synth::decode_conditional (frame 0) ∘
  decode_pframes (the rest). Both pure i64; the composition lives in the test/caller.
- tools/wai_int_video_keyframe_encode.py: uses the committed tiny int_hyper vector
  as frame 0 (so the conformance is self-contained, never-skips), translates it for
  the P-frames, codes the residual. Emits only the P-frame bitstream + expected
  hashes (frame 0's hash IS int_hyper's, 7cbe882c).
- Committed vector (tests/vectors/int_video/video_nk*) + NEVER-skip test (gated on
  neural_int+video_int): decodes the I-frame via int_hyper then the P-frames, every
  frame byte-for-byte + clip hash a5f53d477999d159; frame 0 == the int_hyper image.
- Wired wai.video.int_hyper: NeuralIntegerExact (embeds the learned integer codec),
  Lossy tier. `wai capabilities` → 58, 3 integer-exact (int_synth, int_hyper, video).
  SPEC table + capability comment.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-27 07:34:20 -04:00

58 lines
2.7 KiB
Rust

//! `wai.video.int_hyper` — the NEURAL-KEYFRAME inter-frame codec: the I-frame is
//! decoded by the learned integer codec `int_hyper`, the P-frames are integer
//! block-MC residuals on top. The whole decode is integer, so every frame is
//! byte-identical on every machine — a learned keyframe you can put in a receipt,
//! plus integer inter-frames. Composes the two committed tiny vectors; never skips.
#![cfg(all(feature = "neural_int", feature = "video_int"))]
use std::path::PathBuf;
use wai::int_hyper_synth::{decode_conditional, CondBitstream, CondEntropy, IntModel};
use wai::int_video::{decode_pframes, fnv1a};
fn vroot() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/vectors")
}
fn jload(p: &std::path::Path) -> serde_json::Value {
serde_json::from_slice(&std::fs::read(p).unwrap()).unwrap()
}
fn hex16(s: &str) -> [u8; 8] {
let mut o = [0u8; 8];
for (i, b) in o.iter_mut().enumerate() {
*b = u8::from_str_radix(&s[i * 2..i * 2 + 2], 16).unwrap();
}
o
}
#[test]
fn neural_keyframe_clip_decodes_byte_for_byte() {
let ih = vroot().join("int_hyper");
let iv = vroot().join("int_video");
// frame 0: the learned int_hyper I-frame (the committed tiny conditional codec).
let g_s = IntModel::from_json(&jload(&ih.join("tiny_g_s.json")));
let h_s = IntModel::from_json(&jload(&ih.join("tiny_h_s.json")));
let ent = CondEntropy::from_value(&jload(&ih.join("tiny_entropy.json")));
let bs = CondBitstream::from_value(&jload(&ih.join("tiny_bitstream.json")));
let (frame0, h, w) = decode_conditional(&g_s, &h_s, &ent, &bs).expect("int_hyper I-frame");
// frames 1..N: integer block-MC residuals on top.
let conf = jload(&iv.join("video_nk.json"));
let vbs = jload(&iv.join("video_nk_bitstream.json"));
let clip = decode_pframes(&frame0, h, w, &vbs).expect("p-frames");
let want = conf["frame_hashes"].as_array().unwrap();
assert_eq!(clip.frames.len(), want.len(), "frame count");
// frame 0's hash IS the int_hyper image hash — the keyframe is the learned codec.
assert_eq!(format!("{:016x}", fnv1a(&frame0)), want[0].as_str().unwrap(), "I-frame = int_hyper decode");
let mut all = Vec::new();
for (i, frame) in clip.frames.iter().enumerate() {
let got = format!("{:016x}", fnv1a(frame));
assert_eq!(got, want[i].as_str().unwrap(), "frame {i} must reproduce its committed hash");
all.extend_from_slice(&hex16(&got));
}
let clip_hash = format!("{:016x}", fnv1a(&all));
assert_eq!(clip_hash, conf["clip_hash"].as_str().unwrap(), "clip hash");
println!("int_hyper-keyframe video: {} frames {h}x{w}, I-frame={}, clip {clip_hash}", clip.frames.len(), &want[0].as_str().unwrap()[..8]);
}