| 1 | |
| 2 | |
| 3 | use ec_vp8::decode::Decoder; |
| 4 | use std::time::Instant; |
| 5 | |
| 6 | fn main() { |
| 7 | let args: Vec<String> = std::env::args().collect(); |
| 8 | let bytes = std::fs::read(&args[1]).unwrap(); |
| 9 | let w = u16::from_le_bytes([bytes[12], bytes[13]]) as u64; |
| 10 | let h = u16::from_le_bytes([bytes[14], bytes[15]]) as u64; |
| 11 | let rounds: u64 = args.get(2).map(|s| s.parse().unwrap()).unwrap_or(20); |
| 12 | let mut frames = Vec::new(); |
| 13 | let mut pos = 32; |
| 14 | while pos + 12 <= bytes.len() { |
| 15 | let sz = u32::from_le_bytes(bytes[pos..pos + 4].try_into().unwrap()) as usize; |
| 16 | frames.push(bytes[pos + 12..pos + 12 + sz].to_vec()); |
| 17 | pos += 12 + sz; |
| 18 | } |
| 19 | let nframes = frames.len(); |
| 20 | let shown = frames.iter().filter(|f| (f[0] >> 4) & 1 == 1).count() as u64; |
| 21 | let t = Instant::now(); |
| 22 | for _ in 0..rounds { |
| 23 | let mut dec = Decoder::new(); |
| 24 | for f in &frames { |
| 25 | dec.decode(f).unwrap(); |
| 26 | } |
| 27 | } |
| 28 | let dt = t.elapsed().as_secs_f64(); |
| 29 | let dec_mpx = rounds as f64 * nframes as f64 * w as f64 * h as f64 / 1e6 / dt; |
| 30 | let out_mpx = rounds as f64 * shown as f64 * w as f64 * h as f64 / 1e6 / dt; |
| 31 | println!( |
| 32 | "{}x{rounds} frames ({shown} shown/round) in {dt:.3}s: \ |
| 33 | decode {dec_mpx:.1} MP/s, output {out_mpx:.1} MP/s \ |
| 34 | ({:.1} shown fps @ {w}x{h})", |
| 35 | nframes, |
| 36 | rounds as f64 * shown as f64 / dt |
| 37 | ); |
| 38 | } |