The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.
Rust ffmpegfree-video-editormodel-context-protocolnon-linear-editoroffline-firstopen-source-video-editorself-hostedvideo-editingvideo-editing-automationvideo-editing-softwarevideo-editing-toolsvideo-editorvoice-cloningyoutube-automationyoutube-shorts
fix: centre overlap transitions on the cut
eduardorfreitas934f755b471f50
diff --git a/src/crates/concat-export/src/flatten.rs b/src/crates/concat-export/src/flatten.rsindex 1e62e48a..3c2416a0 100644--- a/src/crates/concat-export/src/flatten.rs+++ b/src/crates/concat-export/src/flatten.rs@@ -131,6 +131,7 @@ pub fn flatten_timeline_in(}),media_width: media.width,media_height: media.height,+ media_duration: media.duration,has_audio: Some(media.has_audio),cutout: clip.cutout.clone(),mask_dir: match (&clip.cutout, project_dir) {diff --git a/src/crates/concat-export/src/lib.rs b/src/crates/concat-export/src/lib.rsindex 5982a512..1e92e548 100644--- a/src/crates/concat-export/src/lib.rs+++ b/src/crates/concat-export/src/lib.rs@@ -184,8 +184,8 @@ pub struct ExportClip {#[serde(default)]pub video_fade_in: f64,/// One frame - the one at `source_start` - held for the clip's length.- /// Set by transition resolution for the pre-roll of a clip with no- /// footage before its in-point, never by the UI; see [`pre_roll`].+ /// Set by transition resolution where the outgoing clip of a cut has no+ /// footage after its out-point, never by the UI; see [`overlap`].#[serde(skip)]pub hold: bool,/// The source's pixel width, when the UI knows it. What makes an@@ -196,6 +196,12 @@ pub struct ExportClip {/// The source's pixel height; see `media_width`.#[serde(default)]pub media_height: Option<u32>,+ /// The source's length in seconds, when the UI knows it: how much+ /// footage lies past the clip's out-point for a transition to run the+ /// clip on into. Absent, a transition holds the clip's last frame+ /// instead.+ #[serde(default)]+ pub media_duration: Option<f64>,/// Whether the file carries an audio stream, when the UI knows (the/// document records it at import). Absent falls back to probing, so an/// older caller still exports correctly - just slower to start.@@ -265,6 +271,7 @@ impl ExportClip {hold: false,media_width: None,media_height: None,+ media_duration: None,has_audio: None,cutout: None,mask_dir: String::new(),@@ -522,10 +529,11 @@ pub(crate) fn transitions_at(shapes: &[TransitionShape], frame: i64) -> Vec<Tran/// collected before anything mutates, so resolving one transition cannot/// unhook the adjacency test of the next.///-/// Every kind but the fades to a colour is built on one overlap: the-/// incoming clip extends backwards over the outgoing one by the transition's-/// length, on the lane above, showing the handle before its in-point. What-/// differs is how the two are blended across that overlap - a dissolve+/// Every kind but the fades to a colour is built on one overlap, centred on+/// the cut the way the timeline draws it: the incoming clip extends+/// backwards by half the transition's length, on the lane above, showing+/// the handle before its in-point, and the outgoing one runs on under it by+/// the other half, past its out-point (see [`overlap`]). What differs is how the two are blended across that overlap - a dissolve/// ramps the incoming clip's opacity, a push slides both, a zoom scales/// both under a dissolve, a wipe uncovers the incoming one behind a moving/// edge. The slides and scales are keys on the clips' animations, which@@ -587,23 +595,31 @@ fn resolve_transitions_at(for cut in cuts {match cut.kind.as_str() {"cross-fade" | "push" | "zoom" | "wipe-left" | "wipe-right" => {- // The picture before the cut on the lane above: the- // incoming clip itself, or its first frame held.- let Some((incoming, d)) = pre_roll(clips, &cut, frame) else {+ // The two pictures across the cut: the incoming clip on the+ // lane above, the outgoing one running on beneath it.+ let Some(Overlap {+ incoming,+ length: d,+ outgoing_runs,+ }) = overlap(clips, &cut, frame)+ else {continue;};// How the two blend across the overlap. A shape that cannot// be applied - a clip the user has already keyed on the- // property the shape would ride - falls back to the dissolve- // rather than half-applying, so the cut still transitions.+ // property the shape would ride, or an outgoing picture that+ // is a held frame rather than the clip a key could move -+ // falls back to the dissolve rather than half-applying, so+ // the cut still transitions.let shaped = match cut.kind.as_str() {// The new picture slides in from the right and shoves the// old one out to the left, edge to edge: both ride the// same ease over the same seconds, which is what keeps// them glued."push" => {- rides(clips, cut.outgoing, incoming, "offsetX")+ outgoing_runs+ && rides(clips, cut.outgoing, incoming, "offsetX")&& ride(&mut clips[incoming],"offsetX",@@ -626,7 +642,8 @@ fn resolve_transitions_at(// The old picture grows as it dissolves into the new one,// which settles from a little large to its own size."zoom" => {- rides(clips, cut.outgoing, incoming, "scale")+ outgoing_runs+ && rides(clips, cut.outgoing, incoming, "scale")&& ride(&mut clips[incoming], "scale", 1.25, 1.0, d, true, EASE_OUT)&& ride(&mut clips[cut.outgoing],@@ -699,7 +716,12 @@ fn resolve_transitions_at(.get(kind).is_some_and(|package| package.transition().is_some()) =>{- let Some((incoming, d)) = pre_roll(clips, &cut, frame) else {+ let Some(Overlap {+ incoming,+ length: d,+ ..+ }) = overlap(clips, &cut, frame)+ else {continue;};let b = &mut clips[incoming];@@ -734,57 +756,146 @@ struct Cut {duration: f64,}-/// The overlap a transition crosses: the picture shown on the lane above-/// the outgoing clip for the transition's length before the cut. Returns-/// the index of the clip that is that overlap, and the length, which is-/// capped by both clips; `None` for a cut too short to overlap at all.+/// What [`overlap`] built a transition on.+struct Overlap {+ /// The incoming clip, moved to the lane above the outgoing one and+ /// starting where the overlap does.+ incoming: usize,+ /// The overlap's length: the transition's, capped by both clips.+ length: f64,+ /// The outgoing clip itself runs on under the overlap. False when a+ /// held copy of its last frame does instead, which a key on the clip+ /// cannot move.+ outgoing_runs: bool,+}++/// The overlap a transition crosses, centred on the cut the way the+/// timeline draws it: the incoming clip on the lane above, from half the+/// transition's length before the cut, over the outgoing one running on+/// for the other half past it. The length is capped by both clips; `None`+/// for a cut too short to overlap at all.///-/// The overlap is the incoming clip itself, extended backwards with its-/// source clock wound back the same way, when it has that much footage-/// before its in-point - a still always has. Without that handle the clip-/// is left exactly where the cut put it, and a copy of its first frame is-/// held on the lane above for the transition's length instead: the-/// "repeated frames" every editor shows over a cut with no handle. Winding-/// the start back without the clock, as this once did, played everything-/// after the cut early and ran the last of it off the file's end into-/// black (#236). The hold is the clip with no sound, no keys and no fades-/// of its own, so the picture coming in is the one the clip then plays;-/// a keyed placement is held where its ride has it at the clip's head.-fn pre_roll(clips: &mut Vec<ExportClip>, cut: &Cut, frame: f64) -> Option<(usize, f64)> {- let (a_track, a_duration) = {- let a = &clips[cut.outgoing];- (a.track, a.duration)- };+/// Each side is the clip itself, extended with its source clock moved the+/// same way, into footage the edit left out: before the incoming clip's+/// in-point, after the outgoing one's out-point - a still has all it needs+/// either way. Winding a start back without the clock, as this once did,+/// played everything after the cut early and ran the last of it off the+/// file's end into black (#236).+///+/// Without footage after its out-point, the outgoing clip ends at the cut+/// and a copy of its last frame is held beneath for the rest: the+/// "repeated frames" every editor shows over a cut with no handle. The+/// hold is the clip with no sound, no keys and no fades of its own; a+/// keyed placement is held where its ride leaves it at the clip's tail.+/// The incoming side gets no hold, as one there would end at the cut and+/// leave the clip after it sharing a lane with the outgoing picture: what+/// it lacks before its in-point moves to after the cut instead, so the+/// transition leans later rather than freezing.+fn overlap(clips: &mut Vec<ExportClip>, cut: &Cut, frame: f64) -> Option<Overlap> {+ let a = &clips[cut.outgoing];let b = &clips[cut.incoming];- let d = cut.duration.min(a_duration).min(b.duration);- if d < frame {+ let length = cut.duration.min(a.duration).min(b.duration);+ if length < frame {return None;}- // Footage before the in-point, in timeline seconds.- let handle = if b.kind == ClipKind::Image {- d- } else {- b.source_start / b.speed.max(f64::EPSILON)- };- if handle + frame / 2.0 >= d {+ let mut lead = (length / 2.0).min(head_handle(b));+ if lead < frame / 2.0 {+ lead = 0.0;+ }+ let tail = length - lead;+ let a_track = a.track;+ let a_end = a.start + a.duration;+ let outgoing_runs = tail_handle(a, frame) + frame / 2.0 >= tail;++ {let b = &mut clips[cut.incoming];- b.start -= d;- b.duration += d;- if b.kind != ClipKind::Image {- b.source_start = (b.source_start - d * b.speed).max(0.0);- }- // Sound rides the picture: the pre-roll fades in rather than- // arriving at full level a dissolve early.- b.fade_in = b.fade_in.max(d);+ extend(b, lead, 0.0);+ // Sound rides the picture: each side fades across the overlap+ // rather than arriving or leaving at full level.+ b.fade_in = b.fade_in.max(length);b.track = a_track + 1;- return Some((cut.incoming, d));}+ if outgoing_runs {+ let a = &mut clips[cut.outgoing];+ extend(a, 0.0, tail);+ a.fade_out = a.fade_out.max(length);+ } else {+ let hold = last_frame_held(&clips[cut.outgoing], a_end, tail, frame);+ clips.push(hold);+ }+ Some(Overlap {+ incoming: cut.incoming,+ length,+ outgoing_runs,+ })+}++/// Footage before `clip`'s in-point, in timeline seconds. A clip whose+/// speed rides a curve has none to offer: its source clock is the curve's,+/// which says nothing about before its start.+fn head_handle(clip: &ExportClip) -> f64 {+ if clip.kind == ClipKind::Image {+ f64::INFINITY+ } else if !clip.speed_curve.is_empty() {+ 0.0+ } else {+ clip.source_start / clip.speed.max(f64::EPSILON)+ }+}++/// Footage after `clip`'s out-point, in timeline seconds, a frame short of+/// the length the file declares so a container that rounds up is not read+/// past its last picture. Nothing where the length is unknown, or where a+/// curve sets the clock.+fn tail_handle(clip: &ExportClip, frame: f64) -> f64 {+ if clip.kind == ClipKind::Image {+ return f64::INFINITY;+ }+ if !clip.speed_curve.is_empty() {+ return 0.0;+ }+ clip.media_duration.map_or(0.0, |length| {+ let speed = clip.speed.max(f64::EPSILON);+ ((length - clip.source_start) / speed - clip.duration - frame).max(0.0)+ })+}++/// Lengthens `clip` by `head` seconds before its start and `tail` after+/// its end, its source clock moved with it. Keys sit at fractions of the+/// clip, so each is moved to stay at the instant it was at.+fn extend(clip: &mut ExportClip, head: f64, tail: f64) {+ if head <= 0.0 && tail <= 0.0 {+ return;+ }+ let old = clip.duration;+ let new = old + head + tail;+ if old > 0.0 {+ for key in &mut clip.animation {+ key.at = (key.at * old + head) / new;+ }+ }+ clip.start -= head;+ clip.duration = new;+ if clip.kind != ClipKind::Image {+ clip.source_start = (clip.source_start - head * clip.speed).max(0.0);+ }+}- let mut hold = b.clone();+/// A copy of `clip`'s last frame held from `start` for `length` seconds,+/// on its lane: silent, unkeyed and unfaded, placed where its keys leave+/// it at its tail.+fn last_frame_held(clip: &ExportClip, start: f64, length: f64, frame: f64) -> ExportClip {+ let mut hold = clip.clone();hold.hold = true;- hold.start = b.start - d;- hold.duration = d;- hold.track = a_track + 1;+ hold.start = start;+ hold.duration = length;+ if clip.kind != ClipKind::Image {+ let (played, rate) = match SpeedCurve::new(&clip.speed_curve) {+ Some(curve) => (clip.duration * curve.consumed(1.0), curve.speed_at(1.0)),+ None => (clip.duration * clip.speed, clip.speed),+ };+ hold.source_start = clip.source_start + (played - frame * rate).max(0.0);+ }hold.speed = 1.0;hold.speed_curve.clear();hold.muted = true;@@ -796,19 +907,19 @@ fn pre_roll(clips: &mut Vec<ExportClip>, cut: &Cut, frame: f64) -> Option<(usizehold.video_fade_in = 0.0;hold.transition_shapes.clear();// Keys are absolute and a keyed property's constant is the neutral- // value, so the head of each ride becomes the hold's constant.- let heads: Vec<(String, f64)> = ["scale", "offsetX", "offsetY", "rotation", "opacity"]+ // value, so the tail of each ride becomes the hold's constant.+ let tails: Vec<(String, f64)> = ["scale", "offsetX", "offsetY", "rotation", "opacity"].into_iter().filter_map(|property| {hold.animation.iter().filter(|key| key.property == property)- .min_by(|a, b| a.at.total_cmp(&b.at))+ .max_by(|a, b| a.at.total_cmp(&b.at)).map(|key| (property.to_owned(), key.value))}).collect();hold.animation.clear();- for (property, value) in heads {+ for (property, value) in tails {match property.as_str() {"scale" => hold.scale = value,"offsetX" => hold.offset_x = value,@@ -818,8 +929,7 @@ fn pre_roll(clips: &mut Vec<ExportClip>, cut: &Cut, frame: f64) -> Option<(usize_ => {}}}- clips.push(hold);- Some((clips.len() - 1, d))+ hold}/// The timing functions the transition shapes ride on, as `ExportKey` holds@@ -2381,10 +2491,10 @@ mod tests {.all(|(got, want)| (i16::from(*got) - i16::from(want)).abs() <= 40)};for (kind, time, x, want) in [- ("wipe-left", 1.5, 0.2, [220, 30, 30]),- ("wipe-left", 1.5, 0.8, [30, 30, 220]),- ("wipe-right", 1.5, 0.2, [30, 30, 220]),- ("wipe-right", 1.5, 0.8, [220, 30, 30]),+ ("wipe-left", 2.0, 0.2, [220, 30, 30]),+ ("wipe-left", 2.0, 0.8, [30, 30, 220]),+ ("wipe-right", 2.0, 0.2, [30, 30, 220]),+ ("wipe-right", 2.0, 0.8, [220, 30, 30]),("fade-black", 2.0, 0.5, [0, 0, 0]),] {let got = look(kind, time, x);@@ -2818,26 +2928,63 @@ mod tests {}}- #[test]- fn a_cross_fade_overlaps_the_incoming_clip_on_its_own_lane() {+ /// Two clips cut at 4 s on one track, the incoming one with two+ /// seconds of footage before its in-point and the outgoing one with+ /// six past its out-point, unless a test takes them away.+ fn cut_with_handles() -> Vec<ExportClip> {let mut clips = vec![clip("video", 0, 0.0, 4.0, 0.0),clip("video", 0, 4.0, 4.0, 2.0),];+ clips[0].media_duration = Some(10.0);+ clips+ }++ #[test]+ fn a_cross_fade_is_centred_on_the_cut() {+ let mut clips = cut_with_handles();clips[1].transition = spec("cross-fade", 1.0);resolve_transitions(&mut clips, FrameRate::THIRTY);let b = &clips[1];- assert_eq!(b.start, 3.0, "extends backwards over the cut");- assert_eq!(b.duration, 5.0);+ assert_eq!(b.start, 3.5, "starts half the transition before the cut");+ assert_eq!(b.duration, 4.5);assert_eq!(- b.source_start, 1.0,+ b.source_start, 1.5,"consumes the handle before the in-point");assert_eq!(b.video_fade_in, 1.0);assert_eq!(b.fade_in, 1.0, "sound rides the picture");- assert_eq!(clips[0].track, 0, "outgoing stays on its doubled lane");- assert_eq!(b.track, 1, "incoming sits directly above it");+ assert_eq!(b.track, 1, "incoming sits directly above the outgoing clip");++ let a = &clips[0];+ assert_eq!(+ (a.start, a.duration, a.source_start),+ (0.0, 4.5, 0.0),+ "runs on half the transition past the cut"+ );+ assert_eq!(a.fade_out, 1.0, "and its sound fades out across it");+ assert_eq!(a.track, 0, "outgoing stays on its doubled lane");+ assert_eq!(clips.len(), 2, "no hold: both sides have footage");+ }++ /// A clip lengthened for a transition keeps its keys at the instants+ /// they were at, although a key's place is a fraction of the clip.+ #[test]+ fn an_extended_clip_keeps_its_keys_where_they_were() {+ let mut clips = cut_with_handles();+ for (n, at) in [1.0, 0.0].into_iter().enumerate() {+ clips[n].animation.push(ExportKey {+ property: "scale".to_owned(),+ at,+ value: 2.0,+ ease: linear_ease(),+ });+ }+ clips[1].transition = spec("cross-fade", 1.0);+ resolve_transitions(&mut clips, FrameRate::THIRTY);+ assert_eq!(keys_on(&clips[0], "scale"), vec![(4.0 / 4.5, 2.0)]);+ assert_eq!(keys_on(&clips[1], "scale"), vec![(0.5 / 4.5, 2.0)]);}#[test]@@ -2845,147 +2992,126 @@ mod tests {// A transition named by its package id (not one of the seven legacy// strings) takes the new path: the same overlap a dissolve gets, plus// a `TransitionSpan` for the compositor to combine over.- let mut clips = vec![- clip("video", 0, 0.0, 4.0, 0.0),- clip("video", 0, 4.0, 4.0, 2.0),- ];+ let mut clips = cut_with_handles();clips[1].transition = spec("concat.dissolve", 1.0);let spans = resolve_transitions(&mut clips, FrameRate::THIRTY);let b = &clips[1];- assert_eq!(- b.start, 3.0,- "extends backwards over the cut, like a dissolve"- );- assert_eq!(b.duration, 5.0);+ assert_eq!(b.start, 3.5, "centred on the cut, like a dissolve");+ assert_eq!(b.duration, 4.5);assert_eq!(b.video_fade_in, 1.0, "the GPU-less fallback dissolve");assert_eq!(b.track, 1);+ assert_eq!(clips[0].duration, 4.5);assert_eq!(spans.len(), 1, "one packaged transition over the cut");let span = &spans[0];assert_eq!(span.id, "concat.dissolve");assert_eq!(span.to_track, 1, "the incoming clip's own lane");- assert_eq!(span.start, Rational::from_int(3));- assert_eq!(span.end, Rational::from_int(4));- assert!((span.progress(Rational::from_int(3)) - 0.0).abs() < 1e-9);- assert!((span.progress(Rational::new(35, 10)) - 0.5).abs() < 1e-9);- assert!((span.progress(Rational::from_int(4)) - 1.0).abs() < 1e-9);- }-- /// A clip with less footage before its in-point than the transition- /// is long keeps its place and its clock - winding the start back- /// without the clock played everything after the cut early and ran- /// the end off the file into black (#236) - and its first frame is- /// held on the lane above for the transition's length instead.+ assert_eq!(span.start, Rational::new(7, 2));+ assert_eq!(span.end, Rational::new(9, 2));+ assert!((span.progress(Rational::new(7, 2)) - 0.0).abs() < 1e-9);+ assert!((span.progress(Rational::from_int(4)) - 0.5).abs() < 1e-9);+ assert!((span.progress(Rational::new(9, 2)) - 1.0).abs() < 1e-9);+ }++ /// An incoming clip with less footage before its in-point than half+ /// the transition takes what it has - winding the start back further+ /// without the clock played everything after the cut early and ran the+ /// end off the file into black (#236) - and the rest of the overlap+ /// goes after the cut, where the outgoing clip runs on.#[test]- fn a_clip_without_the_handle_stays_put_and_its_first_frame_is_held() {- let mut clips = vec![- clip("video", 0, 0.0, 4.0, 0.0),- clip("video", 0, 4.0, 4.0, 0.25),- ];+ fn a_short_handle_leans_the_overlap_after_the_cut() {+ let mut clips = cut_with_handles();+ clips[1].source_start = 0.25;clips[1].fade_in = 0.25;clips[1].transition = spec("cross-fade", 2.0);resolve_transitions(&mut clips, FrameRate::THIRTY);let b = &clips[1];- assert_eq!((b.start, b.duration, b.source_start), (4.0, 4.0, 0.25));- assert_eq!(b.video_fade_in, 0.0, "the clip itself does not ramp");- assert_eq!(b.track, 0, "on its own lane, after the outgoing clip");- assert_eq!(b.fade_in, 0.25, "its own sound fade, not the dissolve's");-- assert_eq!(clips.len(), 3, "the hold is a clip of its own");- let hold = &clips[2];- assert!(hold.hold);- assert_eq!((hold.start, hold.duration), (2.0, 2.0));- assert_eq!(hold.source_start, 0.25, "the frame the clip starts on");- assert_eq!(hold.track, 1, "directly above the outgoing clip");- assert_eq!(hold.video_fade_in, 2.0, "the dissolve rides the hold");- assert!(hold.muted);- assert_eq!(hold.has_audio, Some(false));+ assert_eq!((b.start, b.duration, b.source_start), (3.75, 4.25, 0.0));+ assert_eq!(b.video_fade_in, 2.0);+ assert_eq!(b.track, 1);+ assert_eq!(b.fade_in, 2.0, "the dissolve's sound fade");+ assert_eq!(clips[0].duration, 5.75, "runs on for the other 1.75 s");+ assert_eq!(clips.len(), 2, "nothing is held");}#[test]- fn a_cross_fade_on_untrimmed_clip_holds_the_first_frame() {- let mut clips = vec![- clip("video", 0, 0.0, 4.0, 0.0),- clip("video", 0, 4.0, 4.0, 0.0),- ];+ fn an_untrimmed_incoming_clip_starts_the_overlap_at_the_cut() {+ let mut clips = cut_with_handles();+ clips[1].source_start = 0.0;clips[1].transition = spec("cross-fade", 1.0);resolve_transitions(&mut clips, FrameRate::THIRTY);let b = &clips[1];assert_eq!((b.start, b.duration, b.source_start), (4.0, 4.0, 0.0));- assert_eq!(b.video_fade_in, 0.0);- let hold = &clips[2];- assert_eq!(- (hold.start, hold.duration, hold.source_start),- (3.0, 1.0, 0.0)- );- assert_eq!(hold.video_fade_in, 1.0);+ assert_eq!(b.track, 1, "above the outgoing clip running on");+ assert_eq!(b.video_fade_in, 1.0);+ assert_eq!(clips[0].duration, 5.0);}+ /// An outgoing clip with no footage past its out-point - the file ends+ /// there, or its length is not known - ends at the cut, and its last+ /// frame is held beneath the incoming one for the rest of the overlap.#[test]- fn a_packaged_transition_on_untrimmed_clip_spans_the_hold() {- let mut clips = vec![- clip("video", 0, 0.0, 4.0, 0.0),- clip("video", 0, 4.0, 4.0, 0.0),- ];+ fn an_outgoing_clip_without_footage_past_its_end_is_held() {+ let mut clips = cut_with_handles();+ clips[0].media_duration = Some(4.0);clips[1].transition = spec("concat.dissolve", 1.0);let spans = resolve_transitions(&mut clips, FrameRate::THIRTY);- let b = &clips[1];- assert_eq!((b.start, b.duration, b.source_start), (4.0, 4.0, 0.0));+ let a = &clips[0];+ assert_eq!((a.start, a.duration), (0.0, 4.0), "ends at the cut");+ assert_eq!(clips.len(), 3, "the hold is a clip of its own");let hold = &clips[2];assert!(hold.hold);- assert_eq!((hold.start, hold.duration), (3.0, 1.0));- assert_eq!(hold.video_fade_in, 1.0);+ assert_eq!((hold.start, hold.duration), (4.0, 0.5));+ assert_eq!(+ hold.source_start,+ 4.0 - 1.0 / 30.0,+ "the frame the clip ends on"+ );+ assert_eq!(hold.track, 0, "on the outgoing clip's lane");+ assert!(hold.muted);+ assert_eq!(hold.has_audio, Some(false));++ let b = &clips[1];+ assert_eq!((b.start, b.track), (3.5, 1));assert_eq!(spans.len(), 1);- assert_eq!(spans[0].start, Rational::from_int(3));- assert_eq!(spans[0].end, Rational::from_int(4));- assert_eq!(spans[0].to_track, 1, "the hold's lane");+ assert_eq!(spans[0].start, Rational::new(7, 2));+ assert_eq!(spans[0].end, Rational::new(9, 2));+ assert_eq!(spans[0].to_track, 1);}- /// A push into a clip with no handle slides the hold in, and the clip- /// then starts where the hold leaves it; a keyed placement on the clip- /// is held at its head, not played again over the pre-roll.+ /// A push cannot slide a held frame - the hold carries no keys - so+ /// over an outgoing clip without footage past its end it dissolves;+ /// a keyed placement on the clip is held where its ride leaves it.#[test]- fn a_push_without_the_handle_rides_the_hold() {- let mut clips = vec![- clip("video", 0, 0.0, 4.0, 0.0),- clip("video", 0, 4.0, 4.0, 0.0),- ];- clips[1].animation.push(ExportKey {- property: "scale".to_owned(),- at: 0.0,- value: 2.0,- ease: linear_ease(),- });- clips[1].animation.push(ExportKey {- property: "scale".to_owned(),- at: 1.0,- value: 1.0,- ease: linear_ease(),- });+ fn a_push_over_a_held_outgoing_frame_becomes_a_dissolve() {+ let mut clips = cut_with_handles();+ clips[0].media_duration = None;+ for (at, value) in [(0.0, 1.0), (1.0, 2.0)] {+ clips[0].animation.push(ExportKey {+ property: "scale".to_owned(),+ at,+ value,+ ease: linear_ease(),+ });+ }clips[1].transition = spec("push", 1.0);resolve_transitions(&mut clips, FrameRate::THIRTY);let hold = &clips[2];- assert_eq!(keys_on(hold, "offsetX"), vec![(0.0, 1.0), (1.0, 0.0)]);- assert!(- keys_on(hold, "scale").is_empty(),- "the ride stays on the clip"- );- assert_eq!(hold.scale, 2.0, "held where the ride starts");- assert_eq!(- keys_on(&clips[0], "offsetX"),- vec![(0.75, 0.0), (1.0, -1.0)]- );+ assert!(hold.animation.is_empty(), "the ride stays on the clip");+ assert_eq!(hold.scale, 2.0, "held where the ride ends");+ assert_eq!(clips[1].video_fade_in, 1.0, "falls back to the dissolve");+ assert!(keys_on(&clips[1], "offsetX").is_empty());+ assert!(keys_on(&clips[0], "offsetX").is_empty());assert_eq!(- keys_on(&clips[1], "scale").len(),+ keys_on(&clips[0], "scale").len(),2,"the user's keys are untouched");- assert!(keys_on(&clips[1], "offsetX").is_empty());}#[test]@@ -3015,27 +3141,25 @@ mod tests {#[test]fn a_push_slides_both_pictures_across_the_overlap() {- let mut clips = vec![- clip("video", 0, 0.0, 4.0, 0.0),- clip("video", 0, 4.0, 4.0, 2.0),- ];+ let mut clips = cut_with_handles();clips[1].transition = spec("push", 1.0);resolve_transitions(&mut clips, FrameRate::THIRTY);- // The overlap is the dissolve's: a second of pre-roll on the lane- // above, sound fading in with it - but no picture fade.+ // The overlap is the dissolve's: half a second either side of the+ // cut, the incoming clip on the lane above, sound fading in with+ // it - but no picture fade.let b = &clips[1];- assert_eq!((b.start, b.duration, b.source_start), (3.0, 5.0, 1.0));+ assert_eq!((b.start, b.duration, b.source_start), (3.5, 4.5, 1.5));assert_eq!(b.track, 1);assert_eq!(b.fade_in, 1.0);assert_eq!(b.video_fade_in, 0.0, "a push does not dissolve");// The incoming picture comes in from a frame's width to the right- // over its first second (a fifth of its new length).- assert_eq!(keys_on(b, "offsetX"), vec![(0.0, 1.0), (0.2, 0.0)]);+ // over its first second.+ assert_eq!(keys_on(b, "offsetX"), vec![(0.0, 1.0), (1.0 / 4.5, 0.0)]);// The outgoing one leaves to the left over its last second.assert_eq!(keys_on(&clips[0], "offsetX"),- vec![(0.75, 0.0), (1.0, -1.0)]+ vec![(1.0 - 1.0 / 4.5, 0.0), (1.0, -1.0)]);// Both ride the same ease, which is what keeps them edge to edge.assert_eq!(clips[0].animation[1].ease, clips[1].animation[1].ease);@@ -3044,10 +3168,7 @@ mod tests {#[test]fn a_push_over_a_clip_the_user_keyed_becomes_a_dissolve() {- let mut clips = vec![- clip("video", 0, 0.0, 4.0, 0.0),- clip("video", 0, 4.0, 4.0, 2.0),- ];+ let mut clips = cut_with_handles();clips[0].animation.push(ExportKey {property: "offsetX".to_owned(),at: 0.5,@@ -3070,15 +3191,18 @@ mod tests {#[test]fn a_zoom_scales_both_under_a_dissolve() {- let mut clips = vec![- clip("video", 0, 0.0, 4.0, 0.0),- clip("video", 0, 4.0, 4.0, 2.0),- ];+ let mut clips = cut_with_handles();clips[1].transition = spec("zoom", 1.0);resolve_transitions(&mut clips, FrameRate::THIRTY);assert_eq!(clips[1].video_fade_in, 1.0);- assert_eq!(keys_on(&clips[1], "scale"), vec![(0.0, 1.25), (0.2, 1.0)]);- assert_eq!(keys_on(&clips[0], "scale"), vec![(0.75, 1.0), (1.0, 1.4)]);+ assert_eq!(+ keys_on(&clips[1], "scale"),+ vec![(0.0, 1.25), (1.0 / 4.5, 1.0)]+ );+ assert_eq!(+ keys_on(&clips[0], "scale"),+ vec![(1.0 - 1.0 / 4.5, 1.0), (1.0, 1.4)]+ );}#[test]@@ -3090,7 +3214,7 @@ mod tests {clips[1].transition = spec("wipe-right", 0.5);resolve_transitions(&mut clips, FrameRate::THIRTY);let b = &clips[1];- assert_eq!((b.start, b.duration), (3.5, 4.5));+ assert_eq!((b.start, b.duration), (3.75, 4.25));assert_eq!(b.video_fade_in, 0.0, "the edge does the revealing");assert_eq!(b.transition_shapes,diff --git a/src/crates/concat-host/tests/export.rs b/src/crates/concat-host/tests/export.rsindex b80d03f7..868c840d 100644--- a/src/crates/concat-host/tests/export.rs+++ b/src/crates/concat-host/tests/export.rs@@ -952,13 +952,13 @@ fn fades_and_wipes_reach_the_picture() {studio.export(&format!("transition {kind}"))};- // The wipes overlap the blue clip onto the red one's last second.+ // The wipes overlap the two clips for the second centred on the cut.let wiped = with(&mut studio, "wipe-left");wiped.expect_colours(0.5, &[((0.5, 0.5), red)]);- wiped.expect_colours(1.5, &[((0.2, 0.5), red), ((0.8, 0.5), blue)]);- wiped.expect_colours(2.5, &[((0.5, 0.5), blue)]);+ wiped.expect_colours(2.0, &[((0.2, 0.5), red), ((0.8, 0.5), blue)]);+ wiped.expect_colours(2.9, &[((0.5, 0.5), blue)]);let wiped = with(&mut studio, "wipe-right");- wiped.expect_colours(1.5, &[((0.2, 0.5), blue), ((0.8, 0.5), red)]);+ wiped.expect_colours(2.0, &[((0.2, 0.5), blue), ((0.8, 0.5), red)]);// The fades split the second across the cut, and do not overlap.for (kind, colour) in [("fade-black", [0, 0, 0]), ("fade-white", [255, 255, 255])] {