From af3c0ab8a3d3d25ab0d3c27f051fa4a93515c260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 09:13:40 +0300 Subject: [PATCH] tools/golden video: route IVF by fourcc --- tools/golden/src/video.rs | 42 +++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/tools/golden/src/video.rs b/tools/golden/src/video.rs index 49541dc5..090e2815 100644 --- a/tools/golden/src/video.rs +++ b/tools/golden/src/video.rs @@ -2,6 +2,7 @@ use crate::{error, guard, hash, name, text}; use ec_core::frame::{Frame, VideoFrame}; use ec_core::registry::{CodecId, CodecParameters, Decoder, Demuxer, MediaParameters}; use ec_h264::NalOutcome; +use std::io::Read; use std::path::{Path, PathBuf}; const MAX_FRAMES: usize = 60; @@ -38,11 +39,13 @@ pub fn run() { &[fx.join("bitstreams"), repo().join("crates/ec-av1/fixtures")], ), &["ivf", "obu"], + Some(b"AV01"), ); each("av1", &av1, &[1, 6], av1_run); let h264 = streams( &dirs(&vectors, "h264-jvt", &[fx.join("bitstreams")]), &["264", "h264", "avc"], + None, ); each("h264", &h264, &[0], h264_run); let h265 = streams( @@ -55,30 +58,36 @@ pub fn run() { ], ), &["265", "hevc", "bit", "bin"], + None, ); each("h265", &h265, &[1, 6], h265_run); - each("vp8", &streams(&[fx.join("vp8")], &["ivf"]), &[0], vp8_run); + each( + "vp8", + &streams(&[fx.join("vp8")], &["ivf"], Some(b"VP80")), + &[0], + vp8_run, + ); each( "vp9", - &streams(&dirs(&vectors, "vp9", &[]), &["ivf"]), + &streams(&dirs(&vectors, "vp9", &[]), &["ivf"], Some(b"VP90")), &[1, 6], vp9_run, ); each( "mpeg2", - &streams(&[fx.join("codecs")], &["m2v"]), + &streams(&[fx.join("codecs")], &["m2v"], None), &[0], mpeg2_run, ); each( "mpeg4", - &streams(&[fx.join("codecs")], &["m4v"]), + &streams(&[fx.join("codecs")], &["m4v"], None), &[0], mpeg4_run, ); each( "h263", - &streams(&[fx.join("codecs")], &["h263"]), + &streams(&[fx.join("codecs")], &["h263"], None), &[0], mpeg4_run, ); @@ -139,15 +148,23 @@ fn walk(dir: &Path, out: &mut Vec) { } } -fn streams(dirs: &[PathBuf], exts: &[&str]) -> Vec { +fn ivf_fourcc_is(path: &Path, fourcc: &[u8; 4]) -> bool { + let mut head = [0u8; 12]; + std::fs::File::open(path) + .and_then(|mut file| file.read_exact(&mut head)) + .is_ok() + && head.starts_with(b"DKIF") + && head[8..12] == fourcc[..] +} + +fn streams(dirs: &[PathBuf], exts: &[&str], fourcc: Option<&[u8; 4]>) -> Vec { let mut found = Vec::new(); for dir in dirs { walk(dir, &mut found); } found.retain(|path| { - path.extension() - .and_then(|e| e.to_str()) - .is_some_and(|e| exts.contains(&e)) + let ext = path.extension().and_then(|e| e.to_str()).unwrap_or(""); + exts.contains(&ext) && (ext != "ivf" || fourcc.is_none_or(|f| ivf_fourcc_is(path, f))) }); found.sort_by_key(|path| label(path)); found.truncate(MAX_STREAMS); @@ -436,10 +453,15 @@ fn mpeg4_run(path: &Path, _threads: usize, sink: &mut Sink) -> Result<(), String fn containers() { let fx = ec_testkit::root(); - let mut paths = streams(&[fx.join("codecs")], &["mov", "mp4", "mkv", "dv", "avi"]); + let mut paths = streams( + &[fx.join("codecs")], + &["mov", "mp4", "mkv", "dv", "avi"], + None, + ); paths.extend(streams( &[fx.join("mp4corpus"), fx.join("derived"), fx.join("video")], &["mp4", "mov", "mkv"], + None, )); for path in &paths { let case = format!("video/container/{}", label(path));