Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(compositor): keep Full Camera full across a trim inside it

EtienneLescot1af61821b2d3
diff --git a/crates/compositor/src/compositor_linux.rs b/crates/compositor/src/compositor_linux.rs
index f7c5204b6..2f2390c11 100644
--- a/crates/compositor/src/compositor_linux.rs
+++ b/crates/compositor/src/compositor_linux.rs
@@ -4888,6 +4888,8 @@ mod tests {
clip_index: None,
start_sec: 2.0,
end_sec: 8.0,
+ continues_before: false,
+ continues_after: false,
});
// 5 s : la montee (~1 s) est finie, le retour (~1,5 s) n'a pas commence.
comp.set_timeline_time(Some(5.0));
diff --git a/crates/compositor/src/regions.rs b/crates/compositor/src/regions.rs
index d14c37773..d7881ba07 100644
--- a/crates/compositor/src/regions.rs
+++ b/crates/compositor/src/regions.rs
@@ -969,6 +969,11 @@ pub fn zoom_state_in(
/// `endSec`. Fenêtres bornées à la moitié de la durée de la région pour que les régions courtes
/// s'animent pleinement sans déborder. Fenêtres mesurées à l'écran, comme celles du zoom
/// (`ScreenClock`). Le rect et la bulle y appliquent chacun leur courbe.
+///
+/// Un morceau coupé par un trim (`continues_before` / `continues_after`) n'a pas de transition
+/// du côté de la coupe, bord compris : la région reste plein cadre à travers le trim, montée à
+/// son vrai début seulement, descente à sa vraie fin seulement. Le côté restant prend alors tout
+/// le span au lieu de sa moitié.
fn camera_fullscreen_region_phase(
region: &SceneCameraFullscreenRegion,
t: f32,
@@ -976,13 +981,20 @@ fn camera_fullscreen_region_phase(
) -> f32 {
let start = region.start_sec as f32;
let end = region.end_sec as f32;
- if t <= start || t >= end {
+ let before_start = if region.continues_before { t < start } else { t <= start };
+ let after_end = if region.continues_after { t > end } else { t >= end };
+ if before_start || after_end {
return 0.0;
}
let (start, end, t) = (clock.at(start), clock.at(end), clock.at(t));
- let half = (end - start) * 0.5;
- let lead_in = TRANSITION_WINDOW_S.min(half);
- let lead_out = FULLSCREEN_LEAD_OUT_WINDOW_S.min(half);
+ let span = end - start;
+ let half = span * 0.5;
+ let (lead_in, lead_out) = match (region.continues_before, region.continues_after) {
+ (false, false) => (TRANSITION_WINDOW_S.min(half), FULLSCREEN_LEAD_OUT_WINDOW_S.min(half)),
+ (false, true) => (TRANSITION_WINDOW_S.min(span), 0.0),
+ (true, false) => (0.0, FULLSCREEN_LEAD_OUT_WINDOW_S.min(span)),
+ (true, true) => (0.0, 0.0),
+ };
let lead_in_end = start + lead_in;
let lead_out_start = end - lead_out;
if t < lead_in_end {
@@ -1977,6 +1989,8 @@ mod zoom_focus_tests {
clip_index: None,
start_sec: 18.0 * k,
end_sec: 22.0 * k,
+ continues_before: false,
+ continues_after: false,
}]
};
let (sped, plain) = (zooms(4.0), zooms(1.0));
@@ -2003,11 +2017,52 @@ mod zoom_focus_tests {
}
}
+ fn full_camera_piece(
+ clip_index: Option<usize>,
+ start_sec: f64,
+ end_sec: f64,
+ continues_before: bool,
+ continues_after: bool,
+ ) -> SceneCameraFullscreenRegion {
+ SceneCameraFullscreenRegion {
+ clip_index,
+ start_sec,
+ end_sec,
+ continues_before,
+ continues_after,
+ }
+ }
+
+ /// Un trim au milieu d'une région Full Camera la coupe en deux morceaux, un par segment gardé
+ /// (`projectRegionsToSource`, TS). Chacun est filtré sur son clip (`for_clip_window`) : la
+ /// webcam ne doit pas revenir dans son coin avant la coupe ni regrandir après. Montée au vrai
+ /// début, descente à la vraie fin, plein cadre de part et d'autre du trim — comme un zoom.
+ #[test]
+ fn a_trim_inside_full_camera_keeps_it_full_across_the_cut() {
+ // Source [10, 20], trim [14, 16] : morceaux [10, 14] (clip 0) et [16, 20] (clip 1).
+ let before = [full_camera_piece(Some(0), 10.0, 14.0, false, true)];
+ let after = [full_camera_piece(Some(1), 16.0, 20.0, true, false)];
+ let clock = ScreenClock::default();
+ let at = |r: &[SceneCameraFullscreenRegion], t: f32| {
+ (camera_fullscreen_progress_at(r, t, &clock), camera_fullscreen_shape_at(r, t, &clock))
+ };
+ let frame = 1.0 / 60.0;
+ assert_eq!(at(&before, 14.0 - frame), (1.0, 0.0), "dernière frame avant la coupe");
+ assert_eq!(at(&before, 14.0), (1.0, 0.0), "bord de coupe, fin");
+ assert_eq!(at(&after, 16.0), (1.0, 0.0), "première frame après la coupe");
+ // Les vraies transitions restent, à leur durée pleine (pas la moitié d'un morceau).
+ assert!(at(&before, 10.0 + TRANSITION_WINDOW_S / 2.0).0 < 1.0, "montée au vrai début");
+ assert_eq!(at(&before, 10.0 + TRANSITION_WINDOW_S).0, 1.0);
+ assert!(at(&after, 20.0 - frame).0 < 1.0, "descente à la vraie fin");
+ assert_eq!(at(&after, 20.0 - FULLSCREEN_LEAD_OUT_WINDOW_S).0, 1.0);
+ assert_eq!(at(&after, 20.0).0, 0.0);
+ }
+
/// Les coins suivent la phase, pas le rect. Avec `1 - progrès`, ils étaient carrés presque
/// tout du long de la montée et ne revenaient qu'à la toute fin du retour.
#[test]
fn full_camera_corners_dissolve_late_and_come_back_early() {
- let r = [SceneCameraFullscreenRegion { clip_index: None, start_sec: 10.0, end_sec: 20.0 }];
+ let r = [full_camera_piece(None, 10.0, 20.0, false, false)];
let clock = ScreenClock::default();
let at = |t: f32| {
(camera_fullscreen_progress_at(&r, t, &clock), camera_fullscreen_shape_at(&r, t, &clock))
diff --git a/crates/compositor/src/scene.rs b/crates/compositor/src/scene.rs
index bddd7d55c..94c405d22 100644
--- a/crates/compositor/src/scene.rs
+++ b/crates/compositor/src/scene.rs
@@ -537,6 +537,14 @@ pub struct SceneCameraFullscreenRegion {
pub clip_index: Option<usize>,
pub start_sec: f64,
pub end_sec: f64,
+ /// La région commence avant ce morceau : un trim ou une frontière de clip l'a coupée, et
+ /// `start_sec` est un bord de coupe, pas son vrai début. Pas de montée ici, plein cadre dès
+ /// la première frame, comme un zoom dont l'ease-in tombe hors du clip.
+ #[serde(default)]
+ pub continues_before: bool,
+ /// Pendant de `continues_before` à la fin : pas de descente au bord de la coupe.
+ #[serde(default)]
+ pub continues_after: bool,
}
/// Rendu du curseur.
diff --git a/src/lib/ai-edition/timeline/timelineMap.test.ts b/src/lib/ai-edition/timeline/timelineMap.test.ts
index 675601374..18c6fd142 100644
--- a/src/lib/ai-edition/timeline/timelineMap.test.ts
+++ b/src/lib/ai-edition/timeline/timelineMap.test.ts
@@ -99,8 +99,22 @@ describe("projectRegionsToSource", () => {
});
const out = projectRegionsToSource([region("r", 3, 7, "keep")], [c1, c2], [c1, c2], () => "r2");
expect(out).toEqual([
- { id: "r", startMs: 103000, endMs: 105000, clipIndex: 0, payload: "keep" },
- { id: "r2", startMs: 200000, endMs: 202000, clipIndex: 1, payload: "keep" },
+ {
+ id: "r",
+ startMs: 103000,
+ endMs: 105000,
+ clipIndex: 0,
+ payload: "keep",
+ continuesAfter: true,
+ },
+ {
+ id: "r2",
+ startMs: 200000,
+ endMs: 202000,
+ clipIndex: 1,
+ payload: "keep",
+ continuesBefore: true,
+ },
]);
});
@@ -117,8 +131,8 @@ describe("projectRegionsToSource", () => {
const segments = resolvePlaybackSegments([c], [trim("a", 4, 6)]);
const out = projectRegionsToSource([region("r", 3, 8)], segments, [c], () => "r2");
expect(out).toEqual([
- { id: "r", startMs: 3000, endMs: 4000, clipIndex: 0 },
- { id: "r2", startMs: 6000, endMs: 8000, clipIndex: 1 },
+ { id: "r", startMs: 3000, endMs: 4000, clipIndex: 0, continuesAfter: true },
+ { id: "r2", startMs: 6000, endMs: 8000, clipIndex: 1, continuesBefore: true },
]);
});
@@ -281,8 +295,8 @@ describe("projectRegionsToSource", () => {
};
const out = projectRegionsToSource([anchored], segments, [c], () => "r2");
expect(out).toEqual([
- { ...anchored, id: "r", startMs: 3000, endMs: 4000, clipIndex: 0 },
- { ...anchored, id: "r2", startMs: 6000, endMs: 8000, clipIndex: 1 },
+ { ...anchored, id: "r", startMs: 3000, endMs: 4000, clipIndex: 0, continuesAfter: true },
+ { ...anchored, id: "r2", startMs: 6000, endMs: 8000, clipIndex: 1, continuesBefore: true },
]);
});
diff --git a/src/lib/ai-edition/timeline/timelineMap.ts b/src/lib/ai-edition/timeline/timelineMap.ts
index 577f74241..8a7f763fe 100644
--- a/src/lib/ai-edition/timeline/timelineMap.ts
+++ b/src/lib/ai-edition/timeline/timelineMap.ts
@@ -599,6 +599,14 @@ function cutRegionSourceSpan<T extends { startMs: number; endMs: number } & Regi
return { clipId: clip.id, startSec: toSource(lo), endSec: toSource(hi) };
}
+/** A region as `projectRegionsToSource` emits it. */
+type ProjectedRegion<T> = T & {
+ clipIndex?: number;
+ underTrim?: boolean;
+ continuesBefore?: boolean;
+ continuesAfter?: boolean;
+};
+
/**
* Resolve regions (zoom / annotation / speed / camera-fullscreen) onto the SOURCE-ms
* ranges the native compositor matches against, plus the `clipIndex` into the
@@ -613,7 +621,10 @@ function cutRegionSourceSpan<T extends { startMs: number; endMs: number } & Regi
* extent, kept because migration deliberately preserves un-anchorable regions.
*
* In both paths a region split across two kept segments by a trim yields one entry per
- * segment (fresh id for the extra copies, original id on the first).
+ * segment (fresh id for the extra copies, original id on the first). A piece whose start or
+ * end is a segment edge rather than the region's own edge says so with `continuesBefore` /
+ * `continuesAfter` (omitted when false): Full Camera, whose ramps sit inside its span, must not
+ * ramp at a cut. Zooms need nothing, their envelopes lie outside the span and so outside the clip.
*
* A region overlapping no visible segment lies entirely under a trim: it is emitted ONCE,
* marked `underTrim`, on its own source span and borrowing the `clipIndex` of the kept
@@ -645,16 +656,21 @@ export function projectRegionsToSource<
visibleSegments: AxcutClip[],
rawClips: AxcutClip[],
makeId: () => string,
-): (T & { clipIndex?: number; underTrim?: boolean })[] {
+): ProjectedRegion<T>[] {
// RAW extents + owning raw clip per visible segment. Both are only consulted by the
// path that needs them (raw fallback / anchor match), but resolving them once keeps
// the per-region loop free of repeated lookups.
const spans = visibleSegments.map((seg) => segmentRawSpanSec(seg, rawClips));
const segmentRawClipIds = visibleSegments.map((seg) => findRawClipForSegment(seg, rawClips)?.id);
- const out: (T & { clipIndex?: number; underTrim?: boolean })[] = [];
+ const out: ProjectedRegion<T>[] = [];
for (const region of regions) {
let emitted = 0;
- const emit = (clipIndex: number, srcStartSec: number, srcEndSec: number, underTrim = false) => {
+ const emit = (
+ clipIndex: number,
+ srcStartSec: number,
+ srcEndSec: number,
+ flags: { underTrim?: boolean; continuesBefore?: boolean; continuesAfter?: boolean } = {},
+ ) => {
out.push({
...region,
id: emitted === 0 ? region.id : makeId(),
@@ -663,7 +679,9 @@ export function projectRegionsToSource<
clipIndex,
// Omitted rather than sent as `false`: every payload without a trim under a
// modifier stays byte-for-byte what it was.
- ...(underTrim ? { underTrim: true } : {}),
+ ...(flags.underTrim ? { underTrim: true } : {}),
+ ...(flags.continuesBefore ? { continuesBefore: true } : {}),
+ ...(flags.continuesAfter ? { continuesAfter: true } : {}),
});
emitted += 1;
};
@@ -681,7 +699,7 @@ export function projectRegionsToSource<
const s = Math.max(lo, seg.sourceStartSec);
const e = Math.min(hi, seg.sourceEndSec ?? seg.sourceStartSec);
if (e <= s) return;
- emit(clipIndex, s, e);
+ emit(clipIndex, s, e, { continuesBefore: s > lo, continuesAfter: e < hi });
});
} else {
// UNANCHORED — migration kept this region rather than dropping it (see
@@ -698,6 +716,7 @@ export function projectRegionsToSource<
clipIndex,
seg.sourceStartSec + (s - segRawStart),
seg.sourceStartSec + (e - segRawStart),
+ { continuesBefore: s > lo, continuesAfter: e < hi },
);
});
}
@@ -710,7 +729,7 @@ export function projectRegionsToSource<
? cutAddressingSegmentIndex(visibleSegments, segmentRawClipIds, cut.clipId, cut.startSec)
: -1;
if (cut && clipIndex >= 0 && cut.endSec > cut.startSec) {
- emit(clipIndex, cut.startSec, cut.endSec, true);
+ emit(clipIndex, cut.startSec, cut.endSec, { underTrim: true });
}
}
// No segments AT ALL: no layout to resolve against, so the region passes through on
diff --git a/src/native/sceneDescription.test.ts b/src/native/sceneDescription.test.ts
index 04a2aeeaa..1433edc02 100644
--- a/src/native/sceneDescription.test.ts
+++ b/src/native/sceneDescription.test.ts
@@ -947,8 +947,38 @@ describe("buildSceneDescription.cameraFullscreenRegions", () => {
});
const { cameraFullscreenRegions } = buildSceneDescription(doc);
expect(cameraFullscreenRegions).toEqual([
- { startSec: 103, endSec: 105, clipIndex: 0 },
- { startSec: 200, endSec: 202, clipIndex: 1 },
+ { startSec: 103, endSec: 105, clipIndex: 0, continuesAfter: true },
+ { startSec: 200, endSec: 202, clipIndex: 1, continuesBefore: true },
+ ]);
+ });
+
+ it("marks the cut edges of a region a trim splits, so it stays full across the cut", () => {
+ // Region raw [2, 8] over src [0, 10], trim removes [4, 6]. Each piece ramps only at the
+ // region's own edge: lead-in on the first, lead-out on the second, none at the cut.
+ const doc = makeDoc({
+ assets: [makeAsset({ id: "a", originalPath: "/a.mp4" })],
+ clips: [
+ makeClip({
+ id: "c1",
+ assetId: "a",
+ sourceStartSec: 0,
+ sourceEndSec: 10,
+ timelineStartSec: 0,
+ timelineEndSec: 10,
+ }),
+ ],
+ timeline: {
+ trimRanges: [
+ { id: "t1", assetId: "a", startSec: 4, endSec: 6, reason: "", origin: "user" },
+ ],
+ },
+ legacyEditor: {
+ cameraFullscreenRegions: [{ id: "cf1", startMs: 2000, endMs: 8000 }],
+ },
+ });
+ expect(buildSceneDescription(doc).cameraFullscreenRegions).toEqual([
+ { startSec: 2, endSec: 4, clipIndex: 0, continuesAfter: true },
+ { startSec: 6, endSec: 8, clipIndex: 1, continuesBefore: true },
]);
});
diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.ts
index 1f3d36314..e029aa8f2 100644
--- a/src/native/sceneDescription.ts
+++ b/src/native/sceneDescription.ts
@@ -128,6 +128,12 @@ export interface SceneCameraFullscreenRegion {
/** See `SceneZoomRegion.underTrim`. Full-Camera needs no extra gate — its envelope is
* already contained in `[startSec, endSec]` — so this only carries the intent. */
underTrim?: boolean;
+ /** A cut (trim or clip boundary) split the region and this piece's start is that cut, not
+ * the region's own start: native skips the lead-in so the camera stays full across the
+ * cut. Omitted when false. */
+ continuesBefore?: boolean;
+ /** Same at the end: no lead-out at the cut. Omitted when false. */
+ continuesAfter?: boolean;
}
/** A speed region projected onto each clip's source time. The native compositor matches
@@ -1423,6 +1429,8 @@ export function buildSceneDescription(
endSec: region.endMs / 1000,
clipIndex: region.clipIndex,
...(region.underTrim ? { underTrim: true } : {}),
+ ...(region.continuesBefore ? { continuesBefore: true } : {}),
+ ...(region.continuesAfter ? { continuesAfter: true } : {}),
})),
// Speed is the one modifier with nothing to show for itself on a parked playhead: a
// still frame has no rate. So the entries under a trim are dropped here rather than
diff --git a/technical-documentation/architecture/timeline-model.md b/technical-documentation/architecture/timeline-model.md
index 9cae9941e..f77a37f7b 100644
--- a/technical-documentation/architecture/timeline-model.md
+++ b/technical-documentation/architecture/timeline-model.md
@@ -72,7 +72,7 @@ Every public export of
| `dropPillById` / `dropPillsByIds` (`:368` / `:377`) | Delete every region under a pill (resolved from the merge rule) | regions → regions |
| `replacePillSpan` (`:398`) | Move/resize a pill: clamp against different-identity neighbours, then re-anchor to the clamped span, keeping the id of the member it was called with | pill + clip layout → re-anchored fragments |
| `segmentRawSpanSec` (`:484`) | One kept playback segment → its RAW-virtual extent | segment → RAW span |
-| `projectRegionsToSource` (`:641`) | Region array → source-ms entries with `clipIndex` for native (anchored path uses anchor; unanchored path falls back to RAW mapping through each segment's own raw extent — never drops an un-anchorable region onto an unrelated clip). A region wholly under a trim is emitted once, marked `underTrim`, addressed by the segment the cut interrupts | RAW/anchored → source + `clipIndex` |
+| `projectRegionsToSource` (`:641`) | Region array → source-ms entries with `clipIndex` for native (anchored path uses anchor; unanchored path falls back to RAW mapping through each segment's own raw extent — never drops an un-anchorable region onto an unrelated clip). A region wholly under a trim is emitted once, marked `underTrim`, addressed by the segment the cut interrupts. A region a cut splits marks each piece's cut edge `continuesBefore` / `continuesAfter`, so Full Camera ramps only at its own edges and stays full across the cut | RAW/anchored → source + `clipIndex` |
| `resolveNativePosition` (`:759`) | RAW-virtual playhead → `{clip, clipIndex, sourceTimeSec}` for the active native decoder + paired camera (over a trimmed-out stretch it presents the removed frames themselves, borrowing the same segment index the modifiers under that cut borrow) | RAW-virtual → source + `clipIndex` |
The two **universal region rules** every region kind obeys are expressed once in this