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
Frames mode: Generate waits for frames still uploading, works with a camera motion, holds a one-frame clip longer than the model makes, and says what Lightning does
Claude9f650155f388
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsxindex 4d44f4fa..c27ff915 100644--- a/src/components/studio/composer.tsx+++ b/src/components/studio/composer.tsx@@ -12,7 +12,21 @@ import type { GenerationRequest, MediaKind, ModelDef, Operation, Preset } from "import { enhance, useCreateGeneration, useElements, useEngine, useHydrated, useStatus } from "@/lib/api";import { applyMentions, type StudioElement } from "@/lib/catalog/elements";import { applySketch, stripMotionPaths } from "@/lib/catalog/sketch";-import { chainGapProblem, chainTiming, frameSupport, framesBlocker, framesDuration, framesDurations, framesNote, FRAMES_MODELS, frameTimes, keyframeChain, moveFrameAt, type FrameSupport } from "@/lib/catalog/keyframes";+import {+ chainGapProblem,+ chainTiming,+ frameSupport,+ framesBlocker,+ framesDuration,+ framesDurations,+ framesNote,+ FRAMES_MODELS,+ frameTimes,+ keyframeChain,+ moveFrameAt,+ OPEN_MIN_GAP,+ type FrameSupport,+} from "@/lib/catalog/keyframes";import {blockerFor,costLabel,@@ -21,6 +35,8 @@ import {firstMissingSlot,framesRequest,framesShape,+ framesSlots,+ framesUploading,leaveFrames,namedImageSlots,needsMask,@@ -96,18 +112,20 @@ function buildRequest(const videos = refKind === "video" ? refs : [];let endImage = s.endImage?.ref || undefined;let params = draft.params;+ 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) {const sent = framesRequest(draft.frames, frames);images = sent.images;endImage = sent.endImage;params = { ...params, ...sent.params };+ pinned = op ?? sent.op;}return {feature,presetId: draft.presetId,modelId: draft.modelId,- op,+ op: pinned,prompt: promptSuffix && draft.prompt.trim() ? `${draft.prompt.trim().replace(/[.\s]+$/, "")}. ${promptSuffix}` : draft.prompt,negativePrompt: draft.negativePrompt || undefined,inputs: {@@ -230,6 +248,9 @@ export function Composer({ docked }: { docked: boolean }) {const framesOn = !!config.frames && !!draft.frames;const framesCtx: FramesContext | undefined =framesOn && model ? { support: frameSupport(model), duration: framesDuration(model, draft.params.duration), chained: !!keyframeChain(model) } : undefined;+ const framesAt = framesCtx && draft.frames ? frameTimes(draft.frames.map((f) => f.at), framesCtx.duration) : [];+ // The open chain's gaps (and one frame's clip) must be clips its model makes; the planner checks two or more frames too.+ const framesGap = framesCtx?.chained && model && framesAt.length ? chainGapProblem(framesAt, framesCtx.duration, chainTiming(model)) : null;// The page's drop zone hands its files to this composer.useEffect(() => {@@ -258,8 +279,10 @@ export function Composer({ docked }: { docked: boolean }) {// operation are known up front and the blocker can name the slot in the studio's own words.// Studios that need one of several inputs (Lipsync: a portrait or a video) name the group.const anyOf = preset?.inputs ? undefined : config.anyOf;- const missing = firstMissingSlot(slots, draft.slots, anyOf);- const uploading = Object.values(draft.slots).some((v) => v?.uploading) || draft.refs.some((r) => r.uploading);+ // Frames mode has its own strip: the start frame is frame 1 (a camera motion's start frame tile isn't asked for).+ const askedSlots = framesOn ? framesSlots(slots) : slots;+ const missing = firstMissingSlot(askedSlots, draft.slots, anyOf);+ const uploading = Object.values(draft.slots).some((v) => v?.uploading) || draft.refs.some((r) => r.uploading) || (framesOn && framesUploading(draft.frames));const engineError = lockedModel && preset && !(engine === "open" ? preset.open : preset.cloud) ? `${preset.name} has no ${engine === "open" ? "open-source" : "cloud"} version yet` : null;let op: Operation | undefined;let cost: number | null = null;@@ -268,7 +291,7 @@ export function Composer({ docked }: { docked: boolean }) {try {const stand = (v: SlotValue | null | undefined, kind: MediaKind): SlotValue | null | undefined => (v?.uploading ? { ...v, ref: PLACEHOLDER[kind] } : v);const planSlots: Draft["slots"] = Object.fromEntries(Object.entries(draft.slots).map(([k, v]) => [k, stand(v, v?.kind ?? "image")]));- for (const s of slots) if (s.required && !planSlots[s.key]?.ref) planSlots[s.key] = { ref: PLACEHOLDER[s.accept], preview: "", kind: s.accept };+ for (const s of askedSlots) if (s.required && !planSlots[s.key]?.ref) planSlots[s.key] = { ref: PLACEHOLDER[s.accept], preview: "", kind: s.accept };for (const g of anyOf ?? []) {const first = slots.find((s) => s.key === g[0]);if (first && !g.some((k) => planSlots[k]?.ref)) planSlots[first.key] = { ref: PLACEHOLDER[first.accept], preview: "", kind: first.accept };@@ -294,7 +317,7 @@ export function Composer({ docked }: { docked: boolean }) {loading: !catalog.ready ? "Loading models…" : presetLoading ? "Loading presets…" : null,model: !!model,engineError,- frames: framesOn && model ? framesBlocker(model, draft.frames!.length) : null,+ frames: framesOn && model ? (framesBlocker(model, draft.frames!.length) ?? (framesGap ? { message: framesGap } : null)) : null,missing,uploading,maskMissing: needsMask(model, config.sketch, draft.slots),@@ -437,11 +460,11 @@ export function Composer({ docked }: { docked: boolean }) {const alt = catalog.getModel(FRAMES_MODELS[model.engine].id);const action = alt && alt.id !== model.id ? { label: `Use ${alt.name}`, onClick: () => pickModel(alt) } : undefined;const count = draft.frames.length;- const times = frameTimes(draft.frames.map((f) => f.at), framesCtx.duration);- const gap = framesCtx.chained && count > 1 ? chainGapProblem(times, framesCtx.duration, chainTiming(model)) : null;- const note = framesNote(model, count, draft.frames.at(-1)?.at);+ // On the open chain, a last frame far enough from the end gets a clip of its own after it.+ const tail = framesCtx.chained && count > 0 && framesCtx.duration - framesAt[count - 1] >= OPEN_MIN_GAP - 1e-6;+ const note = framesNote(model, count, draft.frames.at(-1)?.at, { suggested: alt, tail });if (framesCtx.support === "start" || framesCtx.support === "none") framesNotice = { text: `${framesBlocker(model, count)!.message}.`, tone: "warn", action };- else if (gap) framesNotice = { text: `${gap}.`, tone: "warn" };+ else if (framesGap) framesNotice = { text: `${framesGap}.`, tone: "warn" };else if (note) framesNotice = { text: note, tone: "info", action };}const framesChip = config.frames ? (diff --git a/src/components/studio/frames-strip.tsx b/src/components/studio/frames-strip.tsxindex 0077be3d..6f370523 100644--- a/src/components/studio/frames-strip.tsx+++ b/src/components/studio/frames-strip.tsx@@ -1,6 +1,6 @@"use client";-import { Loader2, Minus, Plus, X } from "lucide-react";+import { Loader2, Minus, Plus, TriangleAlert, X } from "lucide-react";import { useId, useRef, useState } from "react";import { toast } from "sonner";import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";@@ -105,16 +105,20 @@ export function FramesStrip({{frames.length > 0 && <Ruler frames={frames} times={times} duration={duration} onMove={onMove} />}{notice && (- <p className={cn("px-1 text-[12px] leading-snug", notice.tone === "warn" ? "text-warning" : "text-muted-foreground")} role={notice.tone === "warn" ? "status" : undefined}>- {notice.text}- {notice.action && (- <>- {" "}- <button type="button" onClick={notice.action.onClick} className="font-medium text-brand-text underline-offset-2 hover:underline">- {notice.action.label}- </button>- </>- )}+ // A warning (Generate waits for it) reads in the body colour beside an amber icon: amber text on white is under 4.5:1.+ <p className={cn("flex items-start gap-1.5 px-1 text-[12px] leading-snug", notice.tone === "warn" ? "text-foreground" : "text-muted-foreground")} role={notice.tone === "warn" ? "status" : undefined}>+ {notice.tone === "warn" && <TriangleAlert aria-hidden className="mt-px size-3.5 shrink-0 text-warning" />}+ <span>+ {notice.text}+ {notice.action && (+ <>+ {" "}+ <button type="button" onClick={notice.action.onClick} className="font-medium text-brand-text underline-offset-2 hover:underline">+ {notice.action.label}+ </button>+ </>+ )}+ </span></p>)}</div>diff --git a/src/lib/composer.ts b/src/lib/composer.tsindex 70377eb9..1fdceb18 100644--- a/src/lib/composer.ts+++ b/src/lib/composer.ts@@ -367,19 +367,32 @@ export function enterFrames<T extends Attachment>(slots: Partial<Record<InputSlo/*** What Frames mode sends: the stills in order at their times (or the first and last as start and end- * frame, as the model takes them), at the strip's length. Frames still uploading (no ref yet) wait.+ * frame, as the model takes them), at the strip's length. Every frame at its time is a keyframes run+ * (`op`, so a camera motion preset's own operation doesn't replace it). A frame still uploading has no+ * ref yet and is left out here, so the composer holds Generate ("Uploading…") until every frame is in.*/export function framesRequest(frames: FrameAttachment[],ctx: { support: FrameSupport; duration: number; chained: boolean },-): { images: string[]; endImage?: string; params: Pick<GenParams, "duration" | "keyframeTimes" | "shots" | "multiShot" | "numOutputs"> } {+): { op?: "keyframes"; images: string[]; endImage?: string; params: Pick<GenParams, "duration" | "keyframeTimes" | "shots" | "multiShot" | "numOutputs"> } {const times = frameTimes(frames.map((f) => f.at), ctx.duration);const kept = frames.map((f, i) => ({ ref: f.value.ref, time: times[i] })).filter((f) => !!f.ref);const sent = framesInputs(kept.map((f) => f.ref), kept.map((f) => f.time), ctx.support);// Frames and shots don't mix; the open chain makes one film (its clips are the jobs).- return { images: sent.images ?? [], endImage: sent.endImage, params: { duration: ctx.duration, keyframeTimes: sent.keyframeTimes, shots: undefined, multiShot: undefined, ...(ctx.chained && { numOutputs: 1 }) } };+ return {+ ...(sent.keyframeTimes && { op: "keyframes" as const }),+ images: sent.images ?? [],+ endImage: sent.endImage,+ params: { duration: ctx.duration, keyframeTimes: sent.keyframeTimes, shots: undefined, multiShot: undefined, ...(ctx.chained && { numOutputs: 1 }) },+ };}+/** Frames mode has its own strip: the studio's start and end frame tiles (a camera motion's too) aren't asked for. */+export const framesSlots = <S extends Pick<InputSlot, "key">>(slots: S[]): S[] => slots.filter((s) => s.key !== "image" && s.key !== "endImage");++/** Frames still uploading: Generate waits for them, as it does for any other attachment. */+export const framesUploading = (frames: FrameAttachment[] | undefined): boolean => !!frames?.some((f) => f.value.uploading);+/*** Frames mode off: the first frame is the start frame again and the last (with two or more) the end* frame. `dropped` counts the frames in between that have no slot to go to (the composer offers Undo).diff --git a/tests/composer-frames.test.ts b/tests/composer-frames.test.tsindex 24e00e42..504aa0aa 100644--- a/tests/composer-frames.test.ts+++ b/tests/composer-frames.test.ts@@ -2,7 +2,22 @@ import { describe, expect, it } from "vitest";import { getModel, getPreset } from "@/lib/catalog";import { frameSupport, framesBlocker, framesDuration, keyframeChain } from "@/lib/catalog/keyframes";import { planGeneration } from "@/lib/catalog/plan";-import { addFrame, blockerFor, enterFrames, framesRequest, framesShape, leaveFrames, removeFrame, replaceAttachment, settingsShape, type Attachment, type FrameAttachment } from "@/lib/composer";+import {+ addFrame,+ blockerFor,+ enterFrames,+ firstMissingSlot,+ framesRequest,+ framesShape,+ framesSlots,+ framesUploading,+ leaveFrames,+ removeFrame,+ replaceAttachment,+ settingsShape,+ type Attachment,+ type FrameAttachment,+} from "@/lib/composer";import { VIDEO_STUDIO } from "@/lib/studios";import { studioCatalog } from "@/lib/studio-catalog";@@ -58,6 +73,7 @@ describe("Frames mode in the Video studio composer", () => {expect(sent.endImage).toBeUndefined();expect(sent.params).toMatchObject({ duration: 8, keyframeTimes: [0, 2.7, 5.3, 8] });expect(sent.params.numOutputs).toBeUndefined();+ expect(sent.op).toBe("keyframes");const plan = planGeneration({ feature: "video", modelId: "flux-3-max", prompt: "a paper boat", inputs: { images: sent.images }, params: sent.params }, getModel, getPreset);expect(plan.op).toBe("keyframes");});@@ -66,16 +82,51 @@ describe("Frames mode in the Video studio composer", () => {const fs = framesOf("a", "b", "c");const sent = framesRequest(fs, ctxFor("kling-o3", 5));expect(sent).toMatchObject({ images: [fs[0].value.ref], endImage: fs[2].value.ref, params: { duration: 5, keyframeTimes: undefined } });+ // The planner picks the operation for the ends (start + end frame, or a start frame alone).+ expect(sent.op).toBeUndefined();const plan = planGeneration({ feature: "video", modelId: "kling-o3", prompt: "x", inputs: { images: sent.images, endImage: sent.endImage }, params: sent.params }, getModel, getPreset);expect(plan.op).toBe("flf2v");expect(framesRequest(framesOf("a"), ctxFor("flux-3-max"))).toMatchObject({ images: ["/api/files/a.png"], params: { keyframeTimes: undefined } });});- it("makes one film on the open chain, and leaves frames still uploading out", () => {- const fs = addFrame(framesOf("a", "b"), still("c", { ref: "", uploading: true }));- const sent = framesRequest(fs, ctxFor("oss-wan22-14b-fast", 8));- expect(sent.images).toEqual(["/api/files/a.png", "/api/files/b.png"]);- expect(sent.params).toMatchObject({ duration: 8, keyframeTimes: [0, 4], numOutputs: 1 });+ it("makes one film on the open chain", () => {+ const sent = framesRequest(framesOf("a", "b", "c"), ctxFor("oss-wan22-14b-fast", 8));+ expect(sent).toMatchObject({ op: "keyframes", images: ["/api/files/a.png", "/api/files/b.png", "/api/files/c.png"], params: { duration: 8, keyframeTimes: [0, 4, 8], numOutputs: 1 } });+ });++ it("holds Generate while a frame is still uploading, so no frame is left out of the run", () => {+ const fs = addFrame(framesOf("a", "b", "c"), still("d", { ref: "", uploading: true }));+ // The frame with no ref yet can't be sent...+ expect(framesRequest(fs, ctxFor("flux-3-max", 5)).images).toHaveLength(3);+ // ...so the composer waits for it, as it waits for any other upload.+ expect(framesUploading(fs)).toBe(true);+ expect(framesUploading(framesOf("a", "b"))).toBe(false);+ expect(framesUploading(undefined)).toBe(false);+ const base = { model: true, frames: framesBlocker(getModel("flux-3-max")!, fs.length), promptMissing: false };+ expect(blockerFor({ ...base, uploading: framesUploading(fs) })).toEqual({ message: "Uploading…" });+ // The start frame uploading too: nothing goes until it's in.+ const first = [{ value: still("s", { ref: "", uploading: true }), at: 0 }, ...framesOf("b", "c").slice(1)];+ expect(blockerFor({ ...base, uploading: framesUploading(first) })?.message).toBe("Uploading…");+ });++ it("doesn't ask for a camera motion's start frame tile: frame 1 is the start frame", () => {+ const preset = getPreset("motion-zoom-in")!;+ expect(firstMissingSlot(preset.inputs!, {})?.key).toBe("image");+ expect(firstMissingSlot(framesSlots(preset.inputs!), {})).toBeUndefined();+ // A transition (start and end frame) too.+ const transition = [{ key: "image" as const, label: "Start frame", accept: "image" as const, required: true }, { key: "endImage" as const, label: "End frame", accept: "image" as const, required: true }];+ expect(firstMissingSlot(framesSlots(transition), {})).toBeUndefined();+ // The motion's words (and, on its own model, its LoRA) go with a keyframes run, not the preset's image-to-video.+ const run = (id: string, presetId: string) => {+ const sent = framesRequest(framesOf("a", "b", "c"), ctxFor(id, 5));+ return planGeneration({ feature: "video", modelId: id, presetId, op: sent.op, prompt: "a fox", inputs: { images: sent.images }, params: sent.params }, getModel, getPreset);+ };+ expect(run("flux-3-max", preset.id)).toMatchObject({ op: "keyframes", prompt: expect.stringMatching(/zooms in/) });+ // Dolly In runs on Wan 2.2 14B with a LoRA: its own operation is image-to-video, which would drop frames 2 and 3.+ expect(getPreset("motion-dolly-in")?.open).toMatchObject({ modelId: "oss-wan22-14b", op: "i2v" });+ const dolly = run("oss-wan22-14b", "motion-dolly-in");+ expect(dolly.op).toBe("keyframes");+ expect(dolly.loras.length).toBeGreaterThan(0);});it("asks for the start frame first and says which models can't follow frames", () => {