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};
2 use ec_core::frame::{Frame, VideoFrame};2 use ec_core::frame::{Frame, VideoFrame};
3 use ec_core::registry::{CodecId, CodecParameters, Decoder, Demuxer, MediaParameters};3 use ec_core::registry::{CodecId, CodecParameters, Decoder, Demuxer, MediaParameters};
4 use ec_h264::NalOutcome;4 use ec_h264::NalOutcome;
5+use std::io::Read;
5 use std::path::{Path, PathBuf};6 use std::path::{Path, PathBuf};
6 7
7 const MAX_FRAMES: usize = 60;8 const MAX_FRAMES: usize = 60;
@@ -38,11 +39,13 @@ pub fn run() {
38 &[fx.join("bitstreams"), repo().join("crates/ec-av1/fixtures")],39 &[fx.join("bitstreams"), repo().join("crates/ec-av1/fixtures")],
39 ),40 ),
40 &["ivf", "obu"],41 &["ivf", "obu"],
42+ Some(b"AV01"),
41 );43 );
42 each("av1", &av1, &[1, 6], av1_run);44 each("av1", &av1, &[1, 6], av1_run);
43 let h264 = streams(45 let h264 = streams(
44 &dirs(&vectors, "h264-jvt", &[fx.join("bitstreams")]),46 &dirs(&vectors, "h264-jvt", &[fx.join("bitstreams")]),
45 &["264", "h264", "avc"],47 &["264", "h264", "avc"],
48+ None,
46 );49 );
47 each("h264", &h264, &[0], h264_run);50 each("h264", &h264, &[0], h264_run);
48 let h265 = streams(51 let h265 = streams(
@@ -55,30 +58,36 @@ pub fn run() {
55 ],58 ],
56 ),59 ),
57 &["265", "hevc", "bit", "bin"],60 &["265", "hevc", "bit", "bin"],
61+ None,
58 );62 );
59 each("h265", &h265, &[1, 6], h265_run);63 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+ );
61 each(70 each(
62 "vp9",71 "vp9",
63- &streams(&dirs(&vectors, "vp9", &[]), &["ivf"]),72+ &streams(&dirs(&vectors, "vp9", &[]), &["ivf"], Some(b"VP90")),
64 &[1, 6],73 &[1, 6],
65 vp9_run,74 vp9_run,
66 );75 );
67 each(76 each(
68 "mpeg2",77 "mpeg2",
69- &streams(&[fx.join("codecs")], &["m2v"]),78+ &streams(&[fx.join("codecs")], &["m2v"], None),
70 &[0],79 &[0],
71 mpeg2_run,80 mpeg2_run,
72 );81 );
73 each(82 each(
74 "mpeg4",83 "mpeg4",
75- &streams(&[fx.join("codecs")], &["m4v"]),84+ &streams(&[fx.join("codecs")], &["m4v"], None),
76 &[0],85 &[0],
77 mpeg4_run,86 mpeg4_run,
78 );87 );
79 each(88 each(
80 "h263",89 "h263",
81- &streams(&[fx.join("codecs")], &["h263"]),90+ &streams(&[fx.join("codecs")], &["h263"], None),
82 &[0],91 &[0],
83 mpeg4_run,92 mpeg4_run,
84 );93 );
@@ -139,15 +148,23 @@ fn walk(dir: &Path, out: &mut Vec<PathBuf>) {
139 }148 }
140 }149 }
141 150
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> {
143 let mut found = Vec::new();161 let mut found = Vec::new();
144 for dir in dirs {162 for dir in dirs {
145 walk(dir, &mut found);163 walk(dir, &mut found);
146 }164 }
147 found.retain(|path| {165 found.retain(|path| {
148- path.extension()166+ let ext = path.extension().and_then(|e| e.to_str()).unwrap_or("");
149- .and_then(|e| e.to_str())167+ exts.contains(&ext) && (ext != "ivf" || fourcc.is_none_or(|f| ivf_fourcc_is(path, f)))
150- .is_some_and(|e| exts.contains(&e))
151 });168 });
152 found.sort_by_key(|path| label(path));169 found.sort_by_key(|path| label(path));
153 found.truncate(MAX_STREAMS);170 found.truncate(MAX_STREAMS);
@@ -436,10 +453,15 @@ fn mpeg4_run(path: &Path, _threads: usize, sink: &mut Sink) -> Result<(), String
436 453
437 fn containers() {454 fn containers() {
438 let fx = ec_testkit::root();455 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+ );
440 paths.extend(streams(461 paths.extend(streams(
441 &[fx.join("mp4corpus"), fx.join("derived"), fx.join("video")],462 &[fx.join("mp4corpus"), fx.join("derived"), fx.join("video")],
442 &["mp4", "mov", "mkv"],463 &["mp4", "mov", "mkv"],
464+ None,
443 ));465 ));
444 for path in &paths {466 for path in &paths {
445 let case = format!("video/container/{}", label(path));467 let case = format!("video/container/{}", label(path));