What a Matroska sound track's open costs, as an example
Browse files at this commit1acf3841a7d93fa994d27a15a14a36f7f06d334aParent: ea25339- chore
- what a Matroska sound track's open costs, as an example
1 changed file +29 -0
crates/engine/examples/audio_open_cost.rsadded+29 -0
| @@ -0,0 +1,29 @@ | |||
| 1 | +//! What one open of a Matroska file's *sound* costs -- the walk the `Cues` do | ||
| 2 | +//! not answer, since Matroska indexes no audio samples at all. | ||
| 3 | +//! | ||
| 4 | +//! `cargo run --release -p engine --example audio_open_cost -- <file> [repeats]` | ||
| 5 | +//! | ||
| 6 | +//! Prints one line per open in milliseconds and the block count it found; the | ||
| 7 | +//! first line is the cold one (no sidecar yet), the rest are what a reopen costs | ||
| 8 | +//! once the walk has been written down. | ||
| 9 | + | ||
| 10 | +use std::path::PathBuf; | ||
| 11 | +use std::time::Instant; | ||
| 12 | + | ||
| 13 | +fn main() { | ||
| 14 | + let mut args = std::env::args_os().skip(1); | ||
| 15 | + let path = PathBuf::from(args.next().expect("usage: audio_open_cost <file> [repeats]")); | ||
| 16 | + let repeats: usize = args | ||
| 17 | + .next() | ||
| 18 | + .and_then(|s| s.to_str().and_then(|s| s.parse().ok())) | ||
| 19 | + .unwrap_or(3); | ||
| 20 | + for i in 0..repeats { | ||
| 21 | + let start = Instant::now(); | ||
| 22 | + let audio = engine::demux::MkvAudio::open(&path).expect("open the sound track"); | ||
| 23 | + let ms = start.elapsed().as_secs_f64() * 1e3; | ||
| 24 | + match audio { | ||
| 25 | + Some(audio) => println!("audio open {i}: {ms:.1} ms ({} blocks)", audio.blocks()), | ||
| 26 | + None => println!("audio open {i}: {ms:.1} ms (no AC-3 track)"), | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | +} | ||