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
import { execFileSync } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
import { beforeAll, describe, expect, it } from "vitest";
import type { CinemaGenerateInput } from "@/lib/catalog/cinema";
import { tempDir } from "./helpers/temp-dir";
/** Blockout to film (package blockout-film): the scene maths, beats, prompts, shots, windows, plans, payloads and the API. */
const dir = tempDir("fuobe-blockout-");
process.env.FUOBE_DATA_DIR = dir;
process.env.COMFYUI_URL = "http://127.0.0.1:9";
process.env.OLLAMA_URL = "http://127.0.0.1:9";
const { setSetting } = await import("@/server/settings");
const gens = await import("@/server/generations");
const cinema = await import("@/server/cinema");
const generateRoute = await import("@/app/api/cinema/projects/[id]/generate/route");
const { saveFile } = await import("@/server/storage");
const { encodePng } = await import("@/server/png");
const { getModel } = await import("@/lib/catalog");
const { buildPayload } = await import("@/lib/catalog/payload");
const { estimateCost } = await import("@/lib/catalog/plan");
const { prepareWorkflow } = await import("@/server/providers/comfyui");
const { BLOCKOUT_FIRST, BLOCKOUT_MODELS, blockoutPrompt, planCinema } = await import("@/lib/catalog/cinema");
const B = await import("@/lib/blockout");
beforeAll(() => {
setSetting("demoMode", "auto");
setSetting("enhanceProvider", "none");
});
const VIDEO = "/api/files/uploads/blockout.webm";
const DEPTH = "/api/files/uploads/blockout-depth.webm";
const FRAME = "/api/files/uploads/blockout-first.png";
const REFS: import("@/lib/blockout").BlockoutRef[] = [
{ url: "/api/files/uploads/interior.png", role: "interior" },
{ url: "/api/files/uploads/mara.png", role: "character", name: "Mara" },
{ url: "/api/files/uploads/exterior.png", role: "exterior" },
];
/** fal's Seedance 2.5 price: h × w × (input + output) × 24 / 1024 tokens at $0.0214 per 1K (1080p $0.0234), × 0.6 with a clip in. */
const seedanceUsd = (pixels: number, input: number, output: number, perK = 0.0214) => ((pixels * (input + output) * 24) / 1024 / 1000) * perK * (input > 0 ? 0.6 : 1);
const exampleBeats = () => B.beatsFrom(B.EXAMPLE_SCENE.markers, B.EXAMPLE_SCENE.duration, B.EXAMPLE_WORDS);
const ctx = { cloudAllowed: true };
const film = (engine: "cloud" | "open", over: Partial<NonNullable<CinemaGenerateInput["blockout"]>> = {}, more: Partial<CinemaGenerateInput> = {}): CinemaGenerateInput => ({
engine,
mode: "video",
action: "blockout",
prompt: "",
settings: {},
blockout: { video: VIDEO, seconds: 8, beats: exampleBeats(), refs: REFS, style: "Low-key horror, cold torchlight, 35 mm film grain", sounds: ["Footsteps on concrete", "A long door creak"], avoid: ["jump cuts", "text on screen"], ...over },
...more,
});
describe("the scene", () => {
it("moves a primitive in a line between its keys and holds before and after them", () => {
const walker = B.EXAMPLE_SCENE.prims.find((p) => p.id === "walker")!;
expect(B.primAt(walker, -1).position).toEqual([0, 0, -1]);
expect(B.primAt(walker, 2.2).position[2]).toBeCloseTo(-5.3, 5);
expect(B.primAt(walker, 99).position).toEqual([0, 0, -13.2]);
expect(B.primSpeed(walker, 2)).toBeCloseTo(8.6 / 4.4, 2);
expect(B.primSpeed(walker, 5)).toBeLessThan(0.2);
const box = B.newPrim("box");
expect(B.primAt(box, 3)).toEqual({ position: [0, 0, 0], rotation: 0 });
});
it("eases the camera between keys, zooms evenly in ratio and shakes the same way every render", () => {
const keys: import("@/lib/blockout").BlockoutCameraKey[] = [
{ t: 0, position: [0, 1.6, 0], target: [0, 1.6, -5], lens: 24, shake: 0 },
{ t: 4, position: [0, 1.6, -4], target: [0, 1.6, -9], lens: 96, shake: 0 },
];
const mid = B.cameraAt(keys, 2);
expect(mid.position[2]).toBeCloseTo(-2, 6);
expect(mid.lens).toBeCloseTo(48, 6);
// Eased: a quarter of the time covers less than a quarter of the way.
expect(-B.cameraAt(keys, 1).position[2]).toBeLessThan(1);
const shaky = keys.map((k) => ({ ...k, shake: 1 }));
const a = B.cameraAt(shaky, 1.3);
expect(a).toEqual(B.cameraAt(shaky, 1.3));
expect(Math.hypot(a.position[0], a.position[1] - 1.6)).toBeGreaterThan(0.001);
expect(Math.abs(a.position[0])).toBeLessThan(0.05);
expect(B.shakeAt(2, 0)).toEqual({ offset: [0, 0, 0], aim: [0, 0, 0] });
});
it("frames the lens like a full-frame camera and renders in even multiples of 16", () => {
expect(B.lensVFov(24, 1.5)).toBeCloseTo(53.13, 1);
expect(B.lensVFov(24, 16 / 9)).toBeLessThan(B.lensVFov(24, 1.5));
expect(B.blockoutSize("16:9")).toEqual({ width: 1280, height: 720 });
expect(B.blockoutSize("9:16", 832)).toEqual({ width: 464, height: 832 });
expect(B.aspectOf("2.39:1")).toBeCloseTo(2.39);
expect(B.aspectOf("nonsense")).toBeCloseTo(16 / 9);
});
it("frames the camera from the builder's number fields: the key at the playhead, or a new one from the pose there", () => {
const s = B.emptyScene();
s.camera = [
{ t: 0, position: [0, 1.6, 0], target: [0, 1.6, -5], lens: 24, shake: 0.4 },
{ t: 4, position: [0, 1.6, -4], target: [0, 1.6, -9], lens: 96, shake: 0.4 },
];
// Between keys the fields read the eased pose with no shake in it.
const mid = B.cameraKeyAt(s.camera, 2);
expect(mid).toMatchObject({ t: 2, lens: expect.closeTo(48, 6), shake: expect.closeTo(0.4, 6) });
expect(mid.position).toEqual([0, 1.6, -2]);
const typed = B.withCameraKey(s, 2, { position: [1, 2, -2] });
expect(typed.camera.map((k) => k.t)).toEqual([0, 2, 4]);
expect(typed.camera[1]).toMatchObject({ position: [1, 2, -2], target: [0, 1.6, -7] });
// A key already there is changed in place; a lens is kept in range.
const again = B.withCameraKey(typed, 2.02, { lens: 5 });
expect(again.camera).toHaveLength(3);
expect(again.camera[1]).toMatchObject({ position: [1, 2, -2], lens: B.BLOCKOUT.lens.min });
expect(B.withCameraKey({ ...s, camera: Array.from({ length: B.BLOCKOUT.maxCameraKeys }, (_, i) => ({ ...B.DEFAULT_CAMERA, t: i })) }, 0.5, { lens: 50 }).camera).toHaveLength(B.BLOCKOUT.maxCameraKeys);
});
it("makes a caller's scene safe: numbers in range, lists capped, a camera always there", () => {
const s = B.normalizeScene({ duration: 999, prims: [{ kind: "box", position: [1e9, NaN, 2], size: [-2, 1, 1] }, { kind: "rocket" }], markers: [{ t: 80, label: "" }], camera: [] });
expect(s.duration).toBe(B.BLOCKOUT.maxSeconds);
expect(s.prims).toHaveLength(1);
expect(s.prims[0].position).toEqual([500, 0, 2]);
expect(s.prims[0].size).toEqual([2, 1, 1]);
expect(s.camera).toEqual([B.DEFAULT_CAMERA]);
expect(s.markers[0]).toMatchObject({ t: 60, label: "Beat 1" });
expect(B.normalizeScene(B.EXAMPLE_SCENE)).toEqual(B.EXAMPLE_SCENE);
});
});
describe("beats and the prompt", () => {
it("turns markers into beats that run to the next marker, with an opening when the first is late", () => {
expect(exampleBeats().map((b) => [b.label, b.start, b.end])).toEqual([
["Arrival", 0, 4.5],
["The door opens", 4.5, 6],
["Into the dark", 6, 8],
]);
const late = B.beatsFrom([{ id: "x", t: 3, label: "Lights out" }], 10);
expect(late.map((b) => [b.id, b.label, b.start, b.end])).toEqual([
["start", "Opening", 0, 3],
["x", "Lights out", 3, 10],
]);
// A caller's beats: sorted, inside the blockout, each running to the next.
expect(B.normalizeBeats([{ start: 5, label: "B" }, { start: 0, label: "A", words: "Hi" }], 8).map((b) => [b.label, b.start, b.end, b.words])).toEqual([
["A", 0, 5, "Hi"],
["B", 5, 8, ""],
]);
});
it("compiles Seedance's prompt in the workflow's structure, with @ tags matching the attached references", () => {
const p = B.compileBlockoutPrompt({ beats: exampleBeats(), refs: REFS, target: "seedance", style: "Low-key horror", sound: true, audio: ["Footsteps"], avoid: ["text on screen"] });
expect(p.split("\n\n").map((s) => s.split(":")[0])).toEqual(["Subject", "Action", "Camera", "Style", "Constraints", "Audio", "No"]);
expect(p).toContain("@Video1 is a grey-box 3D blockout");
expect(p).toContain("@Image1 is the interior");
expect(p).toContain("@Image2 is Mara, the main character");
expect(p).toContain("@Image3 is the exterior");
expect(p).not.toContain("@Image4");
expect(p).toContain("0.0–4.5s — Arrival: A woman walks slowly down the narrow corridor");
expect(p).toContain("4.5–6.0s — The door opens: She stops.");
expect(p).toContain("Follow @Video1 exactly");
expect(p).toContain("Events happen in this order: Arrival, then The door opens, then Into the dark.");
expect(p).toMatch(/Audio: Footsteps\./);
expect(p).toMatch(/No: text on screen\./);
// Sound off: no audio list.
expect(B.compileBlockoutPrompt({ beats: exampleBeats(), refs: REFS, target: "seedance", audio: ["Footsteps"] })).not.toContain("Audio:");
// A later shot names the hand-over frame.
expect(B.compileBlockoutPrompt({ beats: exampleBeats(), refs: REFS, target: "seedance", previousFrame: 4 })).toContain("@Image4 is the last frame of the shot before");
});
it("writes H3 Max's scene intent without tags inside its 2000 characters, and a short prompt for Wan", () => {
const long = Array.from({ length: 20 }, (_, i) => ({ id: `b${i}`, start: i, end: i + 1, label: `Beat ${i}`, words: "x".repeat(300) }));
const h3 = B.compileBlockoutPrompt({ beats: long, refs: REFS, target: "h3" });
expect(h3.length).toBeLessThanOrEqual(B.H3_INTENT_MAX);
expect(h3).not.toContain("@");
expect(h3).toContain("Reference 2 is Mara");
const open = B.compileBlockoutPrompt({ beats: exampleBeats(), refs: REFS, target: "open", style: "Low-key horror" });
expect(open.length).toBeLessThanOrEqual(B.OPEN_PROMPT_MAX);
expect(open).toMatch(/^Low-key horror\. Mara in the scene\. A woman walks/);
});
it("writes each reference's role for you, from where it came", () => {
expect(B.roleFor({ category: "character" })).toBe("character");
expect(B.roleFor({ category: "location" })).toBe("location");
expect(B.roleFor({ category: "prop" })).toBe("prop");
expect(B.roleFor(undefined)).toBe("location");
for (const r of B.REF_ROLES) expect(B.roleSentence({ role: r.id }, "@Image1")).toMatch(/^@Image1 is /);
expect(B.blockoutFramePrompt(REFS.slice(0, 2), "Cold light")).toContain("Picture 2 is the interior; picture 3 is the person the mannequin becomes (Mara). Cold light.");
});
it("clips beats to a shot and times them from its start", () => {
expect(B.beatsIn(exampleBeats(), 4, 8).map((b) => [b.label, b.start, b.end])).toEqual([
["Arrival", 0, 0.5],
["The door opens", 0.5, 2],
["Into the dark", 2, 4],
]);
});
});
describe("shots and windows", () => {
it("cuts a long blockout at its markers, each shot within the model's limit", () => {
expect(B.splitShots(28, [0, 7.8, 15, 22], 30)).toEqual([{ index: 0, start: 0, end: 28 }]);
expect(B.splitShots(42, [0, 10, 24, 33], 30, 4)).toEqual([
{ index: 0, start: 0, end: 24 },
{ index: 1, start: 24, end: 42 },
]);
// No marker in reach: cut at the limit, never leaving a sliver behind.
expect(B.splitShots(31, [], 15, 4)).toEqual([
{ index: 0, start: 0, end: 15 },
{ index: 1, start: 15, end: 27 },
{ index: 2, start: 27, end: 31 },
]);
expect(B.splitShots(16, [], 15, 4).map((s) => [s.start, s.end])).toEqual([
[0, 12],
[12, 16],
]);
});
it("lays 81-frame windows at 16 fps that hand over on a shared frame, each 4n+1 frames", () => {
const w = B.depthWindows(8);
expect(w.map((x) => [x.startFrame, x.frames])).toEqual([
[0, 81],
[80, 45],
]);
expect(w[1].start).toBe(5);
for (const x of B.depthWindows(37)) expect((x.frames - 1) % 4).toBe(0);
expect(B.depthWindows(5).map((x) => x.frames)).toEqual([77]);
expect(B.depthWindows(5.1).map((x) => x.frames)).toEqual([81]);
expect(B.depthWindows(999)).toHaveLength(B.OPEN_MAX_WINDOWS);
expect(B.windowsSeconds(B.depthWindows(8))).toBeCloseTo(125 / 16, 2);
});
});
describe("planning a blockout", () => {
it("cloud, Seedance 2.5: one reference-to-video call with the blockout as @Video1, the stills, sound on and the length", () => {
const plan = planCinema(film("cloud"), ctx);
expect(plan.blocker).toBeUndefined();
expect(plan.model.id).toBe("seedance-2-5");
expect(plan.steps).toHaveLength(1);
const r = plan.steps[0].request;
expect(r).toMatchObject({ feature: "cinema-blockout", modelId: "seedance-2-5", op: "ref2v", inputs: { videos: [VIDEO], images: REFS.map((x) => x.url) } });
expect(r.params).toMatchObject({ duration: 8, resolution: "720p", aspectRatio: "auto", generateAudio: true });
expect(r.prompt).toContain("@Image2 is Mara");
expect(r.prompt).toMatch(/Audio: Footsteps on concrete; A long door creak\./);
// Seedance 2.5 bills the 8 s blockout with the 8 s film, at 0.6 times the rate (fal's formula).
expect(r.params?.clipSeconds).toBe(8);
expect(plan.costUsd).toBeCloseTo(seedanceUsd(1280 * 720, 8, 8), 2);
expect(plan.notes.join(" ")).toMatch(/reference video \(@Video1\).*sound on/);
expect(plan.notes.join(" ")).toMatch(/bills the blockout's seconds with the film's/);
// Per resolution: 480p is 864 × 496, 1080p 1920 × 1080 at $0.0234 per 1K tokens.
expect(planCinema(film("cloud", {}, { resolution: "480p" }), ctx).costUsd).toBeCloseTo(seedanceUsd(864 * 496, 8, 8), 2);
expect(planCinema(film("cloud", {}, { resolution: "1080p" }), ctx).costUsd).toBeCloseTo(seedanceUsd(1920 * 1080, 8, 8, 0.0234), 2);
});
it("cloud: an edited prompt is sent as written, and the prompt the composer shows is the one it would send", () => {
expect(planCinema(film("cloud", {}, { prompt: "My own words" }), ctx).steps[0].request.prompt).toBe("My own words");
expect(blockoutPrompt(film("cloud"))).toBe(planCinema(film("cloud"), ctx).steps[0].request.prompt);
expect(blockoutPrompt(film("cloud", {}, { modelId: "minimax-h3-max-3d" }))).toBe(planCinema(film("cloud", {}, { modelId: "minimax-h3-max-3d" }), ctx).steps[0].request.prompt);
});
it("cloud: longer than 30 s it is cut at the markers into shots that hand over a frame, then joined", () => {
const beats = [
{ start: 0, label: "Arrival", words: "She arrives." },
{ start: 14, label: "Lights out", words: "The lights die." },
{ start: 26, label: "Door kicked", words: "The door bursts open." },
];
const plan = planCinema(film("cloud", { seconds: 40, beats }, { prompt: "edited" }), ctx);
expect(plan.blocker).toBeUndefined();
expect(plan.steps.map((s) => s.key)).toEqual(["cut0", "shot0", "last0", "cut1", "shot1", "join"]);
const [cut0, shot0, , cut1, shot1, join] = plan.steps;
expect(cut0.request).toMatchObject({ modelId: "trim-video", op: "trim", inputs: { video: VIDEO }, params: { startTime: 0, endTime: 26 } });
expect(cut1.request.params).toMatchObject({ startTime: 26, endTime: 40 });
expect(shot0.after).toEqual(["cut0"]);
expect(shot0.request.chain).toEqual([{ slot: "videos", position: "first" }]);
expect(shot0.request.params?.duration).toBe(26);
expect(shot1.after).toEqual(["cut1", "last0"]);
expect(shot1.request.chain).toEqual([
{ slot: "videos", position: "first" },
{ slot: "images", position: "last" },
]);
// Three stills plus the hand-over frame: Seedance takes four.
expect(shot1.request.inputs?.images).toEqual(REFS.map((x) => x.url));
expect(shot1.request.prompt).toContain("@Image4 is the last frame of the shot before");
expect(shot1.request.prompt).toContain("0.0–14.0s — Door kicked: The door bursts open.");
expect(shot0.request.prompt).not.toBe("edited");
expect(join.request).toMatchObject({ modelId: "join-clips", op: "concat" });
expect(join.after).toEqual(["shot0", "shot1"]);
expect(plan.notes.join(" ")).toMatch(/filmed as 2 shots cut at your markers \(0–26 s, 26–40 s\)/);
// Each shot bills its cut with its film: 26 + 26 and 14 + 14 seconds at 720p, plus a few cents of cutting and joining.
expect(shot0.request.params?.clipSeconds).toBe(26);
expect(shot1.request.params?.clipSeconds).toBe(14);
const films = seedanceUsd(1280 * 720, 26, 26) + seedanceUsd(1280 * 720, 14, 14);
expect(plan.costUsd).toBeGreaterThan(films - 0.01);
expect(plan.costUsd).toBeLessThan(films + 0.1);
});
it("cloud, H3 Max 3D to video: its own model, 15 s shots, up to 8 stills, no sound, and its processing fee in the price", () => {
const plan = planCinema(film("cloud", { seconds: 12 }, { modelId: "minimax-h3-max-3d" }), ctx);
expect(plan.model.id).toBe("minimax-h3-max-3d");
const r = plan.steps[0].request;
expect(r).toMatchObject({ op: "v2v", inputs: { video: VIDEO, images: REFS.map((x) => x.url) }, params: { resolution: "768P", duration: 12 } });
expect(r.params?.generateAudio).toBeUndefined();
expect(r.prompt).not.toContain("@");
expect(plan.costUsd).toBeCloseTo(12 * 0.08 + 0.5, 3);
expect(plan.notes.join(" ")).toMatch(/makes no sound/);
// A 3 s shot bills 5 s.
expect(planCinema(film("cloud", { seconds: 3 }, { modelId: "minimax-h3-max-3d" }), ctx).costUsd).toBeCloseTo(5 * 0.08 + 0.5, 3);
const long = planCinema(film("cloud", { seconds: 20 }, { modelId: "minimax-h3-max-3d" }), ctx);
expect(long.steps.filter((s) => s.key.startsWith("shot")).map((s) => s.request.params?.duration)).toEqual([6, 14]);
// No shot is cut under the 5 s H3 bills anyway: 16 s is 11 + 5, not 14 + 2.
const sixteen = planCinema(film("cloud", { seconds: 16, beats: [{ start: 0, label: "All" }] }, { modelId: "minimax-h3-max-3d" }), ctx);
expect(sixteen.steps.filter((s) => s.key.startsWith("shot")).map((s) => s.request.params?.duration)).toEqual([11, 5]);
expect(plan.notes.join(" ")).toMatch(/at least 5 s, and counts every camera cut inside an uploaded render as a shot/);
expect(long.steps.find((s) => s.key === "shot1")!.request.chain).toEqual([
{ slot: "video", position: "first" },
{ slot: "images", position: "last" },
]);
});
it("cloud, H3 Max 3D to video: an edited prompt over 2000 characters is refused before it is sent", () => {
const h3 = (prompt: string) => planCinema(film("cloud", { seconds: 10 }, { modelId: "minimax-h3-max-3d", prompt }), ctx);
expect(h3("x".repeat(2000)).blocker).toBeUndefined();
expect(h3("x".repeat(2000)).steps[0].request.prompt).toHaveLength(2000);
expect(h3("x".repeat(5000)).blocker).toMatch(/up to 2000 characters, and yours has 5000/);
// Seedance has no such limit, and a many-shot H3 film compiles each shot's own prompt.
expect(planCinema(film("cloud", {}, { prompt: "x".repeat(5000) }), ctx).blocker).toBeUndefined();
expect(planCinema(film("cloud", { seconds: 20 }, { modelId: "minimax-h3-max-3d", prompt: "x".repeat(5000) }), ctx).blocker).toBeUndefined();
});
it("cloud, H3 Max 3D to video: with no stills it draws two references of its own, priced", () => {
const bare = planCinema(film("cloud", { seconds: 12, refs: [] }, { modelId: "minimax-h3-max-3d" }), ctx);
expect(bare.costUsd).toBeCloseTo(12 * 0.08 + 0.5 + 2 * 0.1, 3);
expect(bare.notes.join(" ")).toMatch(/With no stills, MiniMax H3 Max 3D to video draws up to 2 references of its own \(\$0\.10 each, in the price\)/);
// A later shot carries the hand-over frame, so only the first draws its own.
const two = planCinema(film("cloud", { seconds: 20, refs: [] }, { modelId: "minimax-h3-max-3d" }), ctx);
expect(two.costUsd).toBeCloseTo(6 * 0.08 + 14 * 0.08 + 2 * 0.5 + 2 * 0.1, 1);
const m = getModel("minimax-h3-max-3d")!;
expect(estimateCost(m, { resolution: "768P", duration: 10, drawnRefs: 2 }, 1, "v2v")).toBeCloseTo(10 * 0.08 + 0.5 + 0.2, 3);
});
it("cloud: a WebM blockout is refused on Seedance 2.5, which takes MP4 or MOV", () => {
expect(planCinema(film("cloud", { webm: true }), ctx).blocker).toMatch(/takes MP4 or MOV blockouts, and this one is WebM/);
expect(planCinema(film("cloud", { webm: true, seconds: 12 }, { modelId: "minimax-h3-max-3d" }), ctx).blocker).toBeUndefined();
expect(planCinema(film("open", { webm: true }), ctx).blocker).toBeUndefined();
});
it("open: the first frame from the references, then depth windows chained by their last frame and joined, free", () => {
const plan = planCinema(film("open", { depth: DEPTH, firstFrame: FRAME }), ctx);
expect(plan.blocker).toBeUndefined();
expect(plan.model.id).toBe(BLOCKOUT_MODELS.open);
expect(plan.costUsd).toBe(0);
expect(plan.steps.map((s) => s.key)).toEqual(["look", "seg0", "win0", "last0", "seg1", "win1", "join"]);
const step = (k: string) => plan.steps.find((s) => s.key === k)!;
expect(step("look").request).toMatchObject({ modelId: "oss-qwen-edit", op: "edit", inputs: { images: [FRAME, REFS[0].url, REFS[1].url] } });
expect(step("seg1").request).toMatchObject({ modelId: "oss-segment", op: "trim", inputs: { video: DEPTH }, params: { startTime: 5, endTime: 7.8125, fps: 16, resolution: "480p", aspectRatio: "16:9" } });
expect(step("win0").after).toEqual(["seg0", "look"]);
expect(step("win1").after).toEqual(["seg1", "last0"]);
expect(step("win1").request).toMatchObject({ modelId: "oss-wan22-vace-blockout", op: "v2v", params: { duration: 45 / 16 }, chain: [{ slot: "video" }, { slot: "images", position: "first" }] });
expect(step("win1").request.prompt).toContain("She stops.");
expect(step("win1").request.prompt).not.toContain("walks slowly");
expect(step("last0").request).toMatchObject({ modelId: "oss-extract-frame", op: "frame", chain: [{ slot: "video" }] });
expect(step("join").request).toMatchObject({ modelId: "oss-join-encoded", op: "concat" });
expect(plan.notes.join(" ")).toMatch(/not the dialogue or sound: add sound afterwards with Sound for video/);
expect(step("win0").request.params?.extra).toBeUndefined();
// A near = dark pass (Blender's mist) is inverted by the graph in every window.
const mist = planCinema(film("open", { depth: DEPTH, firstFrame: FRAME, depthInvert: true }), ctx);
for (const k of ["win0", "win1"]) expect(mist.steps.find((s) => s.key === k)!.request.params?.extra).toEqual({ invertDepth: true });
// Without a depth pass there is nothing to invert.
expect(planCinema(film("open", { depthInvert: true }), ctx).steps.find((s) => s.key === "win0")!.request.params?.extra).toBeUndefined();
});
it("open: an upload without depth reads it with Depth Anything 3 and cuts its own first frame", () => {
const plan = planCinema(film("open", { seconds: 4 }), ctx);
expect(plan.model.id).toBe(BLOCKOUT_MODELS.openNoDepth);
expect(plan.steps.map((s) => s.key)).toEqual(["grab", "look", "seg0", "win0"]);
expect(plan.steps[0].request).toMatchObject({ modelId: "oss-extract-frame", inputs: { video: VIDEO }, params: { startTime: 0, endTime: 0.5, extra: { frameIndex: 0 } } });
expect(plan.steps[1]).toMatchObject({ after: ["grab"], request: { chain: [{ slot: "images", position: "first" }] } });
expect(plan.steps[2].request.inputs).toEqual({ video: VIDEO });
expect(plan.notes.join(" ")).toMatch(/Depth Anything 3/);
});
it("waits for a blockout, and prices the run before one is added", () => {
const none = planCinema({ ...film("cloud"), blockout: undefined }, ctx);
expect(none.blocker).toBe(BLOCKOUT_FIRST);
const blank = planCinema(film("cloud", { video: "" }), ctx);
expect(blank.blocker).toBe(BLOCKOUT_FIRST);
expect(blank.costUsd).toBeGreaterThan(0);
expect(planCinema(film("cloud", { seconds: 1 }), ctx).blocker).toMatch(/at least 2 s/);
});
});
describe("the hosted models and the graph", () => {
it("H3 Max 3D to video sends the blockout, the stills, the words and the quality, and nothing it doesn't take", () => {
const m = getModel("minimax-h3-max-3d")!;
expect(m.hidden).toBe(true);
const route = m.routes[0];
expect(route).toMatchObject({ op: "v2v", provider: "fal", endpoint: "minimax/h3-max/3d-to-video" });
const body = buildPayload(route.map!, { prompt: "Scene", video: "https://fal.test/b.webm", images: ["https://fal.test/a.png"], resolution: "1080P", duration: 12 });
expect(body).toEqual({ prompt: "Scene", video_url: "https://fal.test/b.webm", reference_image_urls: ["https://fal.test/a.png"], resolution: "1080P" });
expect(estimateCost(m, { resolution: "1080P", duration: 10 }, 1, "v2v")).toBeCloseTo(2.1, 3);
});
it("Seedance 2.5's reference route takes the blockout as video_urls and the stills as image_urls", () => {
const route = getModel("seedance-2-5")!.routes.find((r) => r.op === "ref2v")!;
const body = buildPayload(route.map!, { prompt: "p", videos: ["https://fal.test/b.webm"], images: ["https://fal.test/a.png"], duration: 8, generateAudio: true, resolution: "720p", aspectRatio: "auto" });
expect(body).toMatchObject({ video_urls: ["https://fal.test/b.webm"], image_urls: ["https://fal.test/a.png"], duration: "8", generate_audio: true });
});
it("the open graph is validated and binds the depth, the first frame, the words, the window's size and length", async () => {
const manifest = JSON.parse(fs.readFileSync("workflows/comfyui/manifest.json", "utf8")) as { workflows: { id: string; validated?: boolean; customNodes: unknown[]; license: string }[] };
const w = manifest.workflows.find((x) => x.id === "video-blockout-wan22-fun-vace")!;
expect(w.validated).toBe(true);
expect(w.customNodes).toEqual([]);
expect(w.license).toMatch(/Apache-2.0/);
const { workflow } = await prepareWorkflow(
"video-blockout-wan22-fun-vace",
{ prompt: "She walks", images: ["first.png"], video: "depth.webm", aspectRatio: "16:9", resolution: "480p", duration: 81 / 16, seed: 3 },
{ generationId: "gen-b", op: "v2v", upload: async (_d, _t, name) => name },
);
expect(workflow["1"].inputs.file).toBe("depth.webm");
expect(workflow["4"].inputs.image).toBe("first.png");
expect(workflow["12"].inputs.text).toBe("She walks");
expect([workflow["15"].inputs.width, workflow["15"].inputs.height]).toEqual([848, 480]);
expect(workflow["30"].inputs.value).toBe(81);
expect(workflow["32"].inputs.image).toEqual(["3", 0]);
expect(workflow["26"].inputs.audio).toBeUndefined();
expect(Object.values(workflow).some((n) => /^DA3/.test(n.class_type))).toBe(false);
// The depth goes to VACE through a switch: as it is by default, inverted for a near = dark pass.
expect(workflow["33"].inputs["images.image1"]).toEqual(["43", 0]);
expect(workflow["43"]).toMatchObject({ class_type: "ComfySwitchNode", inputs: { switch: ["41", 0], on_false: ["32", 0], on_true: ["42", 0] } });
expect(workflow["42"]).toMatchObject({ class_type: "ImageInvert", inputs: { image: ["32", 0] } });
expect(workflow["41"].inputs.value).toBe(false);
const inverted = await prepareWorkflow(
"video-blockout-wan22-fun-vace",
{ prompt: "She walks", images: ["first.png"], video: "mist.webm", aspectRatio: "16:9", resolution: "480p", duration: 81 / 16, extra: { invertDepth: true } },
{ generationId: "gen-c", op: "v2v", upload: async (_d, _t, name) => name },
);
expect(inverted.workflow["41"].inputs.value).toBe(true);
});
it("Seedance 2.5 is priced by fal's token formula: input and output seconds, 0.6 times with reference clips, per resolution", () => {
const m = getModel("seedance-2-5")!;
// fal's own worked examples (bytedance/seedance-2.5/reference-to-video, read 2026-11-01).
expect(estimateCost(m, { duration: 10, resolution: "720p" }, 1, "ref2v")).toBeCloseTo(4.62, 2);
expect(estimateCost(m, { duration: 10, resolution: "720p", clipSeconds: 8 }, 1, "ref2v")).toBeCloseTo(4.99, 2);
expect(estimateCost(m, { duration: 30, resolution: "720p", clipSeconds: 10 }, 1, "ref2v")).toBeCloseTo(11.09, 2);
// No floor: a short clip bills its own seconds, not twice the output.
expect(estimateCost(m, { duration: 10, resolution: "480p", clipSeconds: 2 }, 1, "ref2v")).toBeCloseTo(seedanceUsd(864 * 496, 2, 10), 3);
expect(estimateCost(m, { duration: 5, resolution: "1080p" }, 1, "t2v")).toBeCloseTo((1920 * 1080 * 5 * 24) / 1024 / 1000 * 0.0234, 3);
});
});
const json = (body: unknown) => new Request("http://x/api", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) });
const params = (id: string) => ({ params: Promise.resolve({ id }) });
const upload = (name: string, type = "image/png") => saveFile({ data: encodePng({ width: 32, height: 18, data: Buffer.alloc(32 * 18 * 4, 128) }), contentType: type, name, source: "upload" }).url;
describe("Cinema API: a blockout in demo mode", () => {
it("files the film as a take that remembers the blockout's length, parts and beats", async () => {
const p = cinema.createProject({ name: "Blockouts" });
const video = upload("blockout.png");
const still = upload("interior.png");
const input = film("cloud", { video, refs: [{ url: still, role: "interior" }] });
const res = await generateRoute.POST(json({ input }), params(p.id));
expect(res.status).toBe(201);
const out = (await res.json()) as { items: { id: string; feature: string }[]; plan: { modelId: string } };
expect(out.plan.modelId).toBe("seedance-2-5");
expect(out.items).toHaveLength(1);
expect(out.items[0].feature).toBe("cinema-blockout");
const items = cinema.listItems(p.id);
expect(items[0].take).toMatchObject({ action: "blockout", blockout: { seconds: 8, parts: 1, beats: ["Arrival", "The door opens", "Into the dark"] } });
expect(gens.getGeneration(out.items[0].id)!.provider).toBe("mock");
});
it("films an upload at the length its file says, and refuses a WebM blockout on Seedance 2.5", async () => {
const p = cinema.createProject({ name: "Lengths" });
const clip = (ext: "mp4" | "webm", seconds: number) => {
const out = path.join(dir, `clip-${seconds}.${ext}`);
const codec = ext === "mp4" ? ["-pix_fmt", "yuv420p", "-c:v", "libx264"] : ["-c:v", "libvpx", "-b:v", "200k"];
execFileSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", `testsrc=size=320x180:rate=24`, "-t", String(seconds), ...codec, out]);
return saveFile({ data: fs.readFileSync(out), contentType: `video/${ext}`, name: `greybox.${ext}`, source: "upload" }).url;
};
// The browser said 8 s (a clip it couldn't read); the file is 40 s: two shots, and the take says 40.
const long = clip("mp4", 40);
const res = await generateRoute.POST(json({ input: film("cloud", { video: long, seconds: 8, beats: [{ start: 0, label: "All" }], refs: [] }) }), params(p.id));
expect(res.status).toBe(201);
const out = (await res.json()) as { items: { id: string; op: string }[] };
expect(out.items.filter((g) => g.op === "ref2v")).toHaveLength(2);
expect(cinema.listItems(p.id)[0].take?.blockout?.seconds).toBeCloseTo(40, 1);
// Assist reads the same header.
const tools = await import("@/server/assist/tools");
expect(tools.planFor("blockout_film", { video: long, seconds: 8, beats: [{ start: 0, label: "All" }] }, { engine: "cloud" }).jobs.filter((j) => j.op === "ref2v")).toHaveLength(2);
// A WebM file, whatever the browser said, is refused on Seedance 2.5 before anything runs.
const webm = clip("webm", 3);
const refused = await generateRoute.POST(json({ input: film("cloud", { video: webm, seconds: 3, refs: [] }) }), params(p.id));
expect(refused.status).toBe(422);
expect(((await refused.json()) as { error: string }).error).toMatch(/takes MP4 or MOV blockouts, and this one is WebM/);
const h3 = await generateRoute.POST(json({ input: film("cloud", { video: webm, seconds: 3, refs: [] }, { modelId: "minimax-h3-max-3d" }) }), params(p.id));
expect(h3.status).toBe(201);
}, 60_000); // encodes real 8 s and 40 s clips with ffmpeg first
it("refuses a blockout from outside Fuobe's files, and one past 60 s", async () => {
const p = cinema.createProject({ name: "Bad" });
for (const bad of [{ video: "https://evil.test/x.mp4" }, { seconds: 61 }, { refs: [{ url: "/api/files/x.png", role: "villain" }] }]) {
const res = await generateRoute.POST(json({ input: film("cloud", bad as never) }), params(p.id));
expect(res.status, JSON.stringify(bad)).toBe(400);
}
});
});
describe("Canvas, the GPU board, Assist and MCP", () => {
it("Canvas's Blockout → film template: Seedance 2.5 with the blockout as a clip in the cloud, the depth graph on your GPU", async () => {
const { getTemplate, planCanvas, inputPorts } = await import("@/lib/catalog/canvas");
const t = getTemplate("blockout-film")!;
const cloud = t.build("cloud");
const film = cloud.nodes.find((n) => n.id === "film")!;
expect(film.data).toMatchObject({ modelId: "seedance-2-5", op: "ref2v" });
expect(inputPorts(film).map((p) => p.id)).toContain("videos");
expect(String(cloud.nodes.find((n) => n.id === "beats")!.data.text)).toContain("@Video1 is a grey-box 3D blockout");
const open = t.build("open");
expect(open.nodes.find((n) => n.id === "film")!.data).toMatchObject({ modelId: "oss-wan22-vace-blockout", op: "v2v" });
const plan = planCanvas(open, { engineMode: "open" });
expect(plan.costUsd).toBe(0);
for (const e of plan.errors) expect(e.message).toMatch(/^(Add (an image|a video) to|Waiting on)/);
});
it("the GPU board has a Blockout to film row on graphs the requirement index knows", async () => {
const { STUDIO_ROWS, studioTool } = await import("@/server/gpu/tools");
const row = STUDIO_ROWS.find((r) => r.href === "/cinema?blockout=1")!;
expect(row).toMatchObject({ label: "Blockout to film", group: "Video" });
const tool = studioTool(row)!;
// An upload without a depth pass runs the restyle graph (Depth Anything 3), so the row needs it too.
expect(tool.workflows).toEqual(expect.arrayContaining(["video-blockout-wan22-fun-vace", "video-restyle-wan22-fun-vace", "video-segment-resample", "frame-extract", "video-concat-encoded"]));
const req = JSON.parse(fs.readFileSync("workflows/comfyui/requirements.json", "utf8")) as { workflows: Record<string, { packs: Record<string, unknown> }> };
expect(req.workflows["video-blockout-wan22-fun-vace"].packs).toEqual({});
});
it("Assist and MCP's blockout_film plans Cinema's steps and runs them as a pipeline in demo mode", async () => {
const tools = await import("@/server/assist/tools");
const video = upload("blockout.png");
const args = { video, seconds: 8, beats: [{ start: 0, label: "Arrival", words: "She walks in." }, { start: 4.5, label: "The door opens" }] };
const cloud = tools.planFor("blockout_film", args, { engine: "cloud" });
expect(cloud.jobs).toMatchObject([{ tool: "blockout_film", modelId: "seedance-2-5", op: "ref2v" }]);
const open = tools.planFor("blockout_film", args, { engine: "open" });
expect(open.jobs.map((j) => j.modelId)).toEqual(["oss-extract-frame", "oss-qwen-edit", "oss-segment", "oss-wan22-vace-restyle", "oss-extract-frame", "oss-segment", "oss-wan22-vace-restyle", "oss-join-encoded"]);
expect(open.jobs.every((j) => j.costUsd === 0)).toBe(true);
const out = await tools.executeTool("blockout_film", args, { engine: "cloud" });
expect(out.isError).toBeFalsy();
const body = JSON.parse(String(out.content)) as { results: string[] };
expect(gens.getGeneration(body.results[0])!.feature).toBe("cinema-blockout");
const bad = await tools.executeTool("blockout_film", { video: "/api/files/uploads/nowhere.mp4", beats: [] }, { engine: "cloud" });
expect(bad.isError).toBe(true);
expect(String(bad.content)).toMatch(/pass seconds/);
});
});