forge
Explore
Log in

Don't you dare go Hollow

tools/golden video: route IVF by fourcc

Browse files at this commit

af3c0ab8a3d3d25ab0d3c27f051fa4a93515c260Ahmet Kaan GümüşParent: 787f323
tools/golden/src/video.rsmodified+32 -10
@@ -2,6 +2,7 @@ use crate::{error, guard, hash, name, text};
22 use ec_core::frame::{Frame, VideoFrame};
33 use ec_core::registry::{CodecId, CodecParameters, Decoder, Demuxer, MediaParameters};
44 use ec_h264::NalOutcome;
5+use std::io::Read;
56 use std::path::{Path, PathBuf};
67
78 const MAX_FRAMES: usize = 60;
@@ -38,11 +39,13 @@ pub fn run() {
3839 &[fx.join("bitstreams"), repo().join("crates/ec-av1/fixtures")],
3940 ),
4041 &["ivf", "obu"],
42+ Some(b"AV01"),
4143 );
4244 each("av1", &av1, &[1, 6], av1_run);
4345 let h264 = streams(
4446 &dirs(&vectors, "h264-jvt", &[fx.join("bitstreams")]),
4547 &["264", "h264", "avc"],
48+ None,
4649 );
4750 each("h264", &h264, &[0], h264_run);
4851 let h265 = streams(
@@ -55,30 +58,36 @@ pub fn run() {
5558 ],
5659 ),
5760 &["265", "hevc", "bit", "bin"],
61+ None,
5862 );
5963 each("h265", &h265, &[1, 6], h265_run);
60- each("vp8", &streams(&[fx.join("vp8")], &["ivf"]), &[0], vp8_run);
64+ each(
65+ "vp8",
66+ &streams(&[fx.join("vp8")], &["ivf"], Some(b"VP80")),
67+ &[0],
68+ vp8_run,
69+ );
6170 each(
6271 "vp9",
63- &streams(&dirs(&vectors, "vp9", &[]), &["ivf"]),
72+ &streams(&dirs(&vectors, "vp9", &[]), &["ivf"], Some(b"VP90")),
6473 &[1, 6],
6574 vp9_run,
6675 );
6776 each(
6877 "mpeg2",
69- &streams(&[fx.join("codecs")], &["m2v"]),
78+ &streams(&[fx.join("codecs")], &["m2v"], None),
7079 &[0],
7180 mpeg2_run,
7281 );
7382 each(
7483 "mpeg4",
75- &streams(&[fx.join("codecs")], &["m4v"]),
84+ &streams(&[fx.join("codecs")], &["m4v"], None),
7685 &[0],
7786 mpeg4_run,
7887 );
7988 each(
8089 "h263",
81- &streams(&[fx.join("codecs")], &["h263"]),
90+ &streams(&[fx.join("codecs")], &["h263"], None),
8291 &[0],
8392 mpeg4_run,
8493 );
@@ -139,15 +148,23 @@ fn walk(dir: &Path, out: &mut Vec<PathBuf>) {
139148 }
140149 }
141150
142-fn streams(dirs: &[PathBuf], exts: &[&str]) -> Vec<PathBuf> {
151+fn ivf_fourcc_is(path: &Path, fourcc: &[u8; 4]) -> bool {
152+ let mut head = [0u8; 12];
153+ std::fs::File::open(path)
154+ .and_then(|mut file| file.read_exact(&mut head))
155+ .is_ok()
156+ && head.starts_with(b"DKIF")
157+ && head[8..12] == fourcc[..]
158+}
159+
160+fn streams(dirs: &[PathBuf], exts: &[&str], fourcc: Option<&[u8; 4]>) -> Vec<PathBuf> {
143161 let mut found = Vec::new();
144162 for dir in dirs {
145163 walk(dir, &mut found);
146164 }
147165 found.retain(|path| {
148- path.extension()
149- .and_then(|e| e.to_str())
150- .is_some_and(|e| exts.contains(&e))
166+ let ext = path.extension().and_then(|e| e.to_str()).unwrap_or("");
167+ exts.contains(&ext) && (ext != "ivf" || fourcc.is_none_or(|f| ivf_fourcc_is(path, f)))
151168 });
152169 found.sort_by_key(|path| label(path));
153170 found.truncate(MAX_STREAMS);
@@ -436,10 +453,15 @@ fn mpeg4_run(path: &Path, _threads: usize, sink: &mut Sink) -> Result<(), String
436453
437454 fn containers() {
438455 let fx = ec_testkit::root();
439- let mut paths = streams(&[fx.join("codecs")], &["mov", "mp4", "mkv", "dv", "avi"]);
456+ let mut paths = streams(
457+ &[fx.join("codecs")],
458+ &["mov", "mp4", "mkv", "dv", "avi"],
459+ None,
460+ );
440461 paths.extend(streams(
441462 &[fx.join("mp4corpus"), fx.join("derived"), fx.join("video")],
442463 &["mp4", "mov", "mkv"],
464+ None,
443465 ));
444466 for path in &paths {
445467 let case = format!("video/container/{}", label(path));