Skip to content

Open source CapCut alternative.

TypeScript

feat(cut): route transitions, animations and looks through the assistant [rebuild]

David Le6d43f09916c0
diff --git a/site/scripts/eval-cut-chat.ts b/site/scripts/eval-cut-chat.ts
index e4d42bc1..a0a0e558 100644
--- a/site/scripts/eval-cut-chat.ts
+++ b/site/scripts/eval-cut-chat.ts
@@ -168,6 +168,49 @@ const EDITOR_STATE = {
view: { pxPerSec: 60, timelineH: 260, exportDialogOpen: false },
};
+/** Two abutting track-0 clips for the effects cases (transition, animation,
+ * and look control). Keys mirror buildAiContext, like EDITOR_STATE. */
+const TWO_CLIP_STATE = {
+ ...EDITOR_STATE,
+ videoTrack: [
+ {
+ index: 0,
+ id: "c1",
+ asset: "beach.mp4",
+ start: 0,
+ len: 6,
+ in: 0,
+ out: 6,
+ sourceDuration: 20,
+ muted: false,
+ framing: "fit",
+ speed: 1,
+ },
+ {
+ index: 1,
+ id: "c2",
+ asset: "beach.mp4",
+ start: 6,
+ len: 6.5,
+ in: 6,
+ out: 12.5,
+ sourceDuration: 20,
+ muted: false,
+ framing: "fit",
+ speed: 1,
+ },
+ ],
+};
+
+/** The same pair already joined by a crossfade, for the edge-override case. */
+const CROSSFADED_STATE = {
+ ...TWO_CLIP_STATE,
+ videoTrack: [
+ { ...TWO_CLIP_STATE.videoTrack[0], transitionToNext: { style: "crossfade", seconds: 0.5 } },
+ { ...TWO_CLIP_STATE.videoTrack[1], start: 5.5 },
+ ],
+};
+
/** A user-imported narration file for the scene-production cases. */
const NARRATION_ASSET = { id: "a-au1", name: "narration.mp3", type: "audio", duration: 24 };
@@ -723,6 +766,89 @@ function cases(audio: { dataBase64: string; mimeType: string }): EvalCase[] {
maxToolCalls: 2,
stubs: { trim_clip: { in: 0, out: 5, len: 5 } },
},
+ {
+ // Effects: a styled transition ask is one set_transition on the LEADING
+ // clip with the catalog style id (a skill read on the way is fine).
+ name: "transition-ask-styled",
+ input: () => [
+ userTurn("add a push down transition between the two clips", { state: TWO_CLIP_STATE }),
+ ],
+ reply: /push|transition/i,
+ requiredTools: ["set_transition"],
+ maxToolCalls: 3,
+ state: TWO_CLIP_STATE,
+ simulate: () => (name, args) => {
+ if (name !== "set_transition") return undefined;
+ if (args.clipId !== "c1")
+ throw new Error(`set_transition on ${args.clipId} — the transition belongs to the leading clip c1`);
+ if (args.style !== "pushdown")
+ throw new Error(`style ${args.style} — expected pushdown`);
+ return { id: "c1", transition: Number(args.seconds) || 0.5, style: "pushdown" };
+ },
+ },
+ {
+ // Directional comprehension: slide names are the motion direction, so
+ // "slide in from the left" moves rightward — slideright on c2's "in".
+ name: "slide-in-direction-correct",
+ input: () => [
+ userTurn("make the second clip slide in from the left", { state: TWO_CLIP_STATE }),
+ ],
+ reply: /slide/i,
+ requiredTools: ["set_animation"],
+ maxToolCalls: 3,
+ state: TWO_CLIP_STATE,
+ simulate: () => (name, args) => {
+ if (name !== "set_animation") return undefined;
+ if (args.clipId !== "c2" || args.which !== "in")
+ throw new Error(`set_animation ${args.clipId}/${args.which} — expected c2 "in"`);
+ if (args.style !== "slideright")
+ throw new Error(`style ${args.style} — "from the left" moves rightward (slideright)`);
+ return { id: "c2", which: "in", style: "slideright", seconds: Number(args.seconds) || 0.5 };
+ },
+ },
+ {
+ // Looks route to set_look with a catalog id — not a hand-rolled
+ // set_color_grade approximation.
+ name: "look-ask-single-tool",
+ input: () => [
+ userTurn("give the second clip a retro VHS look", { state: TWO_CLIP_STATE }),
+ ],
+ reply: /vhs|retro|look/i,
+ requiredTools: ["set_look"],
+ maxToolCalls: 3,
+ state: TWO_CLIP_STATE,
+ simulate: () => (name, args) => {
+ if (name !== "set_look") return undefined;
+ if (args.clipId !== "c2") throw new Error(`set_look on ${args.clipId} — expected c2`);
+ if (args.style !== "vhs") throw new Error(`style ${args.style} — expected vhs`);
+ return { id: "c2", look: "vhs", amount: 1 };
+ },
+ },
+ {
+ // Last pick wins per edge: swapping a crossfading joint for an entrance
+ // animation is a set_animation — the override clears the transition
+ // itself (an explicit set_transition 0 first is fine, not required).
+ // "Pop" exists only as an animation, so the routing is unambiguous
+ // (a wipe ask could legitimately become a wipe *transition* instead).
+ name: "animation-overrides-transition",
+ input: () => [
+ userTurn("get rid of the crossfade — make the second clip pop in instead", {
+ state: CROSSFADED_STATE,
+ }),
+ ],
+ reply: /pop/i,
+ requiredTools: ["set_animation"],
+ maxToolCalls: 4,
+ state: CROSSFADED_STATE,
+ simulate: () => (name, args) => {
+ if (name === "set_transition") return { id: "c1", transition: 0, style: "crossfade" };
+ if (name !== "set_animation") return undefined;
+ if (args.clipId !== "c2" || args.which !== "in")
+ throw new Error(`set_animation ${args.clipId}/${args.which} — expected c2 "in"`);
+ if (args.style !== "pop") throw new Error(`style ${args.style} — expected pop`);
+ return { id: "c2", which: "in", style: "pop", seconds: 0.5 };
+ },
+ },
{
// Driving the editor on the user's behalf: with a transcript in the
// snapshot, "cut the filler words" must land real timeline cuts (split
diff --git a/site/src/cut/lib/aiContext.ts b/site/src/cut/lib/aiContext.ts
index 9f315205..f5899097 100644
--- a/site/src/cut/lib/aiContext.ts
+++ b/site/src/cut/lib/aiContext.ts
@@ -4,24 +4,30 @@ import { chatOwner } from "./chatAssets";
import { useGenerate } from "./generate";
import { getClipSpans, overlayLayers, totalDuration, useEditor } from "./store";
import { laneCues, subtitleLaneCount } from "./subtitles";
-import { isCrossStyle, rectOf, regionLabel, type ClipSpan, type VideoClip } from "./types";
+import { rectOf, regionLabel, type ClipSpan, type VideoClip } from "./types";
const r = (n: number) => Math.round(n * 100) / 100;
-/** The transition this clip applies into the next one, clamped the same way the
- * preview and export are: a cross dissolve to its overlap, an edge fade/zoom to
- * the clip it ramps. Null when there's no transition or no next clip. */
+/** The transition this clip applies into the next one, clamped to the live
+ * overlap the same way the preview and export are. Null when there's no
+ * transition or no next clip. */
function transitionToNext(sp: ClipSpan, index: number, spans: ClipSpan[]) {
const seconds = sp.clip.transition ?? 0;
if (seconds <= 0 || index >= spans.length - 1) return null;
const style = sp.clip.transitionStyle ?? "crossfade";
- const next = spans[index + 1];
- const applied = isCrossStyle(style)
- ? sp.transitionOut
- : style === "fadein" || style === "zoomout"
- ? Math.min(seconds, next.len) // edge style ramps the next clip's head
- : Math.min(seconds, sp.len); // edge style ramps this clip's tail
- return { style, seconds: r(applied) };
+ return { style, seconds: r(sp.transitionOut) };
+}
+
+/** The clip's own effects — entrance/exit animations and filter look — in
+ * the shape set_animation/set_look take. */
+function clipEffects(clip: VideoClip) {
+ return {
+ ...(clip.animIn ? { animIn: { style: clip.animIn.style, seconds: r(clip.animIn.seconds) } } : {}),
+ ...(clip.animOut
+ ? { animOut: { style: clip.animOut.style, seconds: r(clip.animOut.seconds) } }
+ : {}),
+ ...(clip.look ? { look: clip.look, lookAmount: r(clip.lookAmount ?? 1) } : {}),
+ };
}
/**
@@ -182,6 +188,7 @@ export function buildAiContext(opts?: { fullCues?: boolean; chatId?: string | nu
? { panX: r(sp.clip.panX ?? 0), panY: r(sp.clip.panY ?? 0) }
: {}),
...(sp.clip.grade ? { colorGrade: sp.clip.grade } : {}),
+ ...clipEffects(sp.clip),
})),
// Video layers composited over track 0 in track order (the topmost
// full-frame clip covers the rest). Each track carries its own
@@ -195,6 +202,7 @@ export function buildAiContext(opts?: { fullCues?: boolean; chatId?: string | nu
const t = transitionToNext(sp, i, trackSpans);
return t ? { transitionToNext: t } : {};
})(),
+ ...clipEffects(sp.clip),
}));
}),
soundtrack: s.audioClips.map((a) => ({ id: a.id, ...describeAudio(a, assetById) })),
diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.ts
index 6ac91e32..7fe77153 100644
--- a/site/src/cut/lib/aiTools.ts
+++ b/site/src/cut/lib/aiTools.ts
@@ -35,11 +35,15 @@ import { stockAssetInDoc } from "./genvideo/docWriter";
import { resolveVoice, synthesizeSpeech, SPEECH_VOICES } from "./tts";
import { DUCK_DEFAULT, generateSubtitlesReadout } from "./voiceover";
import {
+ ANIM_DEFAULT_SECONDS,
+ ANIM_STYLE_IDS,
FRAME,
IMAGE_CLIP_SECONDS,
LAYOUTS,
+ LOOK_IDS,
MAX_SUBTITLE_LANES,
mediaUrl,
+ overlayAnimStyle,
rectOf,
regionLabel,
SPEED_FLOOR,
@@ -1540,6 +1544,40 @@ export async function runAiTool(
return { id: next.id, transition: next.transition ?? 0, style: next.transitionStyle ?? "crossfade" };
}
+ case "set_animation": {
+ const clip = requireItem(s.clips, input.clipId, "video clip");
+ const which = input.which === "in" || input.which === "out" ? input.which : null;
+ if (!which) throw new ToolError('which must be "in" or "out".');
+ if (input.style === "none") {
+ s.setClipAnim(clip.id, which, null);
+ return { id: clip.id, which, style: "none" };
+ }
+ const style = ANIM_STYLE_IDS.find((x) => x === input.style);
+ if (!style)
+ throw new ToolError(`Unknown style. Use one of: ${ANIM_STYLE_IDS.join(", ")}, none.`);
+ if (clip.track > 0 && overlayAnimStyle(style) !== style)
+ throw new ToolError("Upper-track clips animate with fade or zoom only.");
+ const seconds = isNum(input.seconds) ? input.seconds : ANIM_DEFAULT_SECONDS;
+ s.setClipAnim(clip.id, which, { style, seconds });
+ const next = useEditor.getState().clips.find((c) => c.id === clip.id)!;
+ const anim = which === "in" ? next.animIn : next.animOut;
+ return { id: next.id, which, style: anim?.style ?? "none", seconds: anim?.seconds ?? 0 };
+ }
+
+ case "set_look": {
+ const clip = requireItem(s.clips, input.clipId, "video clip");
+ if (input.style === "none") {
+ s.setClipLook(clip.id, null);
+ return { id: clip.id, look: "none" };
+ }
+ const style = LOOK_IDS.find((x) => x === input.style);
+ if (!style)
+ throw new ToolError(`Unknown look. Use one of: ${LOOK_IDS.join(", ")}, none.`);
+ s.setClipLook(clip.id, style, isNum(input.amount) ? input.amount : undefined);
+ const next = useEditor.getState().clips.find((c) => c.id === clip.id)!;
+ return { id: next.id, look: next.look ?? "none", amount: next.lookAmount ?? 1 };
+ }
+
case "merge_cue": {
const cue = requireItem(s.subtitles.cues, input.id, "subtitle cue");
const mates = laneCues(s.subtitles, cue.lane ?? 0);
diff --git a/site/src/cut/lib/genvideo/editorBridge.ts b/site/src/cut/lib/genvideo/editorBridge.ts
index 4fb80112..a5991c3d 100644
--- a/site/src/cut/lib/genvideo/editorBridge.ts
+++ b/site/src/cut/lib/genvideo/editorBridge.ts
@@ -23,7 +23,7 @@
*/
import { useEditor } from "../store";
-import type { TransitionStyle } from "../types";
+import { TRANSITION_STYLE_IDS, type TransitionStyle } from "../types";
import { docPlaceGenAudio, docPlaceGenClip, projectWriteMode, withProjectDoc } from "./docWriter";
import type { AudioClipInfo, EditorBridge, TimelineInfo } from "./editor";
@@ -152,13 +152,16 @@ export class StoreEditorBridge implements EditorBridge {
}
async addTransition(clipId: string, style: string, durationFrames: number): Promise<void> {
+ const safeStyle: TransitionStyle = TRANSITION_STYLE_IDS.includes(style as TransitionStyle)
+ ? (style as TransitionStyle)
+ : "crossfade";
if ((await this.mode()) === "store") {
- useEditor.getState().setClipTransition(clipId, toSec(durationFrames), style as TransitionStyle);
+ useEditor.getState().setClipTransition(clipId, toSec(durationFrames), safeStyle);
return;
}
await withProjectDoc(this.projectId, (doc) => {
doc.clips = doc.clips.map((c) =>
- c.id === clipId ? { ...c, transition: toSec(durationFrames), transitionStyle: style as TransitionStyle } : c
+ c.id === clipId ? { ...c, transition: toSec(durationFrames), transitionStyle: safeStyle } : c
);
});
}
diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.ts
index d6252d65..caa48d0c 100644
--- a/site/src/cut/server/ai/catalog.ts
+++ b/site/src/cut/server/ai/catalog.ts
@@ -7,6 +7,8 @@
* the exact same state the user sees.
*/
+import { ANIM_STYLE_IDS, LOOK_IDS, TRANSITION_STYLE_IDS } from "../../lib/types";
+
export interface AiToolDef {
name: string;
description: string;
@@ -657,17 +659,46 @@ export const AI_TOOLS: AiToolDef[] = [
{
name: "set_transition",
description:
- "Set the transition from this clip into the next clip on its track (any video track), 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. On upper tracks fades are alpha fades (the tracks beneath show through). Only valid when a next same-track clip exists.",
+ "Set the transition from this clip into the next clip on its track (any video track), in seconds (0 clears it, max 2). Every style overlaps the two clips, so the cut shortens by the duration. On upper tracks every style blends as an alpha dissolve (the tracks beneath show through). Only valid when a next same-track clip exists. Each edge holds one effect: setting a transition clears the animations adjacent to its joint (and set_animation on that edge replaces the transition). Read the transitions-and-fades skill before styling cuts.",
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"],
+ enum: [...TRANSITION_STYLE_IDS],
description: "Transition look (default crossfade)",
},
}, ["clipId", "seconds"]),
},
+ {
+ name: "set_animation",
+ description:
+ "Animate one clip's own entrance (which:'in') or exit (which:'out'): fade, zoom, pop, or a slide named by its motion direction. style 'none' clears. Track-0 clips take every style; upper-track clips only fade and zoom. Each edge holds one effect, last pick wins: animating an edge a transition owns replaces that transition (the pair returns to a hard cut), and setting a transition clears the animations adjacent to its joint. At an abutting cut the animation plays over the neighbor's held frame; at the timeline's ends and across gaps it plays against black.",
+ inputSchema: obj({
+ clipId: str("Video clip id"),
+ which: { type: "string", enum: ["in", "out"], description: "Entrance or exit" },
+ style: {
+ type: "string",
+ enum: [...ANIM_STYLE_IDS, "none"],
+ description: "Animation style, or 'none' to clear",
+ },
+ seconds: num("Ramp length in seconds, 0.1–2 (default 0.5)"),
+ }, ["clipId", "which", "style"]),
+ },
+ {
+ name: "set_look",
+ description:
+ "Apply a preset filter look to a video clip's picture (any track; stills too): vintage, vhs, horror (analogue horror), halation (highlight bloom), tech, noir, grain, pastel, blockbuster (teal-orange), dreamy. amount 0.05–1 scales the strength (default 1); style 'none' clears. Composes with set_color_grade — the look is the base, the grade rides on top.",
+ inputSchema: obj({
+ clipId: str("Video clip id"),
+ style: {
+ type: "string",
+ enum: [...LOOK_IDS, "none"],
+ description: "Look id, or 'none' to clear",
+ },
+ amount: num("Strength 0.05–1 (default 1)"),
+ }, ["clipId", "style"]),
+ },
{
name: "merge_cue",
description:
@@ -727,7 +758,7 @@ Times are in seconds on the shared timeline. The playhead is currentTime; a skim
- A clip's timeline length is (out-in)/speed; total duration runs to the last clip's end, gaps included, minus cross-style transition 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; it changes the clip's timeline length, and later titles/captions ripple to stay in sync.
-- set_transition joins a clip into the next one (0–2s, six styles) — read the transitions-and-fades skill before styling cuts. Splitting or deleting clears the affected transition.
+- set_transition joins a clip into the next one (0–2s, 17 styles); set_animation animates one clip's own entrance/exit; set_look grades its picture with a preset filter — read the transitions-and-fades skill before styling cuts. Splitting or deleting clears the affected transition.
- split_at cuts the track-0 clip under that time into two clips at the exact frame. With a soundtrack or overlay clip selected it splits that instead.
- The user can multi-select (⌘/⇧-click) and delete several items at once; a hover chip on each video clip toggles its own audio.
- detach_audio lifts a video clip's sound to the soundtrack track (and mutes the clip) so audio can be cut independently of video.
@@ -759,19 +790,18 @@ Time math (get this right):
Cutting dead air well: leave ~0.2s of breathing room around speech; prefer split_at + delete_item, then place_clip to close the gap (a beat of black may be wanted — ask the cut, not the tool); trim_clip only tightens a clip's edges.`,
- "transitions-and-fades": `# Transitions & fades
-Three fade-like features exist; route the ask to the right one:
-- set_transition: a styled join between one video clip and the next.
-- set_project_fade: the whole video fades in from black at the start and/or out to black at the end — picture and full mix (titles, captions, soundtrack). Survives clip reordering. For "fade in the video", "fade to black at the end", use this. Shown as "Fade in"/"Fade out" on the first/last clip's Inspector panel.
+ "transitions-and-fades": `# Transitions, animations, looks & fades
+Route the ask to the right feature:
+- set_transition: a styled join between one video clip and the next. Every style overlaps the clips, so the cut shortens by the duration.
+- set_animation: one clip's own entrance ("in") or exit ("out") — the clip fades/zooms/pops/slides on its own edge. Never moves neighbors. For "fade this clip in", "make it slide in", use this. A wipe is a transition, not an animation.
+- set_look: a preset filter over one clip's whole picture (vintage, vhs, horror, halation, tech, noir, grain, pastel, blockbuster, dreamy) with an amount knob.
+- set_project_fade: the whole video fades in from black at the start and/or out to black at the end — picture and full mix (titles, captions, soundtrack). Survives clip reordering. For "fade in the video", "fade to black at the end", use this.
- update_audio fadeIn/fadeOut: audio-only ramps on one soundtrack clip ("fade the music out").
-set_transition(clipId, seconds, style): clipId is the leading clip of the joint; 0 clears, max 2s. Styles:
-- crossfade (default): A blends into B. Overlaps the clips, so the cut shortens by the duration.
-- crosszoom: the blend plus a zoom punch — A pushes in (1→1.18×) while B settles back. Also overlaps.
-- zoomin: A's tail zooms in across a hard cut (duration unchanged). zoomout: B's head settles from zoomed to normal.
-- fadeout: A's tail fades to black (its audio too), then a hard cut. fadein: B's head fades up from black.
-Picking for a vibe: "smooth/dissolve" → crossfade; "punchy/energetic/zoom" → crosszoom; "dramatic pause/scene change" → fadeout 0.5–0.8s; between clips 0.4–0.8s reads well, 1s+ is slow and cuts total duration for cross styles.
-UI: select a clip → Inspector "Transition" (style) + "Length"; a blue badge marks each styled joint on the timeline. Preview and export render the same look.`,
+set_transition styles (clipId = the leading clip; 0 clears, max 2s): crossfade blends; crosszoom adds a zoom punch; dipblack/dipwhite dip through a solid color; blur defocuses through the cut; pushleft/right/up/down shove the old frame out; wipeleft/right/up/down reveal with a hard traveling edge; circleopen/close and splitopen/close are shape reveals. Directional names describe the motion.
+set_animation styles: fade (audio follows), zoom, pop, slideleft/right/up/down — the slide names are the motion direction (slideleft enters from the right edge moving left, or exits off the left). Each edge holds one effect and the last pick wins: set_animation on a transitioned edge replaces that transition, set_transition clears the animations adjacent to its joint.
+Picking for a vibe: "smooth" → crossfade; "punchy/energetic" → crosszoom or a push; "dramatic scene change" → dipblack 0.5–0.8s; "dreamy" → blur (or the dreamy look); "retro" → vhs or vintage look. Between clips 0.4–0.8s reads well; 1s+ is slow and cuts total duration.
+UI: select a clip → Inspector "Effects" opens the panel (Transition / In / Out / Looks tabs); a blue badge marks each styled joint on the timeline. Preview and export render the same treatment.`,
"titles": `# Titles (text overlays)
Each overlay: text, start/end (seconds visible), x/y center (fractions 0..1 of the project frame), size (frame px; the design short side is 1080), font (sf=SF Pro, serif=New York, rounded, mono, impact), weight (400/700), color (any CSS color), shadow (bool), plate (translucent dark plate behind the text).