FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
#805: Morph Cut morphs along optical flow instead of cross-dissolving
vangel7650ce8b090cb2
diff --git a/crates/render/src/plan.rs b/crates/render/src/plan.rsindex 92b333cde..4dd0d4d0e 100644--- a/crates/render/src/plan.rs+++ b/crates/render/src/plan.rs@@ -159,7 +159,7 @@ fn cpu_frame(img: crate::Image) -> Arc<VideoFrame> {}fn simple_transition(id: &str) -> bool {- matches!(id, "cross_dissolve" | "dip_to_black" | "dip_to_white" | "morph_cut")+ matches!(id, "cross_dissolve" | "dip_to_black" | "dip_to_white")}/// The standard effects of a media clip if the GPU can draw it (any blend mode, no opacity masks,diff --git a/crates/render/src/preview.rs b/crates/render/src/preview.rsindex f113e9049..8079502b7 100644--- a/crates/render/src/preview.rs+++ b/crates/render/src/preview.rs@@ -487,7 +487,7 @@ fn estimate_cost(project: &Project, seq: &Sequence, layers: &[Layer]) -> f64 {total += match l {Layer::Item(_, it) => layer_cost(project, it, px, false),Layer::Transition(_, x, a, b) => {- let simple = matches!(x.effect.effect.as_str(), "cross_dissolve" | "dip_to_black" | "dip_to_white" | "non_additive_dissolve" | "morph_cut");+ let simple = matches!(x.effect.effect.as_str(), "cross_dissolve" | "dip_to_black" | "dip_to_white" | "non_additive_dissolve");let sides: f64 = [a, b].iter().filter_map(|s| s.map(|it| layer_cost(project, it, px, !simple))).sum();sides + if simple { 1.0 } else { 12.0 * px }}diff --git a/crates/render/src/tests.rs b/crates/render/src/tests.rsindex 31f5edfc0..31eed64ca 100644--- a/crates/render/src/tests.rs+++ b/crates/render/src/tests.rs@@ -250,6 +250,32 @@ fn push_plan_preserves_reference_track_order_and_reverse() {}}+#[test]+fn morph_cut_frames_render_on_the_cpu_with_the_morph() {+ // the GPU compositor can only cross-fade layers: a Morph Cut frame is planned whole on the+ // CPU, so preview and export show the optical-flow morph, not a dissolve+ let (mut p, red, ocean, seq, map) = setup();+ let a = place(&mut p, seq, 0, red, 0, 24);+ let b = place(&mut p, seq, 0, ocean, 24, 24);+ let rate = FrameRate::FPS_24;+ p.sequence_mut(seq).unwrap().video_tracks[0].transitions.push(filmcraft_project::Transition {+ id: filmcraft_project::TransitionId(998),+ effect: filmcraft_project::find_effect("morph_cut").unwrap().instance(),+ start: rate.tick_of(18),+ duration: rate.tick_of(12),+ from: Some(a),+ to: Some(b),+ align: Default::default(),+ reverse: false,+ });+ let opts = RenderOptions { scale: 0.5, ..Default::default() };+ assert!(plan::is_cpu_frame(&p, seq, rate.tick_of(24)));+ assert!(!plan::is_cpu_frame(&p, seq, rate.tick_of(10)), "outside the transition the frame stays on the GPU");+ let plan = plan::plan_frame(&p, seq, rate.tick_of(24), opts, &map);+ assert!(matches!(plan, plan::FramePlan::Image(_)));+ assert_eq!(plan::execute_cpu(&plan).px, render_sequence(&p, seq, rate.tick_of(24), opts, &map).px);+}+/// A project with a 4 s bars-and-tone clip (1 kHz at −20 dBFS) on A1, with extra audio effects.fn tone_with(effects: &[(&str, &[(&str, f64)])]) -> (Project, ItemId, SourceMap) {let mut p = Project::new("fx");diff --git a/crates/render/src/transitions/dissolve.rs b/crates/render/src/transitions/dissolve.rsindex 208a74ee3..14756eef9 100644--- a/crates/render/src/transitions/dissolve.rs+++ b/crates/render/src/transitions/dissolve.rs@@ -54,6 +54,11 @@ pub(super) fn apply(id: &str, t: &Tx) -> Option<Image> {}})}+ // a jump cut smoothed by morphing: both frames are warped along the dense optical flow+ // between them and blended, so the subject moves from its place in the outgoing shot to+ // its place in the incoming one instead of showing twice; where the frames do not+ // correspond (no consistent motion) it is the cross dissolve+ "morph_cut" => crate::flow::interpolate(t.a, t.b, p),"luma_fade" => {let soft = t.frac("softness").clamp(0.005, 1.0) * 0.5;let from_b = t.choice("source") == 1;diff --git a/crates/render/src/transitions/goldens.txt b/crates/render/src/transitions/goldens.txtindex 91f56bba1..82692a175 100644--- a/crates/render/src/transitions/goldens.txt+++ b/crates/render/src/transitions/goldens.txt@@ -49,9 +49,9 @@ film_dissolve 0.75 1933591e335936415928335919426e1e426e9fa16e28426e1950821e50824luma_fade 0.25 5c2320892320b62320e223205c3620893620b63620e236205c4920894920b64920e249205c5c20895c20b65c20e05c22luma_fade 0.50 472835462f4c4547621a38702540681d438199cb8f0e46951352a80e53b43b81b60d53b60d60d40d60d60d60d60d60d6luma_fade 0.75 0d39760d3976224f760d39760d46960d46969ad3960d46960d53b60d53b63b81b60d53b60d60d60d60d60d60d60d60d6-morph_cut 0.25 4929356a2935912e35ad2935493a3d6a3a3daf5d3dad3a3d494c456a4c45975745ad4c45495d4d6a5d4d8b5d4dad5d4d-morph_cut 0.50 352e4b4b2e4b6c394b782e4b353e5b4b3e5ba8855b783e5b354e6b4b4e6b78656b784e6b355e7b4b5e7b615e7b785e7b-morph_cut 0.75 2134602c34604744604234602142782c4278a1ac784242782150902c50905a7390425090215fa82c5fa8375fa8425fa8+morph_cut 0.25 472a36582c40892d3a563c75483b43683a3e9f5a44684671434c51604d528a685b7f5271465d556c5c44925c3fb9593d+morph_cut 0.50 372e473e31536a364a3f3b763e3d51503e559e7d5b444780324e71484e6f6972803e57a6375e77505d6e6b5c6b9c5557+morph_cut 0.75 263357273563493f5c2a3a752f406737416e99a27729478d21508e344f88537b9b2e53a5295e98355d9b3560aa495da6mosaic_transition 0.25 7f3633973633cb3633f336337f3633973633cb3633f336337f3633973633cb3633f3363359650d70650da4650dcd650dmosaic_transition 0.50 0d4a9f0d4a9fcc3b20cc3b200d4a9f0d4a9fcc3b20cc3b200d4a9f0d4a9fcc3b20cc3b2036566f36566f774e77774e77mosaic_transition 0.75 0d46963d7696a6df964680960d46963d7696a6df964680960d46963d7696a6df964680960d66e50d66e50d66e50d66e5diff --git a/crates/render/src/transitions/legacy.rs b/crates/render/src/transitions/legacy.rsindex 7af9bb249..1cf8ddfd5 100644--- a/crates/render/src/transitions/legacy.rs+++ b/crates/render/src/transitions/legacy.rs@@ -56,7 +56,6 @@ pub(super) fn apply(e: &EffectInstance, a: &Image, b: &Image, p: f32) -> Option<id,"cross_dissolve"| "cross_dissolve_legacy"- | "morph_cut"| "film_dissolve"| "film_dissolve_legacy"| "additive_dissolve"@@ -93,7 +92,7 @@ fn legacy(id: &str, e: &EffectInstance, a: &Image, b: &Image, p: f32) -> Image {let aspect = (a.w as f32) / (a.h as f32).max(1.0);let pd = p as f64;match id {- "cross_dissolve" | "morph_cut" => masked(a, b, |_, _| p),+ "cross_dissolve" => masked(a, b, |_, _| p),"film_dissolve" => {// blend in a gamma-2.2-like space for a filmic, less-dippy dissolvelet mut out = Image::new(a.w, a.h);diff --git a/crates/render/src/transitions/mod.rs b/crates/render/src/transitions/mod.rsindex ceb515f2c..27c26922e 100644--- a/crates/render/src/transitions/mod.rs+++ b/crates/render/src/transitions/mod.rs@@ -18,8 +18,8 @@//!//! Immersive (VR) transitions are flat approximations on the equirectangular frame: sampling wraps//! horizontally and the iris uses great-circle distance, but there is no sphere re-projection.-//! Morph Cut is a cross dissolve (no face tracking), and the Smart Tools / Text transitions are-//! procedural stand-ins (no content analysis, no typed text).+//! Morph Cut morphs with dense optical flow ([`crate::flow`]) but has no face tracking, and the+//! Smart Tools / Text transitions are procedural stand-ins (no content analysis, no typed text).use filmcraft_project::{EffectInstance, ParamValue};use filmcraft_time::Tick;diff --git a/crates/render/src/transitions/tests.rs b/crates/render/src/transitions/tests.rsindex b209a7825..a096c55fe 100644--- a/crates/render/src/transitions/tests.rs+++ b/crates/render/src/transitions/tests.rs@@ -248,6 +248,64 @@ fn modern_and_legacy_ids_are_distinct_renders() {assert!(mean_abs(&m, &want) < 1e-6);}+/// A jump cut (256×144): a static background with a 64×72 subject whose left edge is at `x0`;+/// flat colours, or a smooth texture on both (the subject's own texture moves with it).+fn jump_cut_frame(x0: f32, textured: bool) -> Image {+ let tex = |u: f32, v: f32, k: f32| {+ 0.35 + 0.15 * (u * 0.21 * k).sin() * (v * 0.17).cos() + 0.1 * ((u + v) * 0.11 * k).sin() + 0.05 * (u * 0.53 - v * 0.31 * k).cos()+ };+ paint(256, 144, |x, y| {+ let inside = (x0..x0 + 64.0).contains(&x) && (36.0..108.0).contains(&y);+ let l = match (textured, inside) {+ (false, true) => 0.95,+ (false, false) => 0.3,+ (true, true) => 0.4 + tex(x - x0, y, 0.6),+ (true, false) => 0.6 * tex(x, y, 1.0),+ };+ [l, l * 0.9, l * 0.8, 1.0]+ })+}++#[test]+fn morph_cut_moves_the_subject_instead_of_double_exposing() {+ // the subject jumps 12 px between the shots; at the midpoint Morph Cut shows it once, 6 px+ // along, where a cross dissolve shows two half-bright copies+ let (a, b) = (jump_cut_frame(96.0, false), jump_cut_frame(108.0, false));+ let want = jump_cut_frame(102.0, false);+ let morph = apply(&filmcraft_project::find_effect("morph_cut").unwrap().instance(), &a, &b, 0.5);+ let dissolve = apply(&filmcraft_project::find_effect("cross_dissolve").unwrap().instance(), &a, &b, 0.5);+ // mean red error down a column through the subject's rows+ let column_err = |img: &Image, x: usize| (40..104).map(|y| (img.get(x, y)[0] - want.get(x, y)[0]).abs()).sum::<f32>() / 64.0;+ // uncovered background, both edges, the middle, background still to be covered+ for x in [98usize, 103, 134, 165, 170] {+ let (m, d) = (column_err(&morph, x), column_err(&dissolve, x));+ assert!(m < 0.12, "x={x}: morph off by {m} (dissolve {d})");+ }+ for x in [98usize, 170] {+ assert!(column_err(&dissolve, x) > 0.3, "x={x}: the dissolve ghosts here");+ }+ let (e_morph, e_dissolve) = (mean_abs(&morph, &want), mean_abs(&dissolve, &want));+ assert!(e_morph * 10.0 < e_dissolve, "morph {e_morph} vs dissolve {e_dissolve}");+ // the background away from the subject is left alone+ for (x, y) in [(8, 8), (40, 70), (220, 130)] {+ assert!(morph.get(x, y).iter().zip(a.get(x, y)).all(|(p, q)| (p - q).abs() < 1e-4), "({x}, {y})");+ }+}++#[test]+fn morph_cut_tracks_textured_subjects_and_follows_the_progress() {+ // detail on the subject and behind it: the morph lands much closer than the dissolve, at+ // the midpoint and a quarter of the way through+ for (p, from, to, at) in [(0.5f32, 96.0f32, 108.0f32, 102.0f32), (0.25, 96.0, 112.0, 100.0)] {+ let (a, b) = (jump_cut_frame(from, true), jump_cut_frame(to, true));+ let want = jump_cut_frame(at, true);+ let morph = apply(&filmcraft_project::find_effect("morph_cut").unwrap().instance(), &a, &b, p);+ let dissolve = a.clone().lerp(&b, p);+ let (e_morph, e_dissolve) = (mean_abs(&morph, &want), mean_abs(&dissolve, &want));+ assert!(e_morph * 2.0 < e_dissolve, "p={p}: morph {e_morph} vs dissolve {e_dissolve}");+ }+}+// ---------------------------------------------------------------------------------------------// Golden fingerprintsdiff --git a/docs/gaps.md b/docs/gaps.mdindex ab25b8af5..628bd5a2e 100644--- a/docs/gaps.md+++ b/docs/gaps.md@@ -227,11 +227,12 @@ platforms** G4, G9, G17; **performance** G16; **ecosystem** G11; **measurement**## G18. Effects depth: approximations and missing behaviour-- **Missing:** Warp Stabilizer is 2-D (Premiere's is 3-D subspace), Morph Cut approximate, Lumetri- HDR-aware maths, multicam paging beyond 16 angles, redesigned 26.0 mask tools (rounded corners,- constrained lines).+- **Missing:** Warp Stabilizer is 2-D (Premiere's is 3-D subspace), Morph Cut has no face tracking+ (and occlusion edges are soft), Lumetri HDR-aware maths, multicam paging beyond 16 angles,+ redesigned 26.0 mask tools (rounded corners, constrained lines).- **Have:** Optical Flow time interpolation synthesises motion-compensated in-between frames (dense- coarse-to-fine Lucas–Kanade, CPU; #780); Transform shutter angle motion blur (#415); Ultra Key+ coarse-to-fine Lucas–Kanade, CPU; #780); Morph Cut morphs the subject along that optical flow+ instead of cross-dissolving (CPU; #805); Transform shutter angle motion blur (#415); Ultra KeySetting applied as a parameter preset (#458).- **Estimate:** 60–110 h.diff --git a/docs/target-app-parity.md b/docs/target-app-parity.mdindex 7703c9a71..e74879f6d 100644--- a/docs/target-app-parity.md+++ b/docs/target-app-parity.md@@ -106,7 +106,7 @@ agent-hours to close the area to Premiere, sequential.| Area | Weight | Breadth | Ready | Hours | Evidence | Detail ||---|---|---|---|---|---|---|| Editing, timeline, trimming, multicam | 20% | ~90% | ~70% | 80–140 | Edit algebra, trim modes, Trim Monitor, multicam with audio sync, Premiere default keyboard (143 commands), Source playback and range dragging (10-08). Open: ripple-delete of a gap by column (#668), Backspace on gaps (#648), clip stretching (#653), deselect on empty space (#683), new tracks by dragging media (#483), Escape cancelling drags (#580), time remapping (#510), effects on a whole track (#623) | [ui-parity.md](ui-parity.md) |-| Effects and transitions | 12% | 100% (measured) | ~60% | 80–140 | Every effect exists; Warp Stabilizer is 2-D, Morph Cut and Auto Reframe approximate; Optical Flow time interpolation is motion compensated on the CPU (#780). 34 effect ids run on the GPU against ~82 of Premiere's ~92 marked Accelerated. No Object Mask (26.0, AI). | [hardware-parity.md](hardware-parity.md) |+| Effects and transitions | 12% | 100% (measured) | ~60% | 80–140 | Every effect exists; Warp Stabilizer is 2-D, Auto Reframe approximate, Morph Cut morphs with optical flow but without face tracking (#805); Optical Flow time interpolation is motion compensated on the CPU (#780). 34 effect ids run on the GPU against ~82 of Premiere's ~92 marked Accelerated. No Object Mask (26.0, AI). | [hardware-parity.md](hardware-parity.md) || Media import and codecs | 12% | ~75% | ~60% | 150–250 | Own bit-exact decoders for H.264, HEVC, VP9, AV1, ProRes, DNx, APV, MPEG-2, AAC, AC-3, Opus. But H.264 only 8-bit 4:2:0 and HEVC no 4:2:2 in software (most 10-bit cameras, #626); no camera RAW (R3D, ARRIRAW, BRAW, Sony RAW, Canon RAW, ProRes RAW, #345, #383); no E-AC-3 (#647), AVI (#598), WMV, DV, XAVC / P2 metadata; Sony start timecode (#460); WebM black (#432) | [codec-parity.md](codec-parity.md), [file-format-parity.md](file-format-parity.md) || Audio | 10% | ~88% | ~65% | 50–90 | Mixer graph, automation, all 53 effects, Essential Sound, 5.1, voice-over, Remix, multi-stream container audio (#361). Device and playback reports: crackle / cut-outs (#336, #410, #602, #605, #617); Enhance Speech is DSP, not a model; ALSA fallback fixed (#254) | || Panels and UI fidelity | 10% | ~88% | ~60% | 120–200 | All main panels. Missing: on-screen transform handles in the Program monitor (#639), Effect Controls keyframe zoom / divider / row lines (#640–#645), docking rearrangement (#493), multi-monitor windows (#466), filmstrip thumbnails (#614), marquee in Project panel (#578) | [ui-parity.md](ui-parity.md) |