| 1 | #![allow(clippy::needless_range_loop, clippy::field_reassign_with_default, clippy::too_many_arguments, clippy::type_complexity)] |
| 2 | |
| 3 | |
| 4 | use std::io::Write; |
| 5 | use std::time::Instant; |
| 6 | |
| 7 | use ec_core::registry::{CodecId, CodecParameters}; |
| 8 | use ec_mpeg2::Mpeg2Decoder; |
| 9 | |
| 10 | fn main() { |
| 11 | let args: Vec<String> = std::env::args().collect(); |
| 12 | let data = std::fs::read(&args[1]).expect("read"); |
| 13 | let mut out = args.get(2).map(|p| std::fs::File::create(p).expect("create")); |
| 14 | let quiet = std::env::var_os("QUIET").is_some(); |
| 15 | let reps: usize = std::env::var("REPS").ok().and_then(|v| v.parse().ok()).unwrap_or(1); |
| 16 | let t0 = Instant::now(); |
| 17 | let mut frames = 0usize; |
| 18 | for _ in 0..reps { |
| 19 | let mut dec = Mpeg2Decoder::new(CodecParameters::new(CodecId::Mpeg2Video)).unwrap(); |
| 20 | for chunk in data.chunks(65536) { |
| 21 | if let Err(e) = dec.send_bytes(chunk, None) { |
| 22 | eprintln!("error: {e}"); |
| 23 | } |
| 24 | while let Some((f, info)) = dec.pop_picture() { |
| 25 | frames += 1; |
| 26 | if !quiet { |
| 27 | println!("{:?} tr {} {}x{} {:?} corrupt {} tff {} rff {} prog {}", info.picture_type, info.temporal_reference, f.width, f.height, f.interlace, info.corrupt, info.top_field_first, info.repeat_first_field, info.progressive_frame); |
| 28 | } |
| 29 | if let Some(o) = out.as_mut() { |
| 30 | for p in &f.planes { |
| 31 | o.write_all(&p.data).unwrap(); |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | if let Err(e) = dec.flush_stream() { |
| 37 | eprintln!("error: {e}"); |
| 38 | } |
| 39 | while let Some((f, info)) = dec.pop_picture() { |
| 40 | frames += 1; |
| 41 | if !quiet { |
| 42 | println!("{:?} tr {} {}x{} {:?} corrupt {}", info.picture_type, info.temporal_reference, f.width, f.height, f.interlace, info.corrupt); |
| 43 | } |
| 44 | if let Some(o) = out.as_mut() { |
| 45 | for p in &f.planes { |
| 46 | o.write_all(&p.data).unwrap(); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | let dt = t0.elapsed().as_secs_f64(); |
| 52 | eprintln!("{frames} frames in {dt:.3}s = {:.1} fps", frames as f64 / dt); |
| 53 | } |