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
Faceless: an older Frame by frame render's clips are made again as Ken Burns moves, and Motion reads camera words
Claude257e97900681
diff --git a/src/components/faceless/episode-view.tsx b/src/components/faceless/episode-view.tsxindex b50d0855..f4b03b9a 100644--- a/src/components/faceless/episode-view.tsx+++ b/src/components/faceless/episode-view.tsx@@ -45,6 +45,7 @@ import { NotFoundState } from "@/components/empty-state";import { MediaThumb } from "@/components/studio/feed";import { Viewer } from "@/components/studio/viewer";import {+ CAMERA_WORDS,formatLength,getStyle,PART_LABELS,@@ -236,6 +237,8 @@ function SceneEditor({ view, scenes, onClose, onOpen }: { view: View; scenes: Scconst one = scenes.length === 1 ? scenes[0] : null;const still = one?.still?.generation;const stillImg = still?.outputs.find((o) => o.kind === "image");+ // Frame by frame moves a camera over the picture (Ken Burns): its Motion reads camera words only.+ const camera = ep.settings.animation === "frames" ? CAMERA_WORDS[ep.settings.engine] : null;const discard = () => {setInstruction("");@@ -322,8 +325,8 @@ function SceneEditor({ view, scenes, onClose, onOpen }: { view: View; scenes: SconChange={(e) => setInstruction(e.target.value)}maxLength={1000}rows={2}- aria-label={part === "picture" ? "Describe what to change in the picture" : "Describe the new movement"}- placeholder={part === "picture" ? "e.g. make it night, add a lighthouse on the cliff" : "e.g. slow zoom out, the flags wave in the wind"}+ aria-label={part === "picture" ? "Describe what to change in the picture" : camera ? "Describe the new camera move" : "Describe the new movement"}+ placeholder={part === "picture" ? "e.g. make it night, add a lighthouse on the cliff" : (camera?.placeholder ?? "e.g. slow zoom out, the flags wave in the wind")}className="w-full resize-none rounded-lg border bg-background px-2.5 py-2 text-[14px] outline-none [field-sizing:content] focus:border-primary placeholder:text-subtle-foreground"/>)}@@ -335,7 +338,7 @@ function SceneEditor({ view, scenes, onClose, onOpen }: { view: View; scenes: Sc? part === "picture"? "The picture is edited, then the scene is animated again.": part === "motion"- ? "The picture is kept; the scene is animated again."+ ? (camera?.hint ?? "The picture is kept; the scene is animated again."): "Edit the lines above.": preview.isError? (preview.error as Error).messagediff --git a/src/lib/av/ken-burns.ts b/src/lib/av/ken-burns.tsindex bec1e263..312b2926 100644--- a/src/lib/av/ken-burns.ts+++ b/src/lib/av/ken-burns.ts@@ -55,13 +55,15 @@ const pt = (p: FocusPoint, k = 1000): FocusPoint => ({ x: inward(p.x, k), y: inwexport function readMove(text: string): MoveKind | null {const t = ` ${text.toLowerCase()} `;// Camera words only: "smoke rising" is not a tilt.- if (/\b(zoom(s|ing)? out|pull(s|ing)?[- ](back|out|away)|dolly(ing)? out|widen(s|ing)?|reveal(s|ing)?|draw(s|ing)? back)\b/.test(t)) return "pull-out";- if (/\b(zoom(s|ing)? in|push(es|ing)?[- ]in|push(es|ing)? (slowly |gently )?(towards?|closer|into)|dolly(ing)? in|clos(e|es|ing) in|(camera|it) moves? (in|closer))\b/.test(t)) return "push-in";+ if (/\b(zoom(s|ed|ing)?[- ]?(out|back|away)|pull(s|ed|ing)?[- ](back|out|away)|dolly(ing)?[- ]out|widen(s|ing)?|reveal(s|ing)?|draw(s|ing)? back)\b/.test(t)) return "pull-out";+ if (/\b(zoom(s|ed|ing)?[- ]?(in|into|onto|on|towards?|closer|close)|push(es|ed|ing)?[- ]in|push(es|ing)? (slowly |gently )?(towards?|closer|into)|dolly(ing)?[- ]in|clos(e|es|ing) in|(camera|it) moves? (in|closer))\b/.test(t)) return "push-in";if (/\bpan(s|ning)? (slowly |gently )?(to the |towards? the )?left\b|\bright[- ]to[- ]left\b|\bleftwards?\b/.test(t)) return "pan-left";if (/\bpan(s|ning)? (slowly |gently )?(to the |towards? the )?right\b|\bleft[- ]to[- ]right\b|\brightwards?\b/.test(t)) return "pan-right";if (/\b(tilt(s|ing)?|crane(s|ing)?|pan(s|ning)?) (slowly |gently )?up(wards?)?\b|\bcamera (rises|rising|moves up)\b/.test(t)) return "tilt-up";if (/\b(tilt(s|ing)?|crane(s|ing)?|pan(s|ning)?) (slowly |gently )?down(wards?)?\b|\bcamera (descends|descending|moves down)\b/.test(t)) return "tilt-down";if (/\b(pan(s|ning)?|tracking shot|track(s|ing)? across)\b/.test(t)) return "pan-right";+ // A zoom that says no more ("a slow zoom") goes in.+ if (/\bzoom(s|ed|ing)?\b/.test(t)) return "push-in";return null;}diff --git a/src/lib/catalog/faceless.ts b/src/lib/catalog/faceless.tsindex 8a161528..e94ee936 100644--- a/src/lib/catalog/faceless.ts+++ b/src/lib/catalog/faceless.ts@@ -1363,6 +1363,73 @@ export function planRetry(graph: GraphStep[], status: Record<string, string | unreturn planRerun(graph, broken);}+/** What a kept step's generation was asked for (its stored request). */+export type MadeRequest = Pick<GenerationRequest, "modelId" | "op" | "params">;++/**+ * Whether a bed (or its loop) made with `had` still serves a film that now needs `want`. It has to cover the+ * film; a whole-play loop (cloud) covers its plays of the bed, whatever length was asked (the route plays+ * ⌈duration / bed⌉ times, at least twice). A crossfaded loop (open) fades out at its end, so one left longer+ * than the film by a second or more is made again: its fade-out would fall past the end and the music stop dead.+ */+export function bedFits(had: GenerationRequest["params"], want: GenerationRequest["params"]): boolean {+ const h = had?.duration ?? 0;+ const w = want?.duration ?? 0;+ if (want?.crossfade) return h >= w && h - w < 1 && had?.crossfade === want.crossfade;+ if (want?.sourceDuration && had?.sourceDuration) return Math.max(2, Math.ceil(h / had.sourceDuration - 1e-6)) * had.sourceDuration >= w;+ return h >= w;+}++/**+ * Steps whose kept generation isn't what the graph asks for now, to make again with everything after them:+ * made by another model or operation (a Frame by frame episode rendered before its scenes became Ken Burns+ * moves still holds video-model clips, of other lengths, under the same keys), a clip of another length, or+ * a music bed that no longer serves the film (bedFits).+ */+export function staleSteps(graph: GraphStep[], made: (key: string) => MadeRequest | undefined): string[] {+ return graph+ .filter((s) => {+ const r = made(s.key);+ if (!r) return false;+ if (r.modelId !== s.request.modelId || (r.op ?? null) !== (s.request.op ?? null)) return true;+ if (s.part === "clip") return (r.params?.duration ?? null) !== (s.request.params?.duration ?? null);+ if (s.part === "music" && s.request.params?.duration !== undefined) return !bedFits(r.params, s.request.params);+ return false;+ })+ .map((s) => s.key);+}++/** Whether two Ken Burns requests make the same camera move (a Motion change that reads as the move a scene has). */+export function sameCameraMove(a: MadeRequest, b: MadeRequest): boolean {+ const pa = a.params ?? {};+ const pb = b.params ?? {};+ const pt = (p?: { x: number; y: number }) => (p ? `${p.x},${p.y}` : "");+ return (+ a.modelId === b.modelId &&+ a.op === b.op &&+ pa.duration === pb.duration &&+ pa.zoomFrom === pb.zoomFrom &&+ pa.zoomTo === pb.zoomTo &&+ pt(pa.panFrom) === pt(pb.panFrom) &&+ pt(pa.panTo) === pt(pb.panTo) &&+ pa.easing === pb.easing+ );+}++/** The camera words a Frame by frame Motion change reads, per engine (the cloud's Ken Burns only zooms). */+export const CAMERA_WORDS: Record<Engine, { placeholder: string; hint: string; same: string }> = {+ open: {+ placeholder: "e.g. slow zoom out, pan left toward the tower",+ hint: "The picture is kept; the camera moves again: zoom in or out, pan left or right, tilt up or down, toward a place you name.",+ same: "That's the camera move this scene already has. Name another: zoom in or out, pan left or right, tilt up or down, or a place to head for (the upper left, the sky).",+ },+ cloud: {+ placeholder: "e.g. zoom out, or zoom in toward the upper left",+ hint: "The picture is kept; the camera moves again: a zoom in or out, toward a place you name.",+ same: "That's the camera move this scene already has. Name another: zoom in or zoom out, or a place to head for (the upper left, the sky).",+ },+};+// ---------------------------------------------------------------------------// Costdiff --git a/src/server/faceless.ts b/src/server/faceless.tsindex 9f4a4229..4374d99e 100644--- a/src/server/faceless.ts+++ b/src/server/faceless.ts@@ -6,6 +6,7 @@ import {AUTO_SECONDS,blockCount,buildEpisodeGraph,+ CAMERA_WORDS,changedKeys,channelName,defaultSettings,@@ -31,12 +32,14 @@ import {planRerun,previewLine,resolveModels,+ sameCameraMove,sceneSpans,sceneTiming,scriptBrief,scriptSystem,splitScript,spokenTimes,+ staleSteps,styleRefLimit,TIMING_PARTS,topicsBrief,@@ -794,16 +797,13 @@ function advance(ep: FacelessEpisode): FacelessEpisode {const part = partOf(graph);const status = statusMap(plan.ids);const moved = new Set(blocks.filter((b) => plan.timing?.[b.id] !== timing[b.id]).map((b) => b.id));+ // A step kept from before that the graph now asks for differently is made again too: a bed (or its loop)+ // that no longer fits the film, or a clip made by another model (a Frame by frame episode rendered before+ // its scenes became Ken Burns moves).+ const stale = new Set(staleKeys(graph, plan.ids));const changed = graph- .filter((s) => !plan.ids[s.key] || status[s.key] === "failed" || status[s.key] === "canceled" || (s.part === "clip" && moved.has(blocks[s.block!].id)))+ .filter((s) => !plan.ids[s.key] || status[s.key] === "failed" || status[s.key] === "canceled" || stale.has(s.key) || (s.part === "clip" && moved.has(blocks[s.block!].id))).map((s) => s.key);- // A bed (or its loop) that no longer covers the film is made again.- for (const key of ["music", "music-loop"]) {- const step = graph.find((s) => s.key === key);- if (!step || !plan.ids[key] || changed.includes(key)) continue;- const had = getGeneration(plan.ids[key], { includeDeleted: true })?.request.params?.duration ?? 0;- if (had < (step.request.params?.duration ?? 0)) changed.push(key);- }const rerun = planRerun(graph, changed).rerun.filter((k) => !TIMING_PARTS.has(part(k)));const ids = prune(relaunch(graph, plan.ids, rerun, plan.batchId), graph);const next: EpisodePlan = { ...plan, ids, timing, untimed: !spoken, awaiting: false };@@ -833,6 +833,9 @@ export function renderEpisode(id: string): FacelessEpisode {const statusMap = (ids: Record<string, string>) =>Object.fromEntries(Object.entries(ids).map(([k, id]) => [k, getGeneration(id, { includeDeleted: true })?.status])) as Record<string, string | undefined>;+/** Kept steps whose generation isn't what the graph asks for now (another model or op, a clip of another length, a bed that no longer fits). */+const staleKeys = (graph: GraphStep[], ids: Record<string, string>) => staleSteps(graph, (k) => (ids[k] ? getGeneration(ids[k], { includeDeleted: true })?.request : undefined));+/** Redo the steps that failed (and what waited on them); finished steps are kept. */export function retryEpisode(id: string): FacelessEpisode {const ep = mustEpisode(id);@@ -854,6 +857,8 @@ export function retryEpisode(id: string): FacelessEpisode {}).map((s) => s.key);if (!broken.length && !ep.plan.awaiting) return ep;+ // Kept steps made for an older graph (another model, another length) are redone with what failed.+ broken.push(...staleKeys(graph, ep.plan.ids).filter((k) => !broken.includes(k)));for (const k of planRerun(graph, broken).rerun) if (ep.plan.ids[k]) void cancelGeneration(ep.plan.ids[k]);const { ids, awaiting, started } = launch(ep, graph, ep.plan.ids, broken, ep.plan.batchId);updateEpisodeRow(id, { status: "rendering", error: null, plan_json: JSON.stringify({ ...ep.plan, ids, awaiting } satisfies EpisodePlan) });@@ -908,11 +913,21 @@ function changed(ep: FacelessEpisode, c: ChangeInput) {}}const graph = buildGraph(ep, withTiming(blocks, ep.plan.timing), stillEdits);- // Steps that failed earlier are redone with the change, so the new version can finish.+ // Frame by frame: words that read as the move the scene already has would render the same clip again.+ if (c.part === "motion") {+ const moves = graph.filter((s) => s.part === "clip" && s.request.op === "still-motion" && ids.includes(blocks[s.block!].id));+ const same = moves.every((s) => {+ const g = getGeneration(ep.plan!.ids[s.key] ?? "", { includeDeleted: true });+ return g?.status === "succeeded" && sameCameraMove(g.request, s.request);+ });+ if (moves.length && same) throw new FacelessError(CAMERA_WORDS[ep.settings.engine].same, 422);+ }+ // Steps that failed earlier are redone with the change, so the new version can finish; so are kept steps+ // made for an older graph (another model, another length).const status = statusMap(ep.plan.ids);const part = partOf(graph);const broken = graph.filter((s) => (!status[s.key] && (!ep.plan!.awaiting || TIMING_PARTS.has(part(s.key)))) || status[s.key] === "failed" || status[s.key] === "canceled").map((s) => s.key);- const keys = [...changedKeys(graph, ids, c.part), ...broken];+ const keys = [...new Set([...changedKeys(graph, ids, c.part), ...broken, ...staleKeys(graph, ep.plan.ids)])];return { graph, blocks, stillEdits, keys, plan: planRerun(graph, keys), ids };}diff --git a/tests/av-ken-burns.test.ts b/tests/av-ken-burns.test.tsindex 6a4a3fc7..825d1330 100644--- a/tests/av-ken-burns.test.ts+++ b/tests/av-ken-burns.test.ts@@ -22,6 +22,11 @@ describe("Ken Burns moves", () => {expect(readMove("smoke rising from the chimney")).toBeNull();expect(readMove("camera pans across the market")).toBe("pan-right");expect(readMove("leaves flutter in the wind")).toBeNull();+ // The common ways of asking for a zoom (the timeline's Motion change).+ for (const t of ["zoom into the lighthouse", "zoom-in on the map", "slow zoom toward the castle", "zoom on the face", "a slow zoom", "zoomed in", "push-in"]) expect(readMove(t), t).toBe("push-in");+ for (const t of ["zoom-out", "zooming back to the whole street", "slowly zoom out to reveal the bay", "pulled back"]) expect(readMove(t), t).toBe("pull-out");+ expect(readMove("the flags wave in the wind")).toBeNull();+ expect(readMove("the boat moves closer to the shore")).toBeNull();});it("finds the place the words name, and not a past tense of leave", () => {diff --git a/tests/faceless-api.test.ts b/tests/faceless-api.test.tsindex b56a1537..3e03c7e4 100644--- a/tests/faceless-api.test.ts+++ b/tests/faceless-api.test.ts@@ -436,6 +436,57 @@ describe("Explainer", () => {}});+ it(+ "makes Ken Burns moves again for clips an older Frame by frame render made with a video model, and refuses a Motion change that keeps the move",+ async () => {+ const res = await explainerRoute.POST(json("POST", { prompt: "How lighthouses guide ships", settings: { ...open, music: false, subtitles: false, length: 20 } }));+ const ep: FacelessEpisode = await res.json();+ await faceless.scriptWritten(ep.id);+ const done = await settled(ep.id);+ expect(done.episode.status).toBe("done");+ const blocks = done.episode.script.blocks;+ expect(blocks.length).toBeGreaterThanOrEqual(2);+ const ids = done.episode.plan!.ids;+ const clips = Object.keys(ids).filter((k) => k.startsWith("clip-"));+ expect(clips.every((k) => gens.getGeneration(ids[k])!.modelId === "oss-ken-burns")).toBe(true);++ // Motion in Frame by frame is a camera move: words that read as the move a scene has would remake the same clip.+ const motion = (instruction: string) => changeRoute.POST(json("POST", { blocks: [blocks[1].id], part: "motion", instruction }), params({ id: ep.id }));+ for (const words of ["the flags wave in the wind", blocks[1].motion]) {+ const same = await motion(words);+ expect(same.status, words).toBe(422);+ expect((await same.json()).error).toMatch(/^That's the camera move this scene already has\. Name another: zoom in or out, pan left or right/);+ }+ // Scene 2 pans by the cycle; a zoom is another move.+ const zoom = await (await motion("zoom into the lighthouse")).json();+ expect(zoom.rerun).toEqual([...clips.filter((k) => k.startsWith(`clip-${blocks[1].id}-`)), "join", "mix"]);++ // As an episode rendered before Frame by frame moved a camera: every clip was a Wan 2.2 shot of 5 s.+ for (const k of clips) {+ const g = gens.getGeneration(ids[k])!;+ const request = { ...g.request, modelId: "oss-wan22-14b-fast", op: "i2v", params: { ...g.request.params, duration: 5 } };+ db().prepare("UPDATE generations SET model_id = ?, op = ?, request_json = ? WHERE id = ?").run("oss-wan22-14b-fast", "i2v", JSON.stringify(request), ids[k]);+ }+ // A picture change on scene 1 makes every scene's move again (no old clip is kept under a Ken Burns key).+ const preview = await (await changeRoute.POST(json("POST", { blocks: [blocks[0].id], part: "picture", instruction: "make it stormy" }), params({ id: ep.id }))).json();+ expect(preview.rerun).toEqual(expect.arrayContaining([`still-${blocks[0].id}`, ...clips, "join", "mix"]));+ expect(preview.rerun).not.toContain(`still-${blocks[1].id}`);+ const applied = await changeRoute.POST(json("POST", { blocks: [blocks[0].id], part: "picture", instruction: "make it stormy", apply: true }), params({ id: ep.id }));+ expect(applied.status).toBe(201);+ const redone = await settled(ep.id);+ expect(redone.episode.status).toBe("done");+ const now = redone.episode.plan!.ids;+ for (const k of clips) {+ expect(now[k], k).not.toBe(ids[k]);+ expect(gens.getGeneration(now[k])!.request).toMatchObject({ modelId: "oss-ken-burns", op: "still-motion" });+ }+ expect(now[`still-${blocks[1].id}`]).toBe(ids[`still-${blocks[1].id}`]);+ expect(now.narration).toBe(ids.narration);+ await faceless.deleteEpisode(ep.id);+ },+ 120_000,+ );+it("draws open pictures from the attached images", async () => {const img = (await import("@/server/storage")).saveFile({ data: Buffer.from("x"), contentType: "image/png", name: "subject.png", source: "upload" }).url;const ep = faceless.createEpisode({ kind: "explainer", topic: "Our new kettle", sources: [{ kind: "image", url: img }], settings: { ...open, length: 20 }, autoRender: true });diff --git a/tests/faceless.test.ts b/tests/faceless.test.tsindex b6a67294..e9db12bf 100644--- a/tests/faceless.test.ts+++ b/tests/faceless.test.ts@@ -5,6 +5,7 @@ import { getModel } from "@/lib/catalog";import { buildPayload } from "@/lib/catalog/payload";import type { GenerationRequest } from "@/lib/catalog/types";import {+ bedFits,blockCount,blockShots,buildEpisodeGraph,@@ -49,9 +50,11 @@ import {musicPlan,plannedTiming,resolveModels,+ sameCameraMove,sceneSpans,sceneTiming,spokenTimes,+ staleSteps,styleRefLimit,withTiming,type EpisodeSettings,@@ -337,6 +340,58 @@ describe("timeline re-runs and retries", () => {expect(plan.rerun).not.toContain("narration");expect(planRetry(g, Object.fromEntries(g.map((s) => [s.key, "succeeded"]))).rerun).toEqual([]);});++ it("makes again what an older render kept for a step the graph now asks for differently", () => {+ // A Frame by frame episode rendered before its scenes became Ken Burns moves: Wan 2.2 made each 8 s scene+ // as a 5 s and a 3 s shot. Its Ken Burns graph has one 8 s move per scene under the first shot's key.+ const scenes = [block(0, 20, 8), block(1, 20, 8), block(2, 20, 8)];+ const wan = graphFor({ engine: "open", animation: "animated", music: false, voice: null }, scenes);+ expect(wan.filter((s) => s.block === 0 && s.part === "clip").map((s) => s.seconds)).toEqual([5, 3]);+ const kb = graphFor({ engine: "open", animation: "frames", music: false, voice: null }, scenes);+ expect(kb.filter((s) => s.part === "clip").map((s) => [s.key, s.seconds])).toEqual([+ ["clip-b0-1", 8],+ ["clip-b1-1", 8],+ ["clip-b2-1", 8],+ ]);+ const old = new Map(wan.map((s) => [s.key, s.request]));+ const stale = staleSteps(kb, (k) => old.get(k));+ expect(stale).toEqual(expect.arrayContaining(["clip-b0-1", "clip-b1-1", "clip-b2-1", "join"]));+ expect(stale).not.toContain("still-b0");+ expect(stale).not.toContain("narration");+ // Its own requests are never stale; a clip of another length is.+ const own = new Map(kb.map((s) => [s.key, s.request]));+ expect(staleSteps(kb, (k) => own.get(k))).toEqual([]);+ const longer = (k: string) => (k === "clip-b1-1" ? { ...own.get(k)!, params: { ...own.get(k)!.params, duration: 9 } } : own.get(k));+ expect(staleSteps(kb, longer)).toEqual(["clip-b1-1"]);+ });++ it("keeps a music bed while it still serves the film", () => {+ // A plain bed: as long as it covers the film.+ expect(bedFits({ duration: 61 }, { duration: 55 })).toBe(true);+ expect(bedFits({ duration: 61 }, { duration: 70 })).toBe(false);+ // Whole plays (cloud): 2 plays of 600 s cover a film that grew from 650 s to 660 s.+ expect(bedFits({ duration: 651, sourceDuration: 600 }, { duration: 661, sourceDuration: 600 })).toBe(true);+ expect(bedFits({ duration: 651, sourceDuration: 600 }, { duration: 1201, sourceDuration: 600 })).toBe(false);+ // A crossfaded loop (open) ends on its fade-out: remade when the film grows, or shrinks by a second or more.+ const loop = { duration: 301, sourceDuration: 240, crossfade: 3 };+ expect(bedFits(loop, loop)).toBe(true);+ expect(bedFits(loop, { ...loop, duration: 305 })).toBe(false);+ expect(bedFits(loop, { ...loop, duration: 299 })).toBe(false);+ // In a graph: the loop step is judged so, the bed itself by length.+ const g = graphFor({ engine: "open", music: true, voice: null }, placeholderBlocks(300));+ const made = new Map(g.map((s) => [s.key, s.request]));+ const shorter = graphFor({ engine: "open", music: true, voice: null }, placeholderBlocks(280));+ expect(staleSteps(shorter, (k) => made.get(k))).toEqual(["music-loop"]);+ });++ it("knows a Motion change that reads as the move a scene already has", () => {+ const moves = (motion: string) => graphFor({ engine: "open", animation: "frames", music: false, voice: null }, [block(0), { ...block(1), motion }]).find((s) => s.key === "clip-b1-1")!.request;+ // Scene 2 pans right by the cycle: words with no camera move keep it, a zoom is another move.+ const cycle = moves("");+ expect(sameCameraMove(cycle, moves("the flags wave in the wind"))).toBe(true);+ expect(sameCameraMove(cycle, moves("zoom into the lighthouse"))).toBe(false);+ expect(sameCameraMove(cycle, moves("pan right toward the upper left"))).toBe(false);+ });});describe("cost", () => {