tools/golden video: route IVF by fourcc
Browse files at this commitaf3c0ab8a3d3d25ab0d3c27f051fa4a93515c260Parent: 787f3231 changed file +32 -10
- tools/golden/src/video.rs +32 -10
tools/golden/src/video.rsmodified+32 -10
| @@ -2,6 +2,7 @@ use crate::{error, guard, hash, name, text}; | ||
| 2 | 2 | use ec_core::frame::{Frame, VideoFrame}; |
| 3 | 3 | use ec_core::registry::{CodecId, CodecParameters, Decoder, Demuxer, MediaParameters}; |
| 4 | 4 | use ec_h264::NalOutcome; |
| 5 | +use std::io::Read; | |
| 5 | 6 | use std::path::{Path, PathBuf}; |
| 6 | 7 | |
| 7 | 8 | const MAX_FRAMES: usize = 60; |
| @@ -38,11 +39,13 @@ pub fn run() { | ||
| 38 | 39 | &[fx.join("bitstreams"), repo().join("crates/ec-av1/fixtures")], |
| 39 | 40 | ), |
| 40 | 41 | &["ivf", "obu"], |
| 42 | + Some(b"AV01"), | |
| 41 | 43 | ); |
| 42 | 44 | each("av1", &av1, &[1, 6], av1_run); |
| 43 | 45 | let h264 = streams( |
| 44 | 46 | &dirs(&vectors, "h264-jvt", &[fx.join("bitstreams")]), |
| 45 | 47 | &["264", "h264", "avc"], |
| 48 | + None, | |
| 46 | 49 | ); |
| 47 | 50 | each("h264", &h264, &[0], h264_run); |
| 48 | 51 | let h265 = streams( |
| @@ -55,30 +58,36 @@ pub fn run() { | ||
| 55 | 58 | ], |
| 56 | 59 | ), |
| 57 | 60 | &["265", "hevc", "bit", "bin"], |
| 61 | + None, | |
| 58 | 62 | ); |
| 59 | 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 | 70 | each( |
| 62 | 71 | "vp9", |
| 63 | - &streams(&dirs(&vectors, "vp9", &[]), &["ivf"]), | |
| 72 | + &streams(&dirs(&vectors, "vp9", &[]), &["ivf"], Some(b"VP90")), | |
| 64 | 73 | &[1, 6], |
| 65 | 74 | vp9_run, |
| 66 | 75 | ); |
| 67 | 76 | each( |
| 68 | 77 | "mpeg2", |
| 69 | - &streams(&[fx.join("codecs")], &["m2v"]), | |
| 78 | + &streams(&[fx.join("codecs")], &["m2v"], None), | |
| 70 | 79 | &[0], |
| 71 | 80 | mpeg2_run, |
| 72 | 81 | ); |
| 73 | 82 | each( |
| 74 | 83 | "mpeg4", |
| 75 | - &streams(&[fx.join("codecs")], &["m4v"]), | |
| 84 | + &streams(&[fx.join("codecs")], &["m4v"], None), | |
| 76 | 85 | &[0], |
| 77 | 86 | mpeg4_run, |
| 78 | 87 | ); |
| 79 | 88 | each( |
| 80 | 89 | "h263", |
| 81 | - &streams(&[fx.join("codecs")], &["h263"]), | |
| 90 | + &streams(&[fx.join("codecs")], &["h263"], None), | |
| 82 | 91 | &[0], |
| 83 | 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 | 161 | let mut found = Vec::new(); |
| 144 | 162 | for dir in dirs { |
| 145 | 163 | walk(dir, &mut found); |
| 146 | 164 | } |
| 147 | 165 | 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))) | |
| 151 | 168 | }); |
| 152 | 169 | found.sort_by_key(|path| label(path)); |
| 153 | 170 | found.truncate(MAX_STREAMS); |
| @@ -436,10 +453,15 @@ fn mpeg4_run(path: &Path, _threads: usize, sink: &mut Sink) -> Result<(), String | ||
| 436 | 453 | |
| 437 | 454 | fn containers() { |
| 438 | 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 | 461 | paths.extend(streams( |
| 441 | 462 | &[fx.join("mp4corpus"), fx.join("derived"), fx.join("video")], |
| 442 | 463 | &["mp4", "mov", "mkv"], |
| 464 | + None, | |
| 443 | 465 | )); |
| 444 | 466 | for path in &paths { |
| 445 | 467 | let case = format!("video/container/{}", label(path)); |