Open source CapCut alternative.
TypeScript
feat(site): add six transition styles between cut clips
David Le51cc55482942
diff --git a/site/src/cut/components/Inspector.tsx b/site/src/cut/components/Inspector.tsxindex 6e5a3719..4e364dc6 100644--- a/site/src/cut/components/Inspector.tsx+++ b/site/src/cut/components/Inspector.tsx@@ -24,18 +24,20 @@ import { writeTextStyle } from "@/cut/lib/textStyle";import { formatTime } from "@/cut/lib/time";import {FONTS,- isFullRect,LAYOUTS,rectOf,regionLabel,SPEED_MAX,SPEED_MIN,TRANSITION_MAX,+ TRANSITION_STYLE_IDS,+ TRANSITION_STYLE_LABELS,type AudioClip,type FrameRect,type LayoutId,type OverlayClip,type TextOverlay,+ type TransitionStyle,type VideoClip,} from "@/cut/lib/types";import { cn } from "@/lib/utils";@@ -275,23 +277,48 @@ function ClipPanel({ clip }: { clip: VideoClip }) {<Value className="w-9 text-right text-muted-foreground">{speed.toFixed(2)}×</Value></Row>{hasNext && (- <Row label="Crossfade">- <Slider- className="clip-xfade data-horizontal:w-24"- min={0}- max={TRANSITION_MAX}- step={0.1}- value={xfade}- onValueChange={(v) => setXfadeDraft(Number(v))}- onValueCommitted={() => {- if (xfadeDraft != null) useEditor.getState().setClipTransition(clip.id, xfadeDraft);- setXfadeDraft(null);- }}- />- <Value className="w-9 text-right text-muted-foreground">- {xfade < 0.05 ? "Off" : `${xfade.toFixed(1)}s`}- </Value>- </Row>+ <>+ <Row label="Transition">+ <Select+ value={clip.transitionStyle ?? "crossfade"}+ onValueChange={(v) =>+ // Picking a style with the length still at zero turns the+ // transition on at a sensible default.+ useEditor+ .getState()+ .setClipTransition(clip.id, xfade >= 0.05 ? xfade : 0.5, v as TransitionStyle)+ }+ >+ <SelectTrigger className="clip-transition-style h-7 w-[8.5rem] text-[12px]">+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ {TRANSITION_STYLE_IDS.map((id) => (+ <SelectItem key={id} value={id} className="text-[12px]">+ {TRANSITION_STYLE_LABELS[id]}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ </Row>+ <Row label="Length">+ <Slider+ className="clip-xfade data-horizontal:w-24"+ min={0}+ max={TRANSITION_MAX}+ step={0.1}+ value={xfade}+ onValueChange={(v) => setXfadeDraft(Number(v))}+ onValueCommitted={() => {+ if (xfadeDraft != null) useEditor.getState().setClipTransition(clip.id, xfadeDraft);+ setXfadeDraft(null);+ }}+ />+ <Value className="w-9 text-right text-muted-foreground">+ {xfade < 0.05 ? "Off" : `${xfade.toFixed(1)}s`}+ </Value>+ </Row>+ </>)}<Row label="Mute audio"><Switchdiff --git a/site/src/cut/components/Timeline.tsx b/site/src/cut/components/Timeline.tsxindex bfbfe068..95bf7e4f 100644--- a/site/src/cut/components/Timeline.tsx+++ b/site/src/cut/components/Timeline.tsx@@ -1,7 +1,7 @@"use client";import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";-import { AudioLines, Blend, Check, EllipsisVertical, FolderPlus, Loader2, Pause, Play, Plus, Scissors, SkipBack, Trash2, Type, VolumeX } from "lucide-react";+import { AudioLines, Blend, Check, EllipsisVertical, Expand, FolderPlus, Loader2, Pause, Play, Plus, Scissors, SkipBack, Sunrise, Sunset, Trash2, Type, VolumeX, ZoomIn, ZoomOut, type LucideIcon } from "lucide-react";import { Button } from "@/components/ui/button";import {DropdownMenu,@@ -25,9 +25,19 @@ import { ensurePeaks } from "@/cut/lib/media";import { clipLen, clipSpeed, getClipSpans, projectDuration, TIMELINE_H_MAX, useEditor } from "@/cut/lib/store";import type { VideoTrackPlacement } from "@/cut/lib/store";import { formatTime, formatTimecode } from "@/cut/lib/time";-import type { AudioClip, ClipSpan, MediaAsset, OverlayClip, SubtitleCue, TextOverlay } from "@/cut/lib/types";+import { TRANSITION_STYLE_LABELS } from "@/cut/lib/types";+import type { AudioClip, ClipSpan, MediaAsset, OverlayClip, SubtitleCue, TextOverlay, TransitionStyle } from "@/cut/lib/types";import { cn } from "@/lib/utils";+const TRANSITION_ICONS: Record<TransitionStyle, LucideIcon> = {+ crossfade: Blend,+ crosszoom: Expand,+ zoomin: ZoomIn,+ zoomout: ZoomOut,+ fadein: Sunrise,+ fadeout: Sunset,+};+const VIDEO_H = 64;const OVERLAY_H = VIDEO_H; // upper video tracks match the base row heightconst AUDIO_H = 44;@@ -741,11 +751,16 @@ export function Timeline() {onDragActive={setVideoDragging}/>))}- {/* Dissolve badge, floating in the gutter where the two clips meet- (the overlap midpoint), vertically centered on the clip row. */}+ {/* Transition badge, floating in the gutter where the two clips+ meet (the overlap midpoint; a hard cut for edge styles),+ vertically centered on the clip row. */}{!clipDrag &&- spans.map((span) =>- span.transitionOut > 0 ? (+ spans.map((span, i) => {+ const d = span.clip.transition ?? 0;+ if (!spans[i + 1] || d <= 0) return null;+ const style = span.clip.transitionStyle ?? "crossfade";+ const Icon = TRANSITION_ICONS[style];+ return (<divkey={`xf-${span.clip.id}`}// Above SELECTED_SHADOW's z-10: the badge marks the joint even@@ -757,12 +772,12 @@ export function Timeline() {width: 16,height: 16,}}- title={`Cross-dissolve ${span.transitionOut.toFixed(1)}s`}+ title={`${TRANSITION_STYLE_LABELS[style]} ${d.toFixed(1)}s`}>- <Blend className="size-2.5" />+ <Icon className="size-2.5" /></div>- ) : null- )}+ );+ })}</div>{belowTracks.map((track) => (diff --git a/site/src/cut/hooks/usePlayback.ts b/site/src/cut/hooks/usePlayback.tsindex e0406cbc..dcd78e4f 100644--- a/site/src/cut/hooks/usePlayback.ts+++ b/site/src/cut/hooks/usePlayback.ts@@ -2,7 +2,7 @@import { useEffect, type RefObject } from "react";import { clipSpeed, getClipSpans, projectDuration, useEditor } from "@/cut/lib/store";-import { isFullRect, rectOf } from "@/cut/lib/types";+import { isFullRect, rectOf, TRANSITION_ZOOM } from "@/cut/lib/types";import type { ClipSpan, FrameRect, MediaAsset, OverlayClip, VideoClip } from "@/cut/lib/types";// The canvas backing store is the full frame resolution (1080×1920 or@@ -105,8 +105,9 @@ class Engine {/** Draw a video element into a sub-region of the frame. "fill" covers the* region and crops the overflow (clipped to the rect); "fit" contains the- * whole picture inside it, centered. */- private drawIntoRect(el: HTMLVideoElement, rect: FrameRect, fill: boolean, alpha: number) {+ * whole picture inside it, centered. `zoom` scales the picture around the+ * region's center (zoom transitions), clipping the overflow to the rect. */+ private drawIntoRect(el: HTMLVideoElement, rect: FrameRect, fill: boolean, alpha: number, zoom = 1) {const ctx = this.canvas.getContext("2d");if (!ctx) return;const W = this.canvas.width;@@ -115,16 +116,17 @@ class Engine {const ry = rect.y * H;const rw = rect.w * W;const rh = rect.h * H;- const sc = fill- ? Math.max(rw / el.videoWidth, rh / el.videoHeight)- : Math.min(rw / el.videoWidth, rh / el.videoHeight);+ const sc =+ (fill+ ? Math.max(rw / el.videoWidth, rh / el.videoHeight)+ : Math.min(rw / el.videoWidth, rh / el.videoHeight)) * zoom;const dw = el.videoWidth * sc;const dh = el.videoHeight * sc;const dx = rx + (rw - dw) / 2;const dy = ry + (rh - dh) / 2;const prevAlpha = ctx.globalAlpha;ctx.globalAlpha = Math.max(0, Math.min(1, alpha));- if (fill) {+ if (fill || zoom > 1) {ctx.save();ctx.beginPath();ctx.rect(rx, ry, rw, rh);@@ -137,7 +139,7 @@ class Engine {ctx.globalAlpha = prevAlpha;}- private drawLayer(el: HTMLVideoElement | null, clip: VideoClip | undefined, clear: boolean, alpha: number) {+ private drawLayer(el: HTMLVideoElement | null, clip: VideoClip | undefined, clear: boolean, alpha: number, zoom = 1) {const ctx = this.canvas.getContext("2d");if (!ctx) return;const W = this.canvas.width;@@ -169,13 +171,14 @@ class Engine {// black frame; the full-frame path below keeps the pan-crop behavior.const rect = rectOf(clip ?? {});if (!isFullRect(rect)) {- this.drawIntoRect(el, rect, clip?.fit === "fill", alpha);+ this.drawIntoRect(el, rect, clip?.fit === "fill", alpha, zoom);return;}const fill = clip?.fit === "fill";- const scale = fill- ? Math.max(W / el.videoWidth, H / el.videoHeight)- : Math.min(W / el.videoWidth, H / el.videoHeight);+ const scale =+ (fill+ ? Math.max(W / el.videoWidth, H / el.videoHeight)+ : Math.min(W / el.videoWidth, H / el.videoHeight)) * zoom;const dw = el.videoWidth * scale;const dh = el.videoHeight * scale;let dx = (W - dw) / 2;@@ -193,17 +196,26 @@ class Engine {ctx.globalAlpha = prevAlpha;}- /** Draw `masterSpan` full-frame, and if a cross-dissolve into the next span- * is live at time `t`, draw that next clip over it at ramping opacity — a- * true A·(1−α)+B·α blend. Returns the master element (the playback clock). */+ /** Draw `masterSpan` full-frame, plus any transition live at time `t`: a+ * cross style blends (and for cross zoom, scales) the next clip over it — a+ * true A·(1−α)+B·α blend — while an edge style fades or zooms the master's+ * own edge around a hard cut. Returns the master element (the playback+ * clock). */private composite(masterSpan: ClipSpan, spans: ClipSpan[], t: number, play: boolean) {// A hidden clip is silent as well as black.const masterEl = this.prepare(masterSpan, t, play, masterSpan.clip.muted || !!masterSpan.clip.hidden);this.activeClipId = masterSpan.clip.id;const keep = new Set([masterSpan.clip.id]);- const next = spans[spans.indexOf(masterSpan) + 1];+ const idx = spans.indexOf(masterSpan);+ const next = spans[idx + 1];+ const prev = spans[idx - 1];+ const style = masterSpan.clip.transitionStyle ?? "crossfade";let incEl: HTMLVideoElement | null = null;let alpha = 0;+ let masterZoom = 1;+ let incZoom = 1;+ let black = 0; // fade-to-black veil over the base, 0..1+ let gain = 1; // master audio follows the picture through a fade edge// Warm the next clip's decoder shortly before its entrance (the dissolve// start, or the hard cut) so it enters with a frame already decoded — a// cold element would sit invisible for the first frames of the fade.@@ -211,19 +223,64 @@ class Engine {this.prepare(next, next.start, false, true);keep.add(next.clip.id);}- // Once the incoming footprint starts, dissolve it in over the master. Each- // clip owns its element, so the two decode side by side — a true blend even- // when they are trims of the same source.+ // Cross styles: once the incoming footprint starts, blend it in over the+ // master. Each clip owns its element, so the two decode side by side — a+ // true blend even when they are trims of the same source.if (masterSpan.transitionOut > 0 && next && t >= next.start) {- alpha = (t - next.start) / masterSpan.transitionOut;+ const p = Math.min(1, (t - next.start) / masterSpan.transitionOut);+ alpha = p;incEl = this.prepare(next, t, play, true); // the outgoing clip keeps the audiokeep.add(next.clip.id);+ if (style === "crosszoom") {+ // The outgoing picture pushes in while the incoming one settles back.+ masterZoom = 1 + (TRANSITION_ZOOM - 1) * p;+ incZoom = TRANSITION_ZOOM - (TRANSITION_ZOOM - 1) * p;+ }+ }+ // Edge style on this clip's own tail (fade out / zoom in).+ if (next && (style === "fadeout" || style === "zoomin")) {+ const d = Math.min(masterSpan.clip.transition ?? 0, masterSpan.len);+ const left = masterSpan.start + masterSpan.len - t;+ if (d > 0 && left < d) {+ const p = 1 - left / d;+ if (style === "fadeout") {+ black = Math.max(black, p);+ gain = Math.min(gain, 1 - p);+ } else {+ masterZoom = 1 + (TRANSITION_ZOOM - 1) * p;+ }+ }}+ // Edge style the previous clip set on this clip's head (fade in / zoom out).+ const prevStyle = prev?.clip.transitionStyle ?? "crossfade";+ if (prev && prev.transitionOut === 0 && (prevStyle === "fadein" || prevStyle === "zoomout")) {+ const d = Math.min(prev.clip.transition ?? 0, masterSpan.len);+ const rel = t - masterSpan.start;+ if (d > 0 && rel < d) {+ const p = rel / d;+ if (prevStyle === "fadein") {+ black = Math.max(black, 1 - p);+ gain = Math.min(gain, p);+ } else {+ masterZoom = TRANSITION_ZOOM - (TRANSITION_ZOOM - 1) * p;+ }+ }+ }+ masterEl.volume = Math.max(0, Math.min(1, gain));this.pauseExcept(keep);// No clear here — the tick clears once, then draws the below tracks, so the// base composites over them (a regioned base leaves them showing).- this.drawLayer(masterEl, masterSpan.clip, false, 1);- if (incEl) this.drawLayer(incEl, next!.clip, false, alpha);+ this.drawLayer(masterEl, masterSpan.clip, false, 1, masterZoom);+ if (incEl) this.drawLayer(incEl, next!.clip, false, alpha, incZoom);+ if (black > 0) {+ // Veil the base like the export's fade-to-black; tracks drawn after+ // (above the base) stay lit.+ const ctx = this.canvas.getContext("2d");+ if (ctx) {+ ctx.fillStyle = `rgba(0,0,0,${Math.min(1, black).toFixed(3)})`;+ ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);+ }+ }return masterEl;}diff --git a/site/src/cut/lib/aiContext.ts b/site/src/cut/lib/aiContext.tsindex 390387bd..c4cf5df2 100644--- a/site/src/cut/lib/aiContext.ts+++ b/site/src/cut/lib/aiContext.ts@@ -70,7 +70,14 @@ export function buildAiContext(opts?: { fullCues?: boolean }) {muted: sp.clip.muted,framing: sp.clip.fit ?? "fit",speed: r(sp.clip.speed ?? 1),- ...(sp.transitionOut > 0 ? { crossfadeToNext: r(sp.transitionOut) } : {}),+ ...((sp.clip.transition ?? 0) > 0 && index < spans.length - 1+ ? {+ transitionToNext: {+ style: sp.clip.transitionStyle ?? "crossfade",+ seconds: r(sp.clip.transition ?? 0),+ },+ }+ : {}),...(sp.clip.fit === "fill"? { panX: r(sp.clip.panX ?? 0), panY: r(sp.clip.panY ?? 0) }: {}),diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.tsindex 611959fd..76307044 100644--- a/site/src/cut/lib/aiTools.ts+++ b/site/src/cut/lib/aiTools.ts@@ -4,7 +4,7 @@ import { apiFetch } from "./api";import { enrichAsset, ensurePeaks } from "./media";import { getClipSpans, TIMELINE_H_MAX, TIMELINE_H_MIN, totalDuration, useEditor } from "./store";import { buildAiContext } from "./aiContext";-import { FRAME, mediaUrl, type FontId, type MediaAsset } from "./types";+import { FRAME, mediaUrl, TRANSITION_STYLE_IDS, type FontId, type MediaAsset, type TransitionStyle } from "./types";const clamp = (v: number, lo: number, hi: number) => Math.max(lo, Math.min(hi, v));const isNum = (v: unknown): v is number => typeof v === "number" && Number.isFinite(v);@@ -347,11 +347,16 @@ export async function runAiTool(case "set_transition": {const clip = requireItem(s.clips, input.clipId, "video clip");if (s.clips.findIndex((c) => c.id === clip.id) === s.clips.length - 1)- throw new ToolError("The last clip has no next clip to dissolve into.");- if (!isNum(input.seconds)) throw new ToolError("seconds is required (0 clears the crossfade).");- s.setClipTransition(clip.id, input.seconds);+ throw new ToolError("The last clip has no next clip to transition into.");+ if (!isNum(input.seconds)) throw new ToolError("seconds is required (0 clears the transition).");+ let style: TransitionStyle | undefined;+ if (input.style !== undefined) {+ style = TRANSITION_STYLE_IDS.find((x) => x === input.style);+ if (!style) throw new ToolError(`Unknown style. Use one of: ${TRANSITION_STYLE_IDS.join(", ")}.`);+ }+ s.setClipTransition(clip.id, input.seconds, style);const next = useEditor.getState().clips.find((c) => c.id === clip.id)!;- return { id: next.id, transition: next.transition ?? 0 };+ return { id: next.id, transition: next.transition ?? 0, style: next.transitionStyle ?? "crossfade" };}case "merge_cue": {diff --git a/site/src/cut/lib/exportClient.ts b/site/src/cut/lib/exportClient.tsindex b5f19a60..a5f85ddf 100644--- a/site/src/cut/lib/exportClient.ts+++ b/site/src/cut/lib/exportClient.ts@@ -142,8 +142,38 @@ async function buildExportForm(speed: clipSpeed(sp.clip),transition: sp.transitionOut,hidden: sp.clip.hidden,+ headFade: 0,+ tailFade: 0,+ headZoom: 0,+ tailZoom: 0,}));+ // Translate each joint's transition style into per-segment ramps so the+ // server spec stays dumb. Cross zoom rides the crossfade overlap with a zoom+ // ramp on both sides; edge styles ramp one clip's edge around a hard cut+ // (their `transition` ships as 0 overlap, so the join stays a plain concat).+ spans.forEach((sp, i) => {+ const next = spans[i + 1];+ if (!next) return;+ const style = sp.clip.transitionStyle ?? "crossfade";+ const d = sp.clip.transition ?? 0;+ if (d <= 0) return;+ const a = clips[i];+ const b = clips[i + 1];+ if (style === "crosszoom" && sp.transitionOut > 0) {+ a.tailZoom = sp.transitionOut;+ b.headZoom = sp.transitionOut;+ } else if (style === "fadeout") {+ a.tailFade = Math.min(d, sp.len);+ } else if (style === "zoomin") {+ a.tailZoom = Math.min(d, sp.len);+ } else if (style === "fadein") {+ b.headFade = Math.min(d, next.len);+ } else if (style === "zoomout") {+ b.headZoom = Math.min(d, next.len);+ }+ });+// Upper video tracks composited over the base; hidden ones are dropped.const overlayVideos = doc.overlayClips.filter((c) => !c.hidden && assetById.has(c.assetId) && c.start < duration)diff --git a/site/src/cut/lib/store.ts b/site/src/cut/lib/store.tsindex 6261f4ce..e2a2cb5d 100644--- a/site/src/cut/lib/store.ts+++ b/site/src/cut/lib/store.ts@@ -18,10 +18,11 @@ import type {TemplateMedia,TemplateSaveInput,TextOverlay,+ TransitionStyle,VideoClip,} from "./types";import { apiFetch } from "./api";-import { emptySubtitles, mediaUrl, SPEED_MAX, SPEED_MIN, TRANSITION_MAX } from "./types";+import { emptySubtitles, isCrossStyle, mediaUrl, SPEED_MAX, SPEED_MIN, TRANSITION_MAX } from "./types";import { readTextStyle } from "./textStyle";import { loadUiState, saveUiState } from "./uiState";@@ -133,8 +134,9 @@ interface EditorState {/** Set a clip's playback rate (0.25–4). The clip's timeline footprint* changes, so later titles/captions ripple to stay in sync. */setClipSpeed: (id: string, speed: number) => void;- /** Set the cross-dissolve into the next clip (seconds; 0 clears it). */- setClipTransition: (id: string, seconds: number) => void;+ /** Set the transition into the next clip (seconds; 0 clears it), optionally+ * changing its style; omitting the style keeps the clip's current one. */+ setClipTransition: (id: string, seconds: number, style?: TransitionStyle) => void;updateAudio: (id: string, patch: Partial<AudioClip>) => void;updateOverlay: (id: string, patch: Partial<TextOverlay>) => void;/** Live-drag updates that should not create undo entries. */@@ -548,19 +550,27 @@ export const useEditor = create<EditorState>((set, get) => {get().rippleShift(editEnd, newLen - oldLen);},- setClipTransition: (id, seconds) => {+ setClipTransition: (id, seconds, style) => {const s = get();const idx = s.clips.findIndex((c) => c.id === id);if (idx < 0) return;const clip = s.clips[idx];const next = s.clips[idx + 1];const value = Math.max(0, Math.min(TRANSITION_MAX, seconds));+ const newStyle = value > 0 ? (style ?? clip.transitionStyle ?? "crossfade") : undefined;const oldOverlap = transitionOverlap(clip, next);- const newOverlap = transitionOverlap({ ...clip, transition: value }, next);+ const newOverlap = transitionOverlap(+ { ...clip, transition: value, transitionStyle: newStyle },+ next+ );const span = getClipSpans(s.clips, s.assets).find((sp) => sp.clip.id === id);const editEnd = (span?.start ?? 0) + (span?.len ?? clipLen(clip));push();- get().updateClipTransient(id, { transition: value || undefined });+ get().updateClipTransient(id, {+ transition: value || undefined,+ // "crossfade" is the default — store it as absence to keep docs lean.+ transitionStyle: newStyle === "crossfade" ? undefined : newStyle,+ });get().rippleShift(editEnd, oldOverlap - newOverlap);},@@ -801,7 +811,7 @@ export const useEditor = create<EditorState>((set, get) => {const cutAt = span.clip.in + (t - span.start) * clipSpeed(span.clip);// The left half hard-cuts into the right; the right keeps the original// dissolve into whatever came after.- const left: VideoClip = { ...span.clip, out: cutAt, transition: undefined };+ const left: VideoClip = { ...span.clip, out: cutAt, transition: undefined, transitionStyle: undefined };const right: VideoClip = { ...span.clip, id: uid(), in: cutAt };set((s) => {const idx = s.clips.findIndex((c) => c.id === span.clip.id);@@ -1511,12 +1521,14 @@ export function clipLen(c: VideoClip | AudioClip) {return Math.max(MIN_LEN, eff);}-/** Cross-dissolve overlap (timeline seconds) between a clip and its successor,- * clamped so it can never swallow either clip whole. 0 when there is no next- * clip or no transition set. */+/** Overlap (timeline seconds) between a clip and its successor, clamped so it+ * can never swallow either clip whole. 0 when there is no next clip, no+ * transition set, or the style is an edge style (those ramp one clip's edge+ * around a hard cut instead of overlapping). */export function transitionOverlap(a: VideoClip, b: VideoClip | undefined): number {const d = a.transition ?? 0;if (!b || d <= 0) return 0;+ if (!isCrossStyle(a.transitionStyle ?? "crossfade")) return 0;return Math.min(d, clipLen(a) * 0.9, clipLen(b) * 0.9);}diff --git a/site/src/cut/lib/types.ts b/site/src/cut/lib/types.tsindex f9cf1b54..11589132 100644--- a/site/src/cut/lib/types.ts+++ b/site/src/cut/lib/types.ts@@ -109,9 +109,12 @@ export interface VideoClip {/** Playback rate, default 1 (absent). The source (out-in) seconds play in* (out-in)/speed timeline seconds, so >1 is faster and shorter. */speed?: number;- /** Cross-dissolve into the next clip, in timeline seconds (absent/0 = hard- * cut). The two clips overlap by this much, so the cut shortens by it. */+ /** Transition into the next clip, in timeline seconds (absent/0 = hard cut).+ * Cross styles overlap the two clips by this much (the cut shortens); edge+ * styles ramp one clip's edge over this window around a hard cut. */transition?: number;+ /** Look of that transition; absent = "crossfade". */+ transitionStyle?: TransitionStyle;/** Hidden clips stay on the timeline (grayed) but render as black — excluded* from the played/exported picture without disturbing the layout. */hidden?: boolean;@@ -143,9 +146,46 @@ export interface OverlayClip {/** Speed limits — matches the Inspector control and export atempo range. */export const SPEED_MIN = 0.25;export const SPEED_MAX = 4;-/** Longest cross-dissolve offered; also clamps against the clips it joins. */+/** Longest transition offered; also clamps against the clips it joins. */export const TRANSITION_MAX = 2;+/** How a clip hands off to the next one. Cross styles overlap the two clips;+ * edge styles ramp one side of a hard cut — the outgoing tail (fadeout,+ * zoomin) or the incoming head (fadein, zoomout). */+export type TransitionStyle =+ | "crossfade"+ | "crosszoom"+ | "zoomin"+ | "zoomout"+ | "fadein"+ | "fadeout";++export const TRANSITION_STYLE_IDS: TransitionStyle[] = [+ "crossfade",+ "crosszoom",+ "zoomin",+ "zoomout",+ "fadein",+ "fadeout",+];++export const TRANSITION_STYLE_LABELS: Record<TransitionStyle, string> = {+ crossfade: "Cross fade",+ crosszoom: "Cross zoom",+ zoomin: "Zoom in",+ zoomout: "Zoom out",+ fadein: "Fade in",+ fadeout: "Fade out",+};++/** Cross styles overlap the clips they join; edge styles never do. */+export function isCrossStyle(style: TransitionStyle): boolean {+ return style === "crossfade" || style === "crosszoom";+}++/** Peak scale the zoom transitions push into (preview and export). */+export const TRANSITION_ZOOM = 1.18;+/** A clip on the free-form soundtrack track. */export interface AudioClip {id: string;diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.tsindex 86e3b693..8be71283 100644--- a/site/src/cut/server/ai/catalog.ts+++ b/site/src/cut/server/ai/catalog.ts@@ -242,8 +242,16 @@ export const AI_TOOLS: AiToolDef[] = [{name: "set_transition",description:- "Set a cross-dissolve from this clip into the next one, in seconds (0 clears it, max 2). The two clips overlap by that much, so the cut shortens. Only valid when a next clip exists.",- inputSchema: obj({ clipId: str("Video clip id (the clip the dissolve starts from)"), seconds: num("Dissolve length in seconds, 0–2 (0 = hard cut)") }, ["clipId", "seconds"]),+ "Set the transition from this clip into the next one, in seconds (0 clears it, max 2). crossfade/crosszoom overlap the two clips so the cut shortens; fadeout/zoomin ramp the outgoing tail and fadein/zoomout the incoming head around a hard cut. Only valid when a next clip exists.",+ inputSchema: obj({+ clipId: str("Video clip id (the clip the transition starts from)"),+ seconds: num("Transition length in seconds, 0–2 (0 = hard cut)"),+ style: {+ type: "string",+ enum: ["crossfade", "crosszoom", "zoomin", "zoomout", "fadein", "fadeout"],+ description: "Transition look (default crossfade)",+ },+ }, ["clipId", "seconds"]),},{name: "merge_cue",@@ -291,7 +299,7 @@ Times are in seconds on the shared timeline. The playhead is currentTime; a skim- Video track is magnetic: clips are ordered by index; there are no gaps. move_clip reorders. A clip's timeline length is (out-in)/speed; total duration = the sum of those minus any cross-dissolve overlaps.- trim_clip changes in/out inside the source media. in >= 0, out <= source duration, out-in >= 0.1.- set_speed sets a clip's playback rate (0.25–4×); it changes the clip's timeline length, and later titles/captions ripple to stay in sync.-- set_transition adds a cross-dissolve from a clip into the next one (0–2s). The clips overlap by that duration, so the cut gets shorter; splitting or deleting clears the affected dissolve.+- set_transition joins a clip into the next one (0–2s): crossfade/crosszoom overlap the clips (the cut shortens); fadein/fadeout/zoomin/zoomout ramp one side of a hard cut. Splitting or deleting clears the affected transition.- split_at cuts the clip under that time into two clips at the exact frame. With a soundtrack clip selected it splits that instead.- delete_item removes items; the video track closes the gap automatically. The user can multi-select (⌘/⇧-click) and delete several at once.- detach_audio lifts a video clip's sound to the soundtrack track (and mutes the clip) so audio can be cut independently of video.diff --git a/site/src/cut/server/jobs.ts b/site/src/cut/server/jobs.tsindex a68b6786..548941f9 100644--- a/site/src/cut/server/jobs.ts+++ b/site/src/cut/server/jobs.ts@@ -32,6 +32,13 @@ export interface ExportSpec {speed?: number; // playback rate, default 1/** Cross-dissolve into the next clip, in timeline seconds (overlap). */transition?: number;+ /** Edge-transition ramps, timeline seconds from this segment's head/tail:+ * fades to/from black and zoom pushes. Cross zoom arrives as a tailZoom on+ * one clip plus a headZoom on the next, riding the crossfade overlap. */+ headFade?: number;+ tailFade?: number;+ headZoom?: number;+ tailZoom?: number;/** Hidden clips keep their slot but render black + silent. */hidden?: boolean;}[];@@ -221,6 +228,9 @@ function clipRate(c: ExportSpec["clips"][number]) {return c.speed && c.speed > 0 ? c.speed : 1;}+/** Peak scale of zoom transitions — matches TRANSITION_ZOOM in lib/types.ts. */+const TRANSITION_ZOOM = 1.18;+/** A clip's frame region in even pixels, or null when it fills the whole frame* (the common case, which keeps the plain full-frame filter path). */function regionPx(@@ -356,6 +366,11 @@ async function runExport(job: Job, spec: ExportSpec) {const idx = inputIndex.get(c.file)!;const speed = clipRate(c);const dur = clipDur(c);+ // Edge-transition ramps, clamped so head+tail never overrun the segment.+ const hz = Math.max(0, Math.min(c.headZoom ?? 0, dur));+ const tz = Math.max(0, Math.min(c.tailZoom ?? 0, dur - hz));+ const hf = Math.max(0, Math.min(c.headFade ?? 0, dur));+ const tf = Math.max(0, Math.min(c.tailFade ?? 0, dur - hf));if (videoPresence.get(c.file) && !c.hidden) {const region = regionPx(c.frame, W, H);let frame: string;@@ -380,10 +395,56 @@ async function runExport(job: Job, spec: ExportSpec) {`pad=${W}:${H}:(ow-iw)/2:(oh-ih)/2:color=${padColor}`;}// setpts/speed rescales the clip's duration on the timeline.- filters.push(+ const core =`[${idx}:v]trim=${num(c.in)}:${num(c.out)},setpts=(PTS-STARTPTS)/${num(speed)},` +- `fps=${fps},${frame},setsar=1,format=${baseFmt}[v${j}]`- );+ `fps=${fps},${frame},setsar=1,format=${baseFmt}`;+ const fades =+ (hf > 0.01 ? `,fade=t=in:st=0:d=${num(hf)}` : "") ++ (tf > 0.01 ? `,fade=t=out:st=${num(Math.max(0, dur - tf))}:d=${num(tf)}` : "");+ if (hz > 0.01 || tz > 0.01) {+ // Zoom ramp on the touched slice only: split the segment, run zoompan+ // over the head/tail window, and concat back — the per-frame zoom+ // stays confined to the short transition window. A head ramp settles+ // TRANSITION_ZOOM→1 (zoom out), a tail ramp pushes 1→TRANSITION_ZOOM+ // (zoom in); zoompan clamps z below 1 itself, so the plain arithmetic+ // needs no guards.+ const ramp = (side: "head" | "tail", secs: number) => {+ const frames = Math.max(1, Math.round(secs * fps) - 1);+ const k = num(TRANSITION_ZOOM - 1);+ const z =+ side === "tail"+ ? `1+${k}*in/${frames}`+ : `${num(TRANSITION_ZOOM)}-${k}*in/${frames}`;+ return (+ `zoompan=z=${z}:x=iw/2-(iw/zoom/2):y=ih/2-(ih/zoom/2)` ++ `:d=1:s=${W}x${H}:fps=${fps},setsar=1,format=${baseFmt}`+ );+ };+ const slices: { from: number; to: number; fx?: string }[] = [];+ if (hz > 0.01) slices.push({ from: 0, to: hz, fx: ramp("head", hz) });+ const mid0 = hz > 0.01 ? hz : 0;+ const mid1 = tz > 0.01 ? dur - tz : dur;+ if (mid1 - mid0 > 0.01) slices.push({ from: mid0, to: mid1 });+ if (tz > 0.01) slices.push({ from: dur - tz, to: dur, fx: ramp("tail", tz) });+ if (slices.length === 1) {+ filters.push(`${core},${slices[0].fx}${fades}[v${j}]`);+ } else {+ filters.push(`${core},split=${slices.length}${slices.map((_, k) => `[vs${j}_${k}]`).join("")}`);+ slices.forEach((sl, k) => {+ filters.push(+ `[vs${j}_${k}]trim=${num(sl.from)}:${num(sl.to)},setpts=PTS-STARTPTS` ++ (sl.fx ? `,${sl.fx}` : "") ++ `[vp${j}_${k}]`+ );+ });+ filters.push(+ slices.map((_, k) => `[vp${j}_${k}]`).join("") ++ `concat=n=${slices.length}:v=1:a=0${fades}[v${j}]`+ );+ }+ } else {+ filters.push(`${core}${fades}[v${j}]`);+ }} else {// No video stream, or a hidden clip: keep the slot transparent (so a below// track shows) when one exists, otherwise plain black.@@ -394,10 +455,14 @@ async function runExport(job: Job, spec: ExportSpec) {}if (!c.muted && !c.hidden && audioPresence.get(c.file)) {const tempo = speed !== 1 ? `${atempoChain(speed)},` : "";+ // The picture's fade edges carry the sound with them; zoom edges don't.+ const afades =+ (hf > 0.01 ? `,afade=t=in:st=0:d=${num(hf)}` : "") ++ (tf > 0.01 ? `,afade=t=out:st=${num(Math.max(0, dur - tf))}:d=${num(tf)}` : "");filters.push(`[${idx}:a]atrim=${num(c.in)}:${num(c.out)},asetpts=PTS-STARTPTS,${tempo}` +`aresample=44100,aformat=sample_fmts=fltp:channel_layouts=stereo,` +- `apad=whole_dur=${num(dur)},atrim=0:${num(dur)}[a${j}]`+ `apad=whole_dur=${num(dur)},atrim=0:${num(dur)}${afades}[a${j}]`);} else {filters.push(