diff --git a/crates/engine/examples/bench.rs b/crates/engine/examples/bench.rs index ae88085..aee986c 100644 --- a/crates/engine/examples/bench.rs +++ b/crates/engine/examples/bench.rs @@ -23,7 +23,15 @@ //! writing except the export destination it is handed. //! //! Env: `BENCH_TTFF_TIMEOUT` (s, default 180) how long a seek may wait for its -//! first frame, `BENCH_EXPORT_CAP` (s, default 300) the wall clock any single +//! first frame, `BENCH_EXPORT_SPAN` (s, default 60) how much timeline one +//! export measurement covers, `BENCH_EXPORT_AUDIO` (unset) whether that +//! timeline carries its source's sound as well -- the row is named `_av` when +//! it does, because an export's wall clock is the audio pass plus the picture +//! and a picture-only number is not the thing a person waits for -- +//! `BENCH_EXPORT_ASTREAM` (default 0) which of the file's audio streams that +//! is, a film's second track often being the one no sample table can copy and +//! therefore the one that measures a re-encode, +//! `BENCH_EXPORT_CAP` (s, default 300) the wall clock any single //! export measurement may take, `BENCH_EXPORT_REPS` (default 5) how many times //! an export is repeated *if the cap leaves room* -- a 4K encode gets one //! capped rep, the small control gets five -- and `BENCH_KEEP` (unset) whether @@ -364,7 +372,12 @@ fn export_bench(path: &Path, seat: &str, out_dir: &Path) { "hevchw" => (Format::Hevc, false), _ => usage(), }; - let metric = format!("export_fps_{seat}"); + // The sound is opt-in and named in the row, so an `_av` number is never + // compared against a picture-only one: what it measures is the *export* -- + // audio pass, mux and all -- which is the only shape of the number a + // "twice real time" claim may be made from. + let with_audio = std::env::var_os("BENCH_EXPORT_AUDIO").is_some(); + let metric = format!("export_fps_{seat}{}", if with_audio { "_av" } else { "" }); let (meta, _) = match engine::demux::Demuxer::open(path) { Ok(opened) => opened, Err(e) => { @@ -372,7 +385,8 @@ fn export_bench(path: &Path, seat: &str, out_dir: &Path) { return; } }; - let span = ((meta.frame_rate * 60.0) as u32).min(meta.frame_count.max(1)); + let span = ((meta.frame_rate * env_f64("BENCH_EXPORT_SPAN", 60.0)) as u32) + .min(meta.frame_count.max(1)); let in_frame = (meta.frame_count / 10).min(meta.frame_count.saturating_sub(span)); let clip = Clip { start: 0, @@ -385,9 +399,16 @@ fn export_bench(path: &Path, seat: &str, out_dir: &Path) { fit: engine::scale::FitPolicy::default(), speed: Speed::NORMAL, }; + // The sound, where it was asked for, is the same clip on an audio lane: + // the very window the picture covers, so the two passes measure one export. + let mut lanes = vec![(LaneKind::Video, vec![clip.clone()])]; + if with_audio { + lanes.push((LaneKind::Audio, vec![clip])); + } + let stream = env_f64("BENCH_EXPORT_ASTREAM", 0.0) as usize; let project = match Project::from_parts( - vec![Source::new(path, 0)], - vec![(LaneKind::Video, vec![clip])], + vec![Source::new(path, stream)], + lanes, Vec::new(), Vec::new(), ) { diff --git a/scripts/bench.sh b/scripts/bench.sh index b2326bf..7dadc1d 100755 --- a/scripts/bench.sh +++ b/scripts/bench.sh @@ -41,8 +41,19 @@ LOG="$OUT_DIR/bench.log" # Absolute, because $CARGO_TARGET_DIR may already be one and the plugin path # below must not become "$PWD/$HOME/...". TARGET=$(realpath -m "${CARGO_TARGET_DIR:-target}") -cargo build --release -p engine -p engine-hw --example bench || exit 1 +# Two builds, and that is not tidiness: `--example bench` is a target filter, +# and engine-hw has no example by that name, so one command builds the harness +# and *not the plugin* -- a fresh target directory then benchmarks pure +# software while every row says nothing about it (measured 2026-08-13: the +# film's hardware export read 11.55 fps, and 94.58 fps once the plugin was +# there). +cargo build --release -p engine-hw || exit 1 +cargo build --release -p engine --example bench || exit 1 BENCH="$TARGET/release/examples/bench" +[ -f "$TARGET/release/libengine_hw.so" ] || { + echo "no libengine_hw.so in $TARGET/release: every hardware row would be software" >&2 + exit 1 +} # The plugin is looked for beside the running executable, and an example binary # lives one directory below the plugin: without this, hardware decode and # hardware encode silently fall back to software and the baseline is a lie.