Open source CapCut alternative.
TypeScript
fix(site): a still refuses a rate and points at the trim [rebuild]
David Ledcd9373626d1
diff --git a/site/src/cut/components/Inspector.tools.ts b/site/src/cut/components/Inspector.tools.tsindex da06e37c..7b5dd77e 100644--- a/site/src/cut/components/Inspector.tools.ts+++ b/site/src/cut/components/Inspector.tools.ts@@ -286,13 +286,13 @@ export const INSPECTOR_TOOLS = [{name: "set_speed",description:- "Set a video clip's playback speed, one rate across the whole clip, and/or play it backward. Faster shortens the clip on the timeline; slower stretches it. Later clips, titles, captions, and soundtrack shift to stay in sync. A clip carrying a speed curve loses it when speed is passed: the rate becomes uniform again (set_speed_curve is the tool for a rate that changes through the footage). `reverse: true` plays the clip's trim backward, picture and sound, at its rate — the clip keeps its length and its curve, and its head now shows source `out`; `reverse: false` turns it forward again. `smooth: true` smooths the clip's slow motion: wherever its rate is under 1×, the frames between source frames are synthesized (the export estimates the motion between them) so the slow stretch moves without stepping; at 1× and above nothing changes. Turn it on for real slow motion from ordinary footage; `smooth: false` shows the source frames as they are.",+ "Set a video clip's playback speed, one rate across the whole clip, and/or play it backward. A still has no motion to retime and is refused; trim_clip is what changes how long it holds. Faster shortens the clip on the timeline; slower stretches it. Later clips, titles, captions, and soundtrack shift to stay in sync. A clip carrying a speed curve loses it when speed is passed: the rate becomes uniform again (set_speed_curve is the tool for a rate that changes through the footage). `reverse: true` plays the clip's trim backward, picture and sound, at its rate — the clip keeps its length and its curve, and its head now shows source `out`; `reverse: false` turns it forward again. `smooth: true` smooths the clip's slow motion: wherever its rate is under 1×, the frames between source frames are synthesized (the export estimates the motion between them) so the slow stretch moves without stepping; at 1× and above nothing changes. Turn it on for real slow motion from ordinary footage; `smooth: false` shows the source frames as they are.",inputSchema: obj({ clipId: str("Video clip id"), ids: ids("clipId"), speed: num("Playback rate (1 = normal, no upper limit)"), reverse: bool("Play the footage backward (true) or forward (false)"), smooth: bool("Smooth slow motion: synthesize the frames between source frames wherever the rate is under 1×") }),},{name: "set_speed_curve",description:- `Give a video clip (any track) a speed curve: its rate changes through the footage instead of being one number, so one clip can race through a walk, land on a beat, and hold on a face. Nodes are {at, speed}: \`at\` in SOURCE seconds inside the clip's trim — the unit detect_beats, trim_clip and watch_video speak, so beat times drop straight in — and speed ${SPEED_CURVE_MIN}–${SPEED_CURVE_MAX}×. The rate curves smoothly between nodes and holds flat past the outermost ones; the whole list replaces the clip's curve, and an empty list clears it (the clip keeps its length at one uniform rate). Or pass a preset to lay a named ramp over the trim: ${speedCurvePresetCatalogText()}. Technique: give a peak a beat of normal speed on either side or it reads as a glitch; below about 0.5× ordinary footage shows its own frame rate, so pass \`smooth: true\` with the curve — it synthesizes the frames between source frames wherever the rate is under 1× and leaves the faster stretches alone — unless the source is high-frame-rate already; sound stretches with its pitch kept, which holds up on speech to roughly 0.5–2×. The clip's timeline length becomes the integral of the curve and later items shift like a trim. Returns the resulting nodes, the clip's length before and after, and the rows that moved. In the UI the Speed Curve row opens the same graph over the timeline.`,+ `Give a video clip (any track) a speed curve: its rate changes through the footage instead of being one number, so one clip can race through a walk, land on a beat, and hold on a face. A still is refused — it has no motion to retime. Nodes are {at, speed}: \`at\` in SOURCE seconds inside the clip's trim — the unit detect_beats, trim_clip and watch_video speak, so beat times drop straight in — and speed ${SPEED_CURVE_MIN}–${SPEED_CURVE_MAX}×. The rate curves smoothly between nodes and holds flat past the outermost ones; the whole list replaces the clip's curve, and an empty list clears it (the clip keeps its length at one uniform rate). Or pass a preset to lay a named ramp over the trim: ${speedCurvePresetCatalogText()}. Technique: give a peak a beat of normal speed on either side or it reads as a glitch; below about 0.5× ordinary footage shows its own frame rate, so pass \`smooth: true\` with the curve — it synthesizes the frames between source frames wherever the rate is under 1× and leaves the faster stretches alone — unless the source is high-frame-rate already; sound stretches with its pitch kept, which holds up on speech to roughly 0.5–2×. The clip's timeline length becomes the integral of the curve and later items shift like a trim. Returns the resulting nodes, the clip's length before and after, and the rows that moved. In the UI the Speed Curve row opens the same graph over the timeline.`,inputSchema: obj({clipId: str("Video clip id"),diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.tsindex 6b25e0fd..a9d6a855 100644--- a/site/src/cut/lib/aiTools.ts+++ b/site/src/cut/lib/aiTools.ts@@ -4090,6 +4090,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {set_speed: (s, input) => {const clip = requireItem(s.clips, input.clipId, "video clip");+ refuseStillRetime(s, clip);const reverse = typeof input.reverse === "boolean" ? input.reverse : undefined;const smooth = typeof input.smooth === "boolean" ? input.smooth : undefined;if (!isNum(input.speed) && reverse === undefined && smooth === undefined)@@ -4112,6 +4113,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {set_speed_curve: (s, input) => {const clip = requireItem(s.clips, input.clipId, "video clip");+ refuseStillRetime(s, clip);const before = clipLen(clip);if (typeof input.preset === "string") {if (Array.isArray(input.nodes) && input.nodes.length > 0)@@ -5064,6 +5066,16 @@ function requireItem<T extends { id: string }>(pool: T[], id: unknown, label: streturn item;}+/** A still holds one frame for as long as its clip runs, so a rate over it+ * means nothing — what a "faster" or "shorter" ask wants there is a trim. */+function refuseStillRetime(s: Editor, clip: VideoClip): void {+ const asset = s.assets.find((a) => a.id === clip.assetId);+ if (asset?.type !== "image") return;+ throw new ToolError(+ `"${asset.name}" is a still — it has no motion to retime. Change how long it holds with trim_clip.`+ );+}+/** Resolve a subtitle-track tool param (default: the active track), make it* the active track — generation, translation, and readout all write there. */function targetSubtitleTrack(input: Record<string, unknown>): number {diff --git a/site/src/cut/lib/sweepApply.test.ts b/site/src/cut/lib/sweepApply.test.tsindex 9418273e..c86bb3d0 100644--- a/site/src/cut/lib/sweepApply.test.ts+++ b/site/src/cut/lib/sweepApply.test.ts@@ -61,3 +61,14 @@ test("a call naming no target is refused, and naming both is too", async () => {/not both/,);});++test("a still refuses a rate and names the tool that shortens it", async () => {+ useEditor.setState({+ clips: [],+ assets: [{ id: "p1", fileName: "one.jpg", name: "One", type: "image", duration: 0, url: "" }],+ });+ await runAiTool("add_clip", { asset_id: "p1" });+ const id = useEditor.getState().clips[0].id;+ await expect(runAiTool("set_speed", { clipId: id, speed: 2 })).rejects.toThrow(/still[\s\S]*trim_clip/);+ await expect(runAiTool("set_speed_curve", { clipId: id, preset: "drift" })).rejects.toThrow(/still/);+});