Files
craft-libs/crates/video/tests/mpeg2/perf.rs
Dylan M. Taylor 5e892217ed craft-video: MPEG-2 and MPEG-1 video decoder from FilmCraft (mpeg2) (#864)
* craft-video: MPEG-2 and MPEG-1 video decoder from FilmCraft (`mpeg2`)

FilmCraft's crates/mpeg2v at 4bec22bd moves to craft_video::mpeg2 behind the
decoder-only feature `mpeg2`: sources, README and tests (unit, synthetic
streams checked by ffmpeg, the ffmpeg oracle fixtures, hostile sweeps).

Changes in the move: craft-media-testkit instead of filmcraft-testkit, one
test target (tests/mpeg2), crate paths, rustfmt at this repo's width.

New: a memory budget (Decoder::set_memory_budget, craft_video::budget) checked
when a sequence becomes active, and a mutation test over the synthetic
field-picture, 16x8 and dual-prime streams, which ffmpeg's encoder cannot
produce and the hostile sweep therefore never reached.

* craft-video mpeg2: write the restart check without a negated conjunction (clippy nonminimal_bool)
2026-11-11 17:42:02 -05:00

38 lines
1.3 KiB
Rust

//! Decode speed (ignored; run with `cargo test --release -p craft-video --features mpeg2,threads --test mpeg2 perf:: --
//! --ignored --nocapture`). Uses the 1080i fixture of `tests/mpeg2/oracle.rs` (ffmpeg-encoded, 25 Mb/s).
use crate::common;
use common::*;
#[test]
#[ignore]
fn perf_1080i_decode_fps() {
let Some(ff) = craft_media_testkit::ffmpeg_or_skip("mpeg2 perf") else { return };
let f = make(&ff, &HD1080I).expect("fixture");
let es = std::fs::read(&f).unwrap();
let aus = craft_video::mpeg2::access_units(&es);
for threads in [false, true] {
let mut best = f64::MAX;
let mut frames = 0;
for _ in 0..5 {
let mut d = craft_video::mpeg2::Decoder::new();
d.set_threads(threads);
let t0 = std::time::Instant::now();
let mut n = 0;
for (i, r) in aus.iter().enumerate() {
n += d.decode(&es[r.clone()], i as i64).unwrap().len();
}
n += d.flush().len();
best = best.min(t0.elapsed().as_secs_f64());
frames = n;
}
println!(
"1080i25 MPEG-2 (4:2:0, 25 Mb/s, IBBP): {frames} frames in {:.1} ms = {:.1} fps ({})",
best * 1e3,
frames as f64 / best,
if threads { "slice rows on rayon" } else { "single thread" }
);
}
}