FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
GPU3c: effects-heavy export bench scene (#30)
Manuel Camacho1aa6ff65146c
diff --git a/crates/ui-egui/examples/bench/playback.rs b/crates/ui-egui/examples/bench/playback.rsindex a0228982c..dee93ea05 100644--- a/crates/ui-egui/examples/bench/playback.rs+++ b/crates/ui-egui/examples/bench/playback.rs@@ -38,6 +38,12 @@ pub fn import(s: &mut Session, path: &Path) -> ItemId {/// One clip per track from t = 0 (`layers[0]` on V1), with (scale %, position, rotation°,/// opacity %) Motion/Opacity settings per layer.pub fn build_sequence(s: &mut Session, w: u32, h: u32, layers: &[(ItemId, f64, Option<(f64, f64)>, f64, f64)], effects: &[&str], secs: f64) -> ItemId {+ let per_layer: Vec<&[&str]> = (0..layers.len()).map(|i| if i == 0 { effects } else { &[][..] }).collect();+ build_sequence_fx(s, w, h, layers, &per_layer, secs)+}++/// As [`build_sequence`], with the effect ids of each layer (`per_layer[i]` on V(i+1)).+pub fn build_sequence_fx(s: &mut Session, w: u32, h: u32, layers: &[(ItemId, f64, Option<(f64, f64)>, f64, f64)], per_layer: &[&[&str]], secs: f64) -> ItemId {let rate = FrameRate::FPS_23_976;let sizes: Vec<(u32, u32)> = layers.iter()@@ -69,12 +75,15 @@ pub fn build_sequence(s: &mut Session, w: u32, h: u32, layers: &[(ItemId, f64, Oif let Some(o) = v.effect_mut("opacity").and_then(|o| o.params.get_mut("opacity")) {o.value = ParamValue::Float(opacity);}- if i == 0 {- for (k, id) in effects.iter().enumerate() {+ {+ for (k, id) in per_layer.get(i).copied().unwrap_or(&[]).iter().enumerate() {let mut e = find_effect(id).unwrap_or_else(|| panic!("effect {id}")).instance();let set: &[(&str, f64)] = match *id {"lumetri" => &[("temperature", 18.0), ("contrast", 22.0)],"sharpen" => &[("amount", 40.0)],+ "gaussian_blur" => &[("blurriness", 8.0)],+ "brightness_contrast" => &[("brightness", 10.0), ("contrast", 15.0)],+ "proc_amp" => &[("contrast", 110.0)],_ => &[],};for (name, val) in set {diff --git a/crates/ui-egui/examples/bench/sections.rs b/crates/ui-egui/examples/bench/sections.rsindex e7c067512..27231b732 100644--- a/crates/ui-egui/examples/bench/sections.rs+++ b/crates/ui-egui/examples/bench/sections.rs@@ -457,7 +457,14 @@ pub fn export(o: &Opts) -> Vec<Value> {let dir = std::env::temp_dir().join(format!("filmcraft-bench-export-{}", std::process::id()));std::fs::create_dir_all(&dir).expect("tmp dir");let mut rows = Vec::new();- for (format, label, ext) in [("h264", "H.264 + AAC (MP4)", "mp4"), ("prores", "ProRes 422 (MOV)", "mov")].into_iter().filter(|f| o.wants(f.0)) {+ // Scenes: (id, format, label, extension, effects-heavy). `--only` matches the id exactly here,+ // so `--only h264` runs the plain scene and `--only h264_fx` only the layered one.+ let scenes = [+ ("h264", "h264", "H.264 + AAC (MP4)", "mp4", false),+ ("h264_fx", "h264", "H.264 + AAC, 3 layers + effects", "mp4", true),+ ("prores", "prores", "ProRes 422 (MOV)", "mov", false),+ ];+ for (id, format, label, ext, fx) in scenes.into_iter().filter(|f| o.only.as_deref().is_none_or(|x| x == f.0)) {let mut runs = Vec::new();let mut cpu = Vec::new();let mut bytes = 0u64;@@ -471,7 +478,14 @@ pub fn export(o: &Opts) -> Vec<Value> {for _ in 0..o.repeat {let mut s = Session::default();let a = playback::import(&mut s, &path);- let seq = playback::build_sequence(&mut s, 1920, 1080, &[(a, 100.0, None, 0.0, 100.0)], &[], secs);+ let seq = if fx {+ // PiP layers: (scale %, position, rotation, opacity %); effects per layer, GPU-capable only+ let layers = [(a, 100.0, None, 0.0, 100.0), (a, 50.0, Some((480.0, -270.0)), 0.0, 100.0), (a, 33.0, Some((-560.0, 300.0)), 0.0, 70.0)];+ let per_layer: [&[&str]; 3] = [&["proc_amp", "gaussian_blur", "vignette"], &["brightness_contrast"], &["sharpen"]];+ playback::build_sequence_fx(&mut s, 1920, 1080, &layers, &per_layer, secs)+ } else {+ playback::build_sequence(&mut s, 1920, 1080, &[(a, 100.0, None, 0.0, 100.0)], &[], secs)+ };// build_sequence adds video only: add the clip's audio on A1 for the AAC encodes.edit("audio", |p, _| {let rate = FrameRate::FPS_23_976;@@ -504,7 +518,7 @@ pub fn export(o: &Opts) -> Vec<Value> {if gpu_timings.frames > 0 {let f = gpu_timings.frames as f64;eprintln!(- " [GPU timings for {format}] lock_wait: {:.1} ms ({:.2} ms/f), submit: {:.1} ms ({:.2} ms/f), map_wait: {:.1} ms ({:.2} ms/f), convert: {:.1} ms ({:.2} ms/f)",+ " [GPU timings for {id}] lock_wait: {:.1} ms ({:.2} ms/f), submit: {:.1} ms ({:.2} ms/f), map_wait: {:.1} ms ({:.2} ms/f), convert: {:.1} ms ({:.2} ms/f)",lock_wait.as_secs_f64() * 1000.0,lock_wait.as_secs_f64() * 1000.0 / f,gpu_timings.submit.as_secs_f64() * 1000.0,@@ -523,9 +537,9 @@ pub fn export(o: &Opts) -> Vec<Value> {continue;}let best = runs.iter().cloned().fold(f64::MAX, f64::min);- eprintln!("export {format}: {frames} frames in {best:.1} s");+ eprintln!("export {id}: {frames} frames in {best:.1} s");rows.push(json!({- "format": label, "frames": frames, "seconds": best, "fps": frames as f64 / best,+ "scene": id, "format": label, "frames": frames, "seconds": best, "fps": frames as f64 / best,"realtime": frames as f64 / best / FrameRate::FPS_23_976.as_f64(), "cpu_ms_per_frame": median(&cpu),"mbytes": bytes as f64 / 1e6, "runs_s": runs, "load": load_avg(),// pictures encoded by a hardware encoder during this row (zero with --hw off or where there is none)