//! Minimal IVF demuxing for the ec-vp8 test fixtures (RFC's companion //! container; only what the witnesses need). /// One IVF frame: (pts, payload). pub struct IvfFrame { /// Presentation timestamp from the IVF frame header. #[allow(dead_code)] pub pts: u64, /// The compressed VP8 frame payload. #[allow(dead_code)] // pts-only consumers exist in the stream witnesses pub data: Vec, } /// The frame tag's `show_frame` bit (RFC 6386 §9.1): hidden frames /// (`false`) update the reference buffers but are never displayed. #[allow(dead_code)] // not every witness binary needs the census pub fn show_frame(data: &[u8]) -> bool { (data[0] >> 4) & 1 == 1 } /// Parse an IVF file into (fourcc, width, height, frames). pub fn parse_ivf(bytes: &[u8]) -> (&str, u16, u16, Vec) { assert_eq!(&bytes[0..4], b"DKIF", "not an IVF file"); let hdr_len = u16::from_le_bytes([bytes[6], bytes[7]]) as usize; let fourcc = std::str::from_utf8(&bytes[8..12]).unwrap(); let width = u16::from_le_bytes([bytes[12], bytes[13]]); let height = u16::from_le_bytes([bytes[14], bytes[15]]); let mut pos = hdr_len; let mut frames = Vec::new(); while pos + 12 <= bytes.len() { let sz = u32::from_le_bytes([bytes[pos], bytes[pos + 1], bytes[pos + 2], bytes[pos + 3]]) as usize; let pts = u64::from_le_bytes([ bytes[pos + 4], bytes[pos + 5], bytes[pos + 6], bytes[pos + 7], bytes[pos + 8], bytes[pos + 9], bytes[pos + 10], bytes[pos + 11], ]); pos += 12; if pos + sz > bytes.len() { break; } frames.push(IvfFrame { pts, data: bytes[pos..pos + sz].to_vec(), }); pos += sz; } (fourcc, width, height, frames) } /// Extract the VP8 payload from a lossy WebP file (RIFF/WEBP with a VP8 /// chunk) — the same VP8 key-frame bytes in a different container. #[allow(dead_code)] // only the keyframe_exact binary exercises WebP pub fn webp_vp8_chunk(bytes: &[u8]) -> Vec { assert_eq!(&bytes[0..4], b"RIFF"); assert_eq!(&bytes[8..12], b"WEBP"); let mut pos = 12; while pos + 8 <= bytes.len() { let tag = &bytes[pos..pos + 4]; let sz = u32::from_le_bytes([ bytes[pos + 4], bytes[pos + 5], bytes[pos + 6], bytes[pos + 7], ]) as usize; if tag == b"VP8 " { return bytes[pos + 8..pos + 8 + sz].to_vec(); } pos += 8 + sz + (sz & 1); // chunks are word-aligned } panic!("no VP8 chunk in webp"); } /// ffmpeg's decoded rawvideo byte stream for an IVF file. pub fn ffmpeg_raw_yuv(path: &std::path::Path) -> Vec { let out = ec_testkit::ffmpeg() .args(["-v", "error", "-i"]) .arg(path) .args(["-fps_mode", "passthrough", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]) .output() .expect("ffmpeg runs"); assert!(out.status.success(), "ffmpeg failed on {path:?}"); out.stdout }