tools/golden video: av1/h264/h265/vp8/vp9/mpeg2/mpeg4 elementary + mp4/mkv registry decode, per-frame plane hashes
Browse files at this commit7a5eb82506805fd22c9e2204da000ddf548a4151Parent: 5b64ff01 changed file +471 -1
- tools/golden/src/video.rs +471 -1
tools/golden/src/video.rsmodified+471 -1
| @@ -1 +1,471 @@ | |||
| 1 | -pub fn run() {} | 1 | +use crate::{error, guard, hash, name, text}; |
| 2 | +use ec_core::frame::{Frame, VideoFrame}; | ||
| 3 | +use ec_core::registry::{CodecId, CodecParameters, Decoder, Demuxer, MediaParameters}; | ||
| 4 | +use ec_h264::NalOutcome; | ||
| 5 | +use std::path::{Path, PathBuf}; | ||
| 6 | + | ||
| 7 | +const MAX_FRAMES: usize = 60; | ||
| 8 | +const MAX_STREAMS: usize = 40; | ||
| 9 | +const CHUNK: usize = 65536; | ||
| 10 | + | ||
| 11 | +struct Sink { | ||
| 12 | + case: String, | ||
| 13 | + count: usize, | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +impl Sink { | ||
| 17 | + fn push(&mut self, bytes: &[u8]) { | ||
| 18 | + if self.count < MAX_FRAMES { | ||
| 19 | + hash(&format!("{}/{}", self.case, self.count), bytes); | ||
| 20 | + self.count += 1; | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + fn full(&self) -> bool { | ||
| 25 | + self.count >= MAX_FRAMES | ||
| 26 | + } | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +type Run = fn(&Path, usize, &mut Sink) -> Result<(), String>; | ||
| 30 | + | ||
| 31 | +pub fn run() { | ||
| 32 | + let h264_dirs = [ | ||
| 33 | + "bitstreams", | ||
| 34 | + "vectors/h264-jvt", | ||
| 35 | + "vectors/h264-jvt-interlaced", | ||
| 36 | + "vectors/h264-jvt-hi422", | ||
| 37 | + "vectors/h264-jvt-hi444", | ||
| 38 | + ]; | ||
| 39 | + let hevc_dirs = ["bitstreams", "vectors/hevc-jctvc", "vectors/hevc-rext"]; | ||
| 40 | + each( | ||
| 41 | + "av1", | ||
| 42 | + &list(&["bitstreams", "vectors/av1-aom"], "av1", &["ivf", "obu"]), | ||
| 43 | + &[1, 6], | ||
| 44 | + av1_run, | ||
| 45 | + ); | ||
| 46 | + each( | ||
| 47 | + "h264", | ||
| 48 | + &list(&h264_dirs, "", &["264", "h264"]), | ||
| 49 | + &[0], | ||
| 50 | + h264_run, | ||
| 51 | + ); | ||
| 52 | + each( | ||
| 53 | + "h265", | ||
| 54 | + &list(&hevc_dirs, "", &["265", "hevc", "bit", "bin"]), | ||
| 55 | + &[1, 6], | ||
| 56 | + h265_run, | ||
| 57 | + ); | ||
| 58 | + each("vp8", &list(&["vp8"], "", &["ivf"]), &[0], vp8_run); | ||
| 59 | + each( | ||
| 60 | + "vp9", | ||
| 61 | + &list( | ||
| 62 | + &["bitstreams", "vectors/vp9-libvpx", "vp9"], | ||
| 63 | + "vp9", | ||
| 64 | + &["ivf"], | ||
| 65 | + ), | ||
| 66 | + &[1, 6], | ||
| 67 | + vp9_run, | ||
| 68 | + ); | ||
| 69 | + each("mpeg2", &list(&["codecs"], "", &["m2v"]), &[0], mpeg2_run); | ||
| 70 | + each("mpeg4", &list(&["codecs"], "", &["m4v"]), &[0], mpeg4_run); | ||
| 71 | + containers(); | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +fn list(dirs: &[&str], prefix: &str, exts: &[&str]) -> Vec<PathBuf> { | ||
| 75 | + let mut found = Vec::new(); | ||
| 76 | + for dir in dirs { | ||
| 77 | + let Ok(entries) = std::fs::read_dir(ec_testkit::root().join(dir)) else { | ||
| 78 | + continue; | ||
| 79 | + }; | ||
| 80 | + for entry in entries.flatten() { | ||
| 81 | + let path = entry.path(); | ||
| 82 | + let name_ok = path | ||
| 83 | + .file_name() | ||
| 84 | + .and_then(|n| n.to_str()) | ||
| 85 | + .is_some_and(|n| n.starts_with(prefix)); | ||
| 86 | + let ext_ok = path | ||
| 87 | + .extension() | ||
| 88 | + .and_then(|e| e.to_str()) | ||
| 89 | + .is_some_and(|e| exts.contains(&e)); | ||
| 90 | + if name_ok && ext_ok { | ||
| 91 | + found.push(path); | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | + found.sort(); | ||
| 96 | + found.truncate(MAX_STREAMS); | ||
| 97 | + found | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +fn each(codec: &str, paths: &[PathBuf], threads: &[usize], run: Run) { | ||
| 101 | + for path in paths { | ||
| 102 | + let rel = name(path); | ||
| 103 | + for &t in threads { | ||
| 104 | + let case = if t == 0 { | ||
| 105 | + format!("video/{codec}/{rel}") | ||
| 106 | + } else { | ||
| 107 | + format!("video/{codec}/{rel}/t{t}") | ||
| 108 | + }; | ||
| 109 | + let mut sink = Sink { | ||
| 110 | + case: case.clone(), | ||
| 111 | + count: 0, | ||
| 112 | + }; | ||
| 113 | + guard(&case, || { | ||
| 114 | + let result = run(path, t, &mut sink); | ||
| 115 | + finish(&case, result, &sink); | ||
| 116 | + }); | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | +} | ||
| 120 | + | ||
| 121 | +fn finish(case: &str, result: Result<(), String>, sink: &Sink) { | ||
| 122 | + if let Err(e) = result { | ||
| 123 | + error(case, e); | ||
| 124 | + } | ||
| 125 | + text(&format!("{case}/frames"), sink.count); | ||
| 126 | +} | ||
| 127 | + | ||
| 128 | +fn read_file(path: &Path) -> Result<Vec<u8>, String> { | ||
| 129 | + std::fs::read(path).map_err(|e| e.to_string()) | ||
| 130 | +} | ||
| 131 | + | ||
| 132 | +fn ivf_frames(data: &[u8]) -> Result<Vec<&[u8]>, String> { | ||
| 133 | + if data.len() < 32 || !data.starts_with(b"DKIF") { | ||
| 134 | + return Err("not an IVF file".into()); | ||
| 135 | + } | ||
| 136 | + let mut pos = usize::from(u16::from_le_bytes([data[6], data[7]])); | ||
| 137 | + let mut out = Vec::new(); | ||
| 138 | + while pos + 12 <= data.len() { | ||
| 139 | + let size = u32::from_le_bytes([data[pos], data[pos + 1], data[pos + 2], data[pos + 3]]); | ||
| 140 | + pos += 12; | ||
| 141 | + let end = pos | ||
| 142 | + .checked_add(size as usize) | ||
| 143 | + .filter(|&end| end <= data.len()) | ||
| 144 | + .ok_or("truncated IVF frame")?; | ||
| 145 | + out.push(&data[pos..end]); | ||
| 146 | + pos = end; | ||
| 147 | + } | ||
| 148 | + Ok(out) | ||
| 149 | +} | ||
| 150 | + | ||
| 151 | +fn nal_units(data: &[u8]) -> Vec<&[u8]> { | ||
| 152 | + let mut starts = Vec::new(); | ||
| 153 | + let mut i = 0; | ||
| 154 | + while i + 3 <= data.len() { | ||
| 155 | + if data[i..i + 3] == [0, 0, 1] { | ||
| 156 | + starts.push(i + 3); | ||
| 157 | + i += 3; | ||
| 158 | + } else { | ||
| 159 | + i += 1; | ||
| 160 | + } | ||
| 161 | + } | ||
| 162 | + let mut units = Vec::new(); | ||
| 163 | + for (k, &start) in starts.iter().enumerate() { | ||
| 164 | + let next = starts.get(k + 1).map_or(data.len(), |&n| n - 3); | ||
| 165 | + let mut end = next; | ||
| 166 | + while end > start && data[end - 1] == 0 { | ||
| 167 | + end -= 1; | ||
| 168 | + } | ||
| 169 | + if end > start { | ||
| 170 | + units.push(&data[start..end]); | ||
| 171 | + } | ||
| 172 | + } | ||
| 173 | + units | ||
| 174 | +} | ||
| 175 | + | ||
| 176 | +fn crop8(out: &mut Vec<u8>, plane: &[u8], stride: usize, width: usize, rows: usize) { | ||
| 177 | + for y in 0..rows { | ||
| 178 | + let start = y * stride; | ||
| 179 | + out.extend_from_slice(&plane[start..start + width]); | ||
| 180 | + } | ||
| 181 | +} | ||
| 182 | + | ||
| 183 | +fn crop16(out: &mut Vec<u8>, plane: &[u16], stride: usize, width: usize, rows: usize) { | ||
| 184 | + for y in 0..rows { | ||
| 185 | + let start = y * stride; | ||
| 186 | + for sample in &plane[start..start + width] { | ||
| 187 | + out.extend_from_slice(&sample.to_le_bytes()); | ||
| 188 | + } | ||
| 189 | + } | ||
| 190 | +} | ||
| 191 | + | ||
| 192 | +fn le16(out: &mut Vec<u8>, plane: &[u16]) { | ||
| 193 | + for sample in plane { | ||
| 194 | + out.extend_from_slice(&sample.to_le_bytes()); | ||
| 195 | + } | ||
| 196 | +} | ||
| 197 | + | ||
| 198 | +fn video_bytes(frame: &VideoFrame) -> Vec<u8> { | ||
| 199 | + let mut out = Vec::new(); | ||
| 200 | + let geometry = frame.format.plane_geometry(frame.width, frame.height); | ||
| 201 | + for (plane, (row_bytes, rows)) in frame.planes.iter().zip(geometry) { | ||
| 202 | + crop8(&mut out, &plane.data, plane.stride, row_bytes, rows); | ||
| 203 | + } | ||
| 204 | + out | ||
| 205 | +} | ||
| 206 | + | ||
| 207 | +fn av1_run(path: &Path, threads: usize, sink: &mut Sink) -> Result<(), String> { | ||
| 208 | + let data = read_file(path)?; | ||
| 209 | + let obu = if data.starts_with(b"DKIF") { | ||
| 210 | + ivf_frames(&data)?.concat() | ||
| 211 | + } else { | ||
| 212 | + data | ||
| 213 | + }; | ||
| 214 | + let result = ec_av1::stream::decode_stream_with_threads(&obu, threads, |pic, _, shown| { | ||
| 215 | + if shown { | ||
| 216 | + let mut buf = Vec::new(); | ||
| 217 | + le16(&mut buf, &pic.y); | ||
| 218 | + le16(&mut buf, &pic.u); | ||
| 219 | + le16(&mut buf, &pic.v); | ||
| 220 | + sink.push(&buf); | ||
| 221 | + } | ||
| 222 | + if sink.full() { | ||
| 223 | + Err(ec_core::Error::Eof) | ||
| 224 | + } else { | ||
| 225 | + Ok(()) | ||
| 226 | + } | ||
| 227 | + }); | ||
| 228 | + match result { | ||
| 229 | + Err(e) if !sink.full() => Err(e.to_string()), | ||
| 230 | + _ => Ok(()), | ||
| 231 | + } | ||
| 232 | +} | ||
| 233 | + | ||
| 234 | +fn take_h264(dec: &mut ec_h264::Decoder, sink: &mut Sink) { | ||
| 235 | + while let Some(frame) = dec.next_frame() { | ||
| 236 | + sink.push(&video_bytes(&frame)); | ||
| 237 | + } | ||
| 238 | +} | ||
| 239 | + | ||
| 240 | +fn finish_h264(dec: &mut ec_h264::Decoder) -> Result<(), String> { | ||
| 241 | + if dec.picture_open() { | ||
| 242 | + dec.end_picture().map_err(|e| e.to_string())?; | ||
| 243 | + } | ||
| 244 | + Ok(()) | ||
| 245 | +} | ||
| 246 | + | ||
| 247 | +fn h264_run(path: &Path, _threads: usize, sink: &mut Sink) -> Result<(), String> { | ||
| 248 | + let data = read_file(path)?; | ||
| 249 | + let mut dec = ec_h264::Decoder::new(); | ||
| 250 | + for unit in nal_units(&data) { | ||
| 251 | + if sink.full() { | ||
| 252 | + break; | ||
| 253 | + } | ||
| 254 | + let outcome = dec.push_nal(unit).map_err(|e| e.to_string())?; | ||
| 255 | + if matches!(outcome, NalOutcome::PictureBoundary) { | ||
| 256 | + finish_h264(&mut dec)?; | ||
| 257 | + dec.push_nal(unit).map_err(|e| e.to_string())?; | ||
| 258 | + } | ||
| 259 | + take_h264(&mut dec, sink); | ||
| 260 | + } | ||
| 261 | + finish_h264(&mut dec)?; | ||
| 262 | + dec.flush().map_err(|e| e.to_string())?; | ||
| 263 | + take_h264(&mut dec, sink); | ||
| 264 | + Ok(()) | ||
| 265 | +} | ||
| 266 | + | ||
| 267 | +fn h265_run(path: &Path, threads: usize, sink: &mut Sink) -> Result<(), String> { | ||
| 268 | + let data = read_file(path)?; | ||
| 269 | + let mut dec = ec_h265::Decoder::new(); | ||
| 270 | + dec.set_threads(threads); | ||
| 271 | + for unit in nal_units(&data) { | ||
| 272 | + if sink.full() { | ||
| 273 | + break; | ||
| 274 | + } | ||
| 275 | + dec.push_nal(unit).map_err(|e| e.to_string())?; | ||
| 276 | + while let Some(frame) = dec.next_frame() { | ||
| 277 | + h265_push(&frame.cropped(), sink); | ||
| 278 | + } | ||
| 279 | + } | ||
| 280 | + dec.flush().map_err(|e| e.to_string())?; | ||
| 281 | + while let Some(frame) = dec.next_frame() { | ||
| 282 | + h265_push(&frame.cropped(), sink); | ||
| 283 | + } | ||
| 284 | + Ok(()) | ||
| 285 | +} | ||
| 286 | + | ||
| 287 | +fn h265_push(pic: &ec_h265::decode::DecodedPicture, sink: &mut Sink) { | ||
| 288 | + let mut buf = Vec::new(); | ||
| 289 | + le16(&mut buf, &pic.y); | ||
| 290 | + le16(&mut buf, &pic.cb); | ||
| 291 | + le16(&mut buf, &pic.cr); | ||
| 292 | + sink.push(&buf); | ||
| 293 | +} | ||
| 294 | + | ||
| 295 | +fn vp8_run(path: &Path, _threads: usize, sink: &mut Sink) -> Result<(), String> { | ||
| 296 | + let data = read_file(path)?; | ||
| 297 | + let mut dec = ec_vp8::decode::Decoder::new(); | ||
| 298 | + for frame in ivf_frames(&data)? { | ||
| 299 | + if sink.full() { | ||
| 300 | + break; | ||
| 301 | + } | ||
| 302 | + if let Some(pic) = dec.decode(frame).map_err(|e| e.to_string())? { | ||
| 303 | + let (w, h) = (usize::from(pic.width), usize::from(pic.height)); | ||
| 304 | + let (cw, ch) = ((w + 1) >> 1, (h + 1) >> 1); | ||
| 305 | + let mut buf = Vec::new(); | ||
| 306 | + crop8(&mut buf, &pic.y, pic.stride, w, h); | ||
| 307 | + crop8(&mut buf, &pic.u, pic.uv_stride, cw, ch); | ||
| 308 | + crop8(&mut buf, &pic.v, pic.uv_stride, cw, ch); | ||
| 309 | + sink.push(&buf); | ||
| 310 | + } | ||
| 311 | + } | ||
| 312 | + Ok(()) | ||
| 313 | +} | ||
| 314 | + | ||
| 315 | +fn vp9_run(path: &Path, threads: usize, sink: &mut Sink) -> Result<(), String> { | ||
| 316 | + let data = read_file(path)?; | ||
| 317 | + let mut dec = ec_vp9::decode::Decoder::new(); | ||
| 318 | + dec.set_threads(threads); | ||
| 319 | + for frame in ivf_frames(&data)? { | ||
| 320 | + if sink.full() { | ||
| 321 | + break; | ||
| 322 | + } | ||
| 323 | + if let Some(pic) = dec.decode(frame).map_err(|e| e.to_string())? { | ||
| 324 | + let (w, h) = (usize::from(pic.width), usize::from(pic.height)); | ||
| 325 | + let (sx, sy) = ( | ||
| 326 | + usize::from(pic.subsampling_x), | ||
| 327 | + usize::from(pic.subsampling_y), | ||
| 328 | + ); | ||
| 329 | + let (cw, ch) = ((w + sx) >> sx, (h + sy) >> sy); | ||
| 330 | + let mut buf = Vec::new(); | ||
| 331 | + crop16(&mut buf, &pic.y, pic.stride, w, h); | ||
| 332 | + crop16(&mut buf, &pic.u, pic.uv_stride, cw, ch); | ||
| 333 | + crop16(&mut buf, &pic.v, pic.uv_stride, cw, ch); | ||
| 334 | + sink.push(&buf); | ||
| 335 | + } | ||
| 336 | + } | ||
| 337 | + Ok(()) | ||
| 338 | +} | ||
| 339 | + | ||
| 340 | +fn mpeg2_run(path: &Path, _threads: usize, sink: &mut Sink) -> Result<(), String> { | ||
| 341 | + let data = read_file(path)?; | ||
| 342 | + let mut dec = ec_mpeg2::Mpeg2Decoder::new(CodecParameters::new(CodecId::Mpeg2Video)) | ||
| 343 | + .map_err(|e| e.to_string())?; | ||
| 344 | + for chunk in data.chunks(CHUNK) { | ||
| 345 | + if sink.full() { | ||
| 346 | + break; | ||
| 347 | + } | ||
| 348 | + dec.send_bytes(chunk, None).map_err(|e| e.to_string())?; | ||
| 349 | + while let Some((frame, _)) = dec.pop_picture() { | ||
| 350 | + sink.push(&video_bytes(&frame)); | ||
| 351 | + } | ||
| 352 | + } | ||
| 353 | + dec.flush_stream().map_err(|e| e.to_string())?; | ||
| 354 | + while let Some((frame, _)) = dec.pop_picture() { | ||
| 355 | + sink.push(&video_bytes(&frame)); | ||
| 356 | + } | ||
| 357 | + Ok(()) | ||
| 358 | +} | ||
| 359 | + | ||
| 360 | +fn mpeg4_run(path: &Path, _threads: usize, sink: &mut Sink) -> Result<(), String> { | ||
| 361 | + let data = read_file(path)?; | ||
| 362 | + let mut dec = ec_mpeg4::Mpeg4Decoder::new(CodecParameters::new(CodecId::Mpeg4Part2)) | ||
| 363 | + .map_err(|e| e.to_string())?; | ||
| 364 | + for chunk in data.chunks(CHUNK) { | ||
| 365 | + if sink.full() { | ||
| 366 | + break; | ||
| 367 | + } | ||
| 368 | + dec.send_bytes(chunk, None).map_err(|e| e.to_string())?; | ||
| 369 | + while let Some((frame, _)) = dec.pop_picture() { | ||
| 370 | + sink.push(&video_bytes(&frame)); | ||
| 371 | + } | ||
| 372 | + } | ||
| 373 | + dec.flush_stream().map_err(|e| e.to_string())?; | ||
| 374 | + while let Some((frame, _)) = dec.pop_picture() { | ||
| 375 | + sink.push(&video_bytes(&frame)); | ||
| 376 | + } | ||
| 377 | + Ok(()) | ||
| 378 | +} | ||
| 379 | + | ||
| 380 | +fn containers() { | ||
| 381 | + let paths = list( | ||
| 382 | + &["codecs", "mp4corpus", "derived", "video"], | ||
| 383 | + "", | ||
| 384 | + &["mp4", "mov", "mkv"], | ||
| 385 | + ); | ||
| 386 | + for path in &paths { | ||
| 387 | + let rel = name(path); | ||
| 388 | + guard(&format!("video/container/{rel}"), || { | ||
| 389 | + if let Err(e) = container(path, &rel) { | ||
| 390 | + error(&format!("video/container/{rel}"), e); | ||
| 391 | + } | ||
| 392 | + }); | ||
| 393 | + } | ||
| 394 | +} | ||
| 395 | + | ||
| 396 | +fn open_demuxer(path: &Path) -> Result<Box<dyn Demuxer>, String> { | ||
| 397 | + let file = std::fs::File::open(path).map_err(|e| e.to_string())?; | ||
| 398 | + let demux: Box<dyn Demuxer> = match path.extension().and_then(|e| e.to_str()) { | ||
| 399 | + Some("mkv") => { | ||
| 400 | + Box::new(ec_matroska::MatroskaDemuxer::new(file).map_err(|e| e.to_string())?) | ||
| 401 | + } | ||
| 402 | + _ => Box::new(ec_mp4::Mp4Demuxer::new(file).map_err(|e| e.to_string())?), | ||
| 403 | + }; | ||
| 404 | + Ok(demux) | ||
| 405 | +} | ||
| 406 | + | ||
| 407 | +fn make_decoder(params: &CodecParameters) -> Result<Box<dyn Decoder>, String> { | ||
| 408 | + let p = params.clone(); | ||
| 409 | + let decoder: Box<dyn Decoder> = match params.codec { | ||
| 410 | + CodecId::H264 => Box::new(ec_h264::H264Decoder::new(p).map_err(|e| e.to_string())?), | ||
| 411 | + CodecId::ProRes => Box::new(ec_prores::ProResDecoder::new(p).map_err(|e| e.to_string())?), | ||
| 412 | + CodecId::Dnxhd => Box::new(ec_dnxhd::DnxhdDecoder::new(p).map_err(|e| e.to_string())?), | ||
| 413 | + CodecId::Mjpeg => Box::new(ec_mjpeg::MjpegDecoder::new(p).map_err(|e| e.to_string())?), | ||
| 414 | + CodecId::Mpeg2Video => Box::new(ec_mpeg2::Mpeg2Decoder::new(p).map_err(|e| e.to_string())?), | ||
| 415 | + CodecId::Mpeg4Part2 => Box::new(ec_mpeg4::Mpeg4Decoder::new(p).map_err(|e| e.to_string())?), | ||
| 416 | + other => return Err(format!("no registry decoder for {other:?}")), | ||
| 417 | + }; | ||
| 418 | + Ok(decoder) | ||
| 419 | +} | ||
| 420 | + | ||
| 421 | +fn drain(dec: &mut dyn Decoder, sink: &mut Sink) -> Result<(), String> { | ||
| 422 | + loop { | ||
| 423 | + match dec.receive_frame() { | ||
| 424 | + Ok(Frame::Video(frame)) => sink.push(&video_bytes(&frame)), | ||
| 425 | + Ok(Frame::Audio(_)) => {} | ||
| 426 | + Err(e) if e.is_need_more() || e.is_eof() => return Ok(()), | ||
| 427 | + Err(e) => return Err(e.to_string()), | ||
| 428 | + } | ||
| 429 | + } | ||
| 430 | +} | ||
| 431 | + | ||
| 432 | +fn decode_container( | ||
| 433 | + demux: &mut dyn Demuxer, | ||
| 434 | + index: u32, | ||
| 435 | + params: &CodecParameters, | ||
| 436 | + sink: &mut Sink, | ||
| 437 | +) -> Result<(), String> { | ||
| 438 | + let mut dec = make_decoder(params)?; | ||
| 439 | + while !sink.full() { | ||
| 440 | + let packet = match demux.next_packet() { | ||
| 441 | + Ok(packet) => packet, | ||
| 442 | + Err(e) if e.is_eof() => break, | ||
| 443 | + Err(e) => return Err(e.to_string()), | ||
| 444 | + }; | ||
| 445 | + if packet.stream == index { | ||
| 446 | + dec.send_packet(&packet).map_err(|e| e.to_string())?; | ||
| 447 | + drain(dec.as_mut(), sink)?; | ||
| 448 | + } | ||
| 449 | + } | ||
| 450 | + dec.flush().map_err(|e| e.to_string())?; | ||
| 451 | + drain(dec.as_mut(), sink) | ||
| 452 | +} | ||
| 453 | + | ||
| 454 | +fn container(path: &Path, rel: &str) -> Result<(), String> { | ||
| 455 | + let mut demux = open_demuxer(path)?; | ||
| 456 | + let (index, params) = demux | ||
| 457 | + .streams() | ||
| 458 | + .iter() | ||
| 459 | + .find(|s| matches!(s.params.media, MediaParameters::Video(_))) | ||
| 460 | + .map(|s| (s.index, s.params.clone())) | ||
| 461 | + .ok_or("no video stream")?; | ||
| 462 | + let codec = format!("{:?}", params.codec).to_lowercase(); | ||
| 463 | + let case = format!("video/{codec}/{rel}"); | ||
| 464 | + let mut sink = Sink { | ||
| 465 | + case: case.clone(), | ||
| 466 | + count: 0, | ||
| 467 | + }; | ||
| 468 | + let result = decode_container(demux.as_mut(), index, ¶ms, &mut sink); | ||
| 469 | + finish(&case, result, &sink); | ||
| 470 | + Ok(()) | ||
| 471 | +} | ||