The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Keyframe animation: a gap's words keep their spaces as typed, the timing goes only to the animation model, the last keyframe reads End frame, and a playback rate alone holds
Claude7025a85b79f6
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsxindex e5945c6e..23dd0412 100644--- a/src/components/studio/composer.tsx+++ b/src/components/studio/composer.tsx@@ -12,7 +12,7 @@ import { Kbd } from "@/components/ui/kbd";import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";import { useToday } from "@/hooks/use-today";import { estimateCost, imageLimit, layoutCanvas, planGeneration, routesFor, type Plan } from "@/lib/catalog/plan";-import type { Engine, GenerationRequest, MediaKind, ModelDef, Operation, Preset, PresetRoute, VideoFormat } from "@/lib/catalog/types";+import type { Engine, GenerationRequest, GenParams, MediaKind, ModelDef, Operation, Preset, PresetRoute, VideoFormat } from "@/lib/catalog/types";import { dualEngine } from "@/lib/catalog/engines";import { locksByDefault } from "@/lib/catalog/palettes";import { DEFAULT_LOOK, lookCard } from "@/lib/catalog/soul-cards";@@ -155,6 +155,17 @@ interface FramesContext {animation?: { timing: InbetweenTiming };}+/**+ * The draft's keyframe-animation settings (params.extra.inbetween, stillMouth) go only with an animation: after Animation+ * is turned off or another model is picked they stay in the draft (to come back to) but are not sent to that model.+ */+function withoutAnimation(params: GenParams, animating: boolean): GenParams {+ const extra = params.extra;+ if (animating || !extra || !("inbetween" in extra || "stillMouth" in extra)) return params;+ const { inbetween: _i, stillMouth: _s, ...rest } = extra;+ return { ...params, extra: Object.keys(rest).length ? rest : undefined };+}+function buildRequest(feature: string,draft: Pick<Draft, "slots" | "refs" | "presetId" | "modelId" | "prompt" | "negativePrompt" | "params" | "presetOptions" | "presetStrength" | "mix" | "frames" | "layout">,@@ -173,7 +184,7 @@ function buildRequest(let images = [s.image, s.image2, s.image3].filter((x): x is SlotValue => !!x?.ref).map((x) => x.ref).concat(refKind === "image" ? refs : []);const videos = refKind === "video" ? refs : [];let endImage = s.endImage?.ref || undefined;- let params = draft.params;+ let params = withoutAnimation(draft.params, !!(draft.frames && frames?.animation));let pinned = op;// Frames mode: the stills in order at their times (or the first and last as start and end frame), at the strip's length.if (draft.frames && frames) {diff --git a/src/components/studio/frames-strip.tsx b/src/components/studio/frames-strip.tsxindex 81b264c4..c9ad47d0 100644--- a/src/components/studio/frames-strip.tsx+++ b/src/components/studio/frames-strip.tsx@@ -143,7 +143,7 @@ export function FramesStrip({)}<FrameTileindex={i}- role={animation ? (i === 0 ? "Start frame" : "Middle frame") : frameRole(i, frames.length, f.at)}+ role={animation ? (i === 0 ? "Start frame" : i === frames.length - 1 ? "End frame" : "Middle frame") : frameRole(i, frames.length, f.at)}value={f.value}time={times[i] ?? 0}onChange={(v) => onFrame(i, v)}diff --git a/src/lib/inbetween.ts b/src/lib/inbetween.tsindex 2bf944f5..63f571d2 100644--- a/src/lib/inbetween.ts+++ b/src/lib/inbetween.ts@@ -135,7 +135,8 @@ export function timingFor(keys: number, given: Partial<InbetweenTiming> | undeficonst gaps = Array.from({ length: Math.max(0, keys - 1) }, (_, i) => {const g = given?.gaps?.[i] ?? DEFAULT_GAP;const speed = can.speeds.includes(g.speed) ? g.speed : 1;- return { frames: snapGapFrames(g.frames), speed, ...(g.prompt?.trim() && { prompt: g.prompt.trim() }) };+ // The words as typed (a trailing space is the next word coming); requests trim them (requestTiming, gapPrompt).+ return { frames: snapGapFrames(g.frames), speed, ...(g.prompt?.trim() && { prompt: g.prompt }) };});return { gaps, fps };}@@ -210,9 +211,12 @@ export function requestTiming(extra: Record<string, unknown> | undefined, keys:...(typeof (g as GapTiming)?.prompt === "string" && (g as GapTiming).prompt!.trim() && { prompt: (g as GapTiming).prompt!.trim().slice(0, 500) }),}));t = { gaps, fps: Number(raw.fps ?? ENGINE_TIMING[engine].rates[0]) as PlaybackFps };- } else if (times && times.length === keys && keys >= MIN_KEYS) {- t = timingFromTimes(times, { engine });- } else t = timingFor(keys, undefined, engine);+ } else {+ // A playback rate alone (no gaps): the gaps come from the times (or the default), played at that rate.+ const fps = raw && typeof raw === "object" && raw.fps !== undefined ? (Number(raw.fps) as PlaybackFps) : undefined;+ t = times && times.length === keys && keys >= MIN_KEYS ? timingFromTimes(times, { engine, fps }) : timingFor(keys, { fps }, engine);+ if (fps !== undefined) t = { ...t, fps };+ }const problem = timingProblem(t, keys, engine);if (problem) throw new Error(problem);return t;diff --git a/src/server/assist/tools.ts b/src/server/assist/tools.tsindex b161f893..ea53d519 100644--- a/src/server/assist/tools.ts+++ b/src/server/assist/tools.ts@@ -366,7 +366,7 @@ function asRequest(j: JobInput): GenerationRequest {...(shots && { shots }),...(j.keyframe_times?.length && { keyframeTimes: j.keyframe_times }),...((j.system || animation) && { extra: { ...(j.system && { system: j.system }), ...animation } }),- ...(animation?.inbetween && !j.keyframe_times?.length && { keyframeTimes: keyTimes({ ...animation.inbetween, fps: animation.inbetween.fps ?? (j.engine === "cloud" ? 16 : 24) }) }),+ ...(animation?.inbetween?.gaps && !j.keyframe_times?.length && { keyframeTimes: keyTimes({ ...animation.inbetween, fps: animation.inbetween.fps ?? (j.engine === "cloud" ? 16 : 24) }) }),},};}@@ -375,12 +375,15 @@ function asRequest(j: JobInput): GenerationRequest {function animationOf(j: JobInput): { inbetween?: InbetweenTiming; stillMouth?: true } | undefined {if (!j.gaps?.length && !j.playback_fps && !j.still_mouth) return undefined;// Without a rate the engine's own plays it (24 fps on the GPU, 16 in the cloud: src/lib/inbetween.ts requestTiming).+ // A rate with no gaps rides alone: the gaps then come from the keyframe times at that rate.const inbetween = j.gaps?.length? ({gaps: j.gaps.map((g) => ({ frames: g.frames, speed: (g.speed ?? 1) as Speed, ...(g.words?.trim() && { prompt: g.words.trim() }) })),...(j.playback_fps && { fps: j.playback_fps as PlaybackFps }),} as InbetweenTiming)- : undefined;+ : j.playback_fps+ ? ({ fps: j.playback_fps as PlaybackFps } as InbetweenTiming)+ : undefined;return { ...(inbetween && { inbetween }), ...(j.still_mouth && { stillMouth: true as const }) };}diff --git a/tests/e2e/inbetweening.mjs b/tests/e2e/inbetweening.mjsindex 5a26c230..61bb2d0d 100644--- a/tests/e2e/inbetweening.mjs+++ b/tests/e2e/inbetweening.mjs@@ -102,14 +102,19 @@ for (const width of [1440, 390]) {check(`${tag}: Frames opens with the 3 handed-over keyframes`, (await s.locator('button[aria-label^="Frame "][aria-label$=": replace"]').count()) === 3);check(`${tag}: Animation style is on`, (await s.getByRole("switch").first().getAttribute("aria-checked")) === "true");check(`${tag}: a timing chip per gap`, (await s.locator("[data-gap-chip]").count()) === 2);+ check(`${tag}: the last keyframe is the end frame`, (await s.locator('button[aria-label^="Frame 3, end frame"]').count()) === 1);const before = await s.locator("[data-animation-length]").innerText();await s.locator("[data-gap-chip]").first().click();const pop = page.getByRole("dialog").last();await pop.waitFor();await pop.getByRole("radio", { name: "×3" }).click();await pop.getByRole("button", { name: "More frames" }).click();- await pop.getByPlaceholder("she jumps and lands").fill("he leaps");+ // Typed key by key, as a person types: the spaces stay.+ const words = pop.getByPlaceholder("she jumps and lands");+ await words.click();+ await words.pressSequentially("he leaps high", { delay: 20 });await page.waitForTimeout(300);+ check(`${tag}: a gap's words keep their spaces as typed`, (await words.inputValue()) === "he leaps high", await words.inputValue());const chip = await s.locator("[data-gap-chip]").first().innerText();check(`${tag}: the chip shows the gap's frames and speed`, /\d+ f · ×3/.test(chip.replace(/\s+/g, " ")), chip.replace(/\s+/g, " "));await shoot(page, `frames-gap-${width}-${scheme}.png`);diff --git a/tests/inbetween-request.test.ts b/tests/inbetween-request.test.tsnew file mode 100644index 00000000..82eebb69--- /dev/null+++ b/tests/inbetween-request.test.ts@@ -0,0 +1,33 @@+import { describe, expect, it } from "vitest";+import { buildRequest } from "@/components/studio/composer";+import { addFrame, type Attachment, type FrameAttachment } from "@/lib/composer";+import { WORKFLOW_TIMING } from "@/lib/inbetween";++const still = (name: string): Attachment => ({ id: name, ref: `/api/files/${name}.png`, preview: `/api/files/${name}.png`, kind: "image" });+const framesOf = (...names: string[]) => names.reduce<FrameAttachment[]>((fs, n) => addFrame(fs, still(n)), []);++// A Frames draft that was animated, then switched to another model: its timing and still mouth are kept in the draft.+const draft = (modelId: string) => ({+ slots: {},+ refs: [],+ modelId,+ prompt: "a girl turns",+ negativePrompt: "",+ params: { aspectRatio: "16:9", extra: { inbetween: WORKFLOW_TIMING, stillMouth: true, system: "keep" } },+ frames: framesOf("a", "b", "c", "d", "e"),+});+const ctx = { support: "all" as const, duration: 5, chained: false };++describe("The studio request for keyframe animation", () => {+ it("sends the timing and the still mouth only with an animation", () => {+ const off = buildRequest("video", draft("flux-3-max") as never, undefined, undefined, "image", ctx);+ expect(off.params?.extra).toEqual({ system: "keep" });+ const on = buildRequest("video", draft("fuobe-animation") as never, undefined, undefined, "image", { ...ctx, chained: true, animation: { timing: WORKFLOW_TIMING } });+ expect(on.params?.extra).toMatchObject({ inbetween: WORKFLOW_TIMING, stillMouth: true, system: "keep" });+ });++ it("drops an emptied extra", () => {+ const d = { ...draft("flux-3-max"), params: { extra: { stillMouth: true } } };+ expect(buildRequest("video", d as never, undefined, undefined, "image", ctx).params?.extra).toBeUndefined();+ });+});diff --git a/tests/inbetween-runs.test.ts b/tests/inbetween-runs.test.tsindex 75ff06c2..b558aa30 100644--- a/tests/inbetween-runs.test.ts+++ b/tests/inbetween-runs.test.ts@@ -97,4 +97,11 @@ describe("Fuobe Animation runs", () => {expect(g.request.params?.extra).toMatchObject({ inbetween: { gaps: [{ frames: 21, speed: 2, prompt: "it yawns" }, { frames: 17, speed: 1 }] }, stillMouth: true });expect(g.request.params?.keyframeTimes).toEqual([0, 10 / 24, 26 / 24].map((t) => Math.round(t * 1000) / 1000));});++ it("plays a generate job at the asked rate when it gives no gaps", () => {+ const job = { model_id: "fuobe-animation", prompt: "a cat stretches", images: frames(2), playback_fps: 16 };+ const plan = tools.planFor("generate", { summary: "Animate", jobs: [job] }, { engine: "open" });+ expect(plan.error).toBeUndefined();+ expect(plan.jobs[0].error).toBeUndefined();+ });});diff --git a/tests/inbetween.test.ts b/tests/inbetween.test.tsindex 16a02c00..14e7da9d 100644--- a/tests/inbetween.test.ts+++ b/tests/inbetween.test.ts@@ -85,7 +85,11 @@ describe("in-between timing", () => {it("fits saved timing to the keyframes and the engine", () => {const t = timingFor(4, { gaps: [{ frames: 30, speed: 3, prompt: " jumps " }], fps: 16 });- expect(t.gaps).toEqual([{ frames: 29, speed: 3, prompt: "jumps" }, { frames: 33, speed: 1 }, { frames: 33, speed: 1 }]);+ // The words stay as typed (the box keeps its spaces); a request trims them.+ expect(t.gaps).toEqual([{ frames: 29, speed: 3, prompt: " jumps " }, { frames: 33, speed: 1 }, { frames: 33, speed: 1 }]);+ expect(timingFor(2, { gaps: [{ frames: 33, speed: 1, prompt: "she " }] }).gaps[0].prompt).toBe("she ");+ expect(timingFor(2, { gaps: [{ frames: 33, speed: 1, prompt: " " }] }).gaps[0].prompt).toBeUndefined();+ expect(requestTiming({ inbetween: t }, 4, undefined, "open").gaps[0].prompt).toBe("jumps");expect(timingFor(3, { gaps: [{ frames: 21, speed: 4 }], fps: 24 }, "cloud")).toEqual({ gaps: [{ frames: 21, speed: 1 }, { frames: 33, speed: 1 }], fps: 16 });});@@ -103,6 +107,10 @@ describe("in-between timing", () => {expect(requestTiming({}, 3, [0, 1, 2], "open").gaps.map((g) => g.frames)).toEqual([25, 25]);expect(requestTiming(undefined, 2, undefined, "cloud")).toEqual({ gaps: [{ frames: 33, speed: 1 }], fps: 16 });expect(() => requestTiming({ inbetween: { gaps: [{ frames: 17, speed: 9 }], fps: 24 } }, 2, undefined, "open")).toThrow(/×1 to ×4/);+ // A playback rate alone: the gaps from the times, played at that rate (and refused where the engine can't).+ expect(requestTiming({ inbetween: { fps: 16 } }, 3, [0, 1, 2], "open")).toEqual({ gaps: [{ frames: 17, speed: 1 }, { frames: 17, speed: 1 }], fps: 16 });+ expect(requestTiming({ inbetween: { fps: 16 } }, 2, undefined, "open").fps).toBe(16);+ expect(() => requestTiming({ inbetween: { fps: 24 } }, 2, undefined, "cloud")).toThrow(/16 fps/);});it("writes each gap's words", () => {