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
N7-5 fixes: Film shows its price before the path is ready, every path starts at the photo, the take keeps the real length
Claudee20cea63495f
diff --git a/src/lib/camera-path.ts b/src/lib/camera-path.tsindex 8568a236..5d24f9ed 100644--- a/src/lib/camera-path.ts+++ b/src/lib/camera-path.ts@@ -109,14 +109,24 @@ export function presetKeys(id: string): CameraKey[] | null {// ---------------------------------------------------------------------------// Editing a path-/** Keys in time order inside 0–1, starting at the photo's pose (prepended when the first key isn't at 0). */+/** Whether a key is the photo's own camera (where every path starts). */+export function isPhotoPose(k: CameraKey): boolean {+ const near = (a: number, b: number, eps: number) => Math.abs(a - b) < eps;+ return near(k.azimuth, 0, 0.05) && near(k.elevation, 0, 0.05) && near(k.distance, 1, 1e-3) && near(k.truck ?? 0, 0, 1e-3);+}++/**+ * Keys in time order inside 0–1, starting at the photo's pose: the clip's first frame is the photo, so a key at time 0+ * anywhere else (an API or MCP caller's; the editor never makes one) is replaced by the photo's pose, and the photo's+ * pose is put first when the path starts later.+ */export function normalizeKeys(keys: readonly CameraKey[]): CameraKey[] {const list = keys.filter((k) => [k.t, k.azimuth, k.elevation, k.distance].every(Number.isFinite)).map((k) => ({ ...k, t: clamp(k.t, 0, 1), elevation: clamp(k.elevation, -90, 90), distance: clamp(k.distance, DISTANCE.min, DISTANCE.max) })).sort((a, b) => a.t - b.t);- if (!list.length || list[0].t > 0) list.unshift({ ...PHOTO_KEY });- return list;+ const start = list.find((k) => k.t === 0 && isPhotoPose(k));+ return [start ?? { ...PHOTO_KEY }, ...list.filter((k) => k.t > 0)];}/** The same keys, evenly spaced in time (what adding or removing a key leaves). */diff --git a/src/lib/catalog/cinema.ts b/src/lib/catalog/cinema.tsindex b1b35328..12badc29 100644--- a/src/lib/catalog/cinema.ts+++ b/src/lib/catalog/cinema.ts@@ -2013,7 +2013,19 @@ function planPath(input: CinemaGenerateInput): CinemaPlan {request = { feature: "cinema-path", modelId: model.id, op: "camera-path", prompt, inputs: src ? { images: [src] } : undefined, params };}const blocker = !src ? "Pick the scene's still" : !moving ? "Add a keyframe or pick a move first" : open && !path?.render ? PATH_RENDER_FIRST : undefined;- return finish(model, [{ key: "main", request }], notes, blocker);+ const step: CinemaStep = { key: "main", request };+ if (!blocker) return finish(model, [step], notes);+ // Priced before it can run (the price depends on the length and the quality only), so Film shows what it will cost+ // while the path is still being made: priced with stand-ins for the still and the render, then blocked.+ const stand: GenerationRequest = { ...request, inputs: { images: [PLACEHOLDER.image], ...(open ? { video: PLACEHOLDER.video } : {}) } };+ return { ...finish(model, [{ key: "main", request: stand }], notes), steps: [step], blocker };+}++/** What a filmed path's take remembers: the keys it was planned with (from the photo's pose) and the clip's real length. */+export function pathTake(input: Pick<CinemaGenerateInput, "engine" | "path">, plan: CinemaPlan): CinemaTakeInfo["path"] {+ const params = plan.steps[0]?.request.params;+ const duration = input.engine === "open" ? PATH_FRAMES / PATH_FPS : (params?.duration ?? 5);+ return { keys: params?.cameraPath ?? normalizeKeys(input.path?.keys ?? []), duration, ...(input.path?.preset ? { preset: input.path.preset } : {}) };}/** Everything a Generate press would run, priced, without running it (the browser shows it live). */diff --git a/src/lib/catalog/models.ts b/src/lib/catalog/models.tsindex 2f40cae7..8eb5a141 100644--- a/src/lib/catalog/models.ts+++ b/src/lib/catalog/models.ts@@ -1421,7 +1421,13 @@ const open: ModelDef[] = [badges: ["new"],hidden: true,routes: [comfy("camera-path", "wan21-i2v-uni3c-path", "your browser's render of the path guides Wan 2.1 I2V 720P through core Uni3C")],- options: { resolutions: ["480p", "720p"], aspectRatios: ["auto", ...VID_AR], seed: true, maxImages: 1 },+ options: {+ resolutions: ["480p", "720p"],+ aspectRatios: ["auto", ...VID_AR],+ seed: true,+ maxImages: 1,+ requires: { images: 1, video: true, msg: "Add the still and the render of the path (Cinema's 3D scene records it when you film a path)" },+ },defaults: { resolution: "480p", aspectRatio: "auto" },}),o({diff --git a/src/lib/catalog/plan.ts b/src/lib/catalog/plan.tsindex 847451da..6a7ba3b5 100644--- a/src/lib/catalog/plan.ts+++ b/src/lib/catalog/plan.ts@@ -356,6 +356,7 @@ export function planGeneration(if (requires?.images && (req.inputs?.images?.length ?? 0) < requires.images) throw new Error(requires.msg);if (requires?.prompt && !prompt) throw new Error(requires.msg);if (requires?.mask && !req.inputs?.mask) throw new Error(requires.msg);+ if (requires?.video && !req.inputs?.video) throw new Error(requires.msg);if (requires?.points && !params.points?.length) throw new Error(requires.msg);if (op === "bg-remove-video" || op === "depth-video") checkVideoToolOptions(model, op, prompt, params);// Remove background on a model that makes both files: the picker's default (the cut-out) unless asked, so the job@@ -527,6 +528,8 @@ const NEEDS: Partial<"extract-frames": { video: true, msg: "Add the video to take frames from" },"images-to-video": { images: 1, msg: "Add the images, in order" },overlay: { images: 2, msg: "Add the picture and the overlay to put on it" },+ // N7-5 (the open engine also needs the browser's render along the path: its model's options.requires.video)+ "camera-path": { images: 1, msg: "Add the still to film along the path" },};const given = (v: unknown) => (Array.isArray(v) ? v.length > 0 : !!v);diff --git a/src/lib/catalog/types.ts b/src/lib/catalog/types.tsindex c45b91e2..89062397 100644--- a/src/lib/catalog/types.ts+++ b/src/lib/catalog/types.ts@@ -572,9 +572,10 @@ export interface ModelOptions {/*** What this model needs beyond its operation's own inputs, checked before a job is created (the* composer shows `msg` inline): reference images for a style-reference t2i model, a prompt for a- * model whose operation is otherwise promptless, a painted mask or clicked points (video erasers).+ * model whose operation is otherwise promptless, a painted mask or clicked points (video erasers), a video to follow+ * (the open Fly path's render).*/- requires?: { images?: number; prompt?: boolean; mask?: boolean; points?: boolean; msg: string };+ requires?: { images?: number; prompt?: boolean; mask?: boolean; points?: boolean; video?: boolean; msg: string };/** Output formats it can write (params.format: SDR to HDR, export). */formats?: VideoFormat[];/** Depth maps: the colour maps it draws (params.colormap; see COLORMAPS). Unset = grayscale only. */diff --git a/src/server/cinema-generate.ts b/src/server/cinema-generate.tsindex b9a4d8f3..b2a4ee8a 100644--- a/src/server/cinema-generate.ts+++ b/src/server/cinema-generate.ts@@ -3,6 +3,7 @@ import { nanoid } from "nanoid";import { getModel } from "@/lib/catalog";import {SWATCH_PLACEHOLDER,+ pathTake,planCinema,withPlaceholders,type CinemaContext,@@ -140,9 +141,7 @@ export function generateInProject(projectId: string, input: CinemaRequest, folde...(input.moves?.length ? { moves: input.moves } : {}),...(input.action === "grid" && input.grid ? { grid: input.grid } : {}),...(input.action === "recompose" && input.capture ? { camera: { lens: input.capture.lens, aperture: input.capture.aperture, pose: input.capture.pose } } : {}),- ...(input.action === "path" && input.path- ? { path: { keys: input.path.keys, duration: plan.steps[0]?.request.params?.duration ?? 5, ...(input.path.preset ? { preset: input.path.preset } : {}) } }- : {}),+ ...(input.action === "path" && input.path ? { path: pathTake(input, plan) } : {}),};const batchId = nanoid(10);const made: Record<string, Generation[]> = {};diff --git a/tests/camera-path.test.ts b/tests/camera-path.test.tsindex a0464721..2f9e5e2f 100644--- a/tests/camera-path.test.ts+++ b/tests/camera-path.test.ts@@ -10,6 +10,7 @@ import {flyPoseOf,framePoses,fromScenePose,+ isPhotoPose,keyAt,keyLabel,normalizeKeys,@@ -130,6 +131,26 @@ describe("editing a path", () => {expect(k[1]).toMatchObject({ elevation: 90, distance: 4 });});+ it("always starts at the photo's pose: a key at time 0 anywhere else is replaced by it", () => {+ const k = normalizeKeys([+ { t: 0, azimuth: 90, elevation: 10, distance: 2 },+ { t: 1, azimuth: 180, elevation: 0, distance: 1 },+ ]);+ expect(k).toEqual([PHOTO_KEY, { t: 1, azimuth: 180, elevation: 0, distance: 1 }]);+ // Two keys at time 0: the photo's pose stays, the other goes.+ const two = normalizeKeys([{ t: 0, azimuth: 45, elevation: 0, distance: 1 }, PHOTO_KEY, { t: 0.5, azimuth: 90, elevation: 0, distance: 1 }]);+ expect(two.map((x) => [x.t, x.azimuth])).toEqual([+ [0, 0],+ [0.5, 90],+ ]);+ // A slide's start (the photo's pose, no slide yet) is kept as it is; a start already slid is not the photo's pose.+ expect(normalizeKeys(keys("truck_left"))).toEqual(keys("truck_left"));+ expect(isPhotoPose({ t: 0, azimuth: 0, elevation: 0, distance: 1, truck: 0.5 })).toBe(false);+ // H3 Max and the per-frame cameras get the corrected start too.+ const cam = toH3MaxTrajectory([{ t: 0, azimuth: 90, elevation: 0, distance: 1 }, { t: 1, azimuth: 180, elevation: 0, distance: 1 }]);+ expect("trajectory" in cam && cam.trajectory[0]).toMatchObject({ time: 0, azimuth: 0, elevation: 0, distance: 1 });+ });+it("labels a chip with seconds, round, height and distance", () => {expect(keyLabel({ t: 0.24, azimuth: 90, elevation: 10, distance: 1.2 }, 5)).toBe("1.2 s · 90° · +10° · 1.2x");expect(keyLabel({ t: 1, azimuth: -45.4, elevation: -5, distance: 0.6 }, 5)).toBe("5.0 s · -45° · -5° · 0.6x");diff --git a/tests/cinema-path.test.ts b/tests/cinema-path.test.tsindex 734b52f5..fc6befd4 100644--- a/tests/cinema-path.test.ts+++ b/tests/cinema-path.test.ts@@ -18,13 +18,13 @@ 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 { getModel, getPreset } = await import("@/lib/catalog");const { buildPayload } = await import("@/lib/catalog/payload");-const { estimateCost } = await import("@/lib/catalog/plan");+const { estimateCost, planGeneration } = await import("@/lib/catalog/plan");const { getWorkflow, prepareWorkflow } = await import("@/server/providers/comfyui");const { mockProvider } = await import("@/server/providers/mock");-const { planCinema, PATH_MODELS, PATH_RENDER_FIRST } = await import("@/lib/catalog/cinema");-const { DEFAULT_MOTION, PHOTO_KEY, presetKeys } = await import("@/lib/camera-path");+const { pathTake, planCinema, PATH_MODELS, PATH_RENDER_FIRST } = await import("@/lib/catalog/cinema");+const { DEFAULT_MOTION, PATH_FPS, PATH_FRAMES, PHOTO_KEY, presetKeys } = await import("@/lib/camera-path");beforeAll(() => {setSetting("demoMode", "auto");@@ -114,6 +114,46 @@ describe("planning a fly path", () => {expect(planCinema(film("cloud", { path: undefined }), ctx).blocker).toBe("Add a keyframe or pick a move first");expect(planCinema(film("open", { path: { keys: orbit } }), ctx).blocker).toBe(PATH_RENDER_FIRST);});++ it("shows the price that applies before the path is ready: Film never reads 'Free' for a paid run", () => {+ vi.useFakeTimers({ now: Date.parse("2026-10-29T12:00:00Z"), toFake: ["Date"] });+ const start = planCinema(film("cloud", { path: { keys: [PHOTO_KEY], duration: 5 } }), ctx);+ expect(start.blocker).toBe("Add a keyframe or pick a move first");+ expect(start.costUsd).toBe(0.26);+ expect(planCinema(film("cloud", { resolution: "1080P", path: { keys: [PHOTO_KEY], duration: 10 } }), ctx).costUsd).toBe(1.04);+ expect(planCinema(film("cloud", { source: undefined }), ctx)).toMatchObject({ blocker: "Pick the scene's still", costUsd: 0.26 });+ // The blocked step keeps what was really asked (no stand-ins), and the open engine stays free.+ expect(start.steps[0].request.inputs).toEqual({ images: [STILL] });+ expect(planCinema(film("open", { path: { keys: [PHOTO_KEY] } }), ctx)).toMatchObject({ blocker: "Add a keyframe or pick a move first", costUsd: 0 });+ });++ it("starts every path at the photo's pose, even when a caller sends a different first key", () => {+ const sent = [+ { t: 0, azimuth: 90, elevation: 0, distance: 1 },+ { t: 1, azimuth: 180, elevation: 0, distance: 1 },+ ];+ for (const engine of ["cloud", "open"] as const) {+ const plan = planCinema(film(engine, { path: { keys: sent, ...(engine === "open" ? { render: RENDER } : {}) } }), ctx);+ expect(plan.blocker).toBeUndefined();+ expect(plan.steps[0].request.params?.cameraPath).toEqual([PHOTO_KEY, sent[1]]);+ }+ });++ it("remembers the path it planned and the clip's real length: 81 frames at 16 fps on the open engine", () => {+ const open = film("open", { path: { keys: orbit, duration: 8, render: RENDER, preset: "orbit_360" } });+ expect(pathTake(open, planCinema(open, ctx))).toEqual({ keys: orbit, duration: PATH_FRAMES / PATH_FPS, preset: "orbit_360" });+ const cloud = film("cloud", { path: { keys: orbit, duration: 8 } });+ expect(pathTake(cloud, planCinema(cloud, ctx))).toEqual({ keys: orbit, duration: 8 });+ });++ it("a direct run of either helper is refused up front without its still (and, on the GPU, the render)", () => {+ const run = (modelId: string, inputs: Record<string, unknown> | undefined) => () =>+ planGeneration({ feature: "video", modelId, op: "camera-path", prompt: "x", inputs, params: { cameraPath: orbit } }, getModel, getPreset);+ expect(run("minimax-h3-max-camera", undefined)).toThrow("Add the still to film along the path");+ expect(run("minimax-h3-max-camera", { images: [STILL] })).not.toThrow();+ expect(run("oss-uni3c-path", { images: [STILL] })).toThrow(/render of the path/);+ expect(run("oss-uni3c-path", { images: [STILL], video: RENDER })).not.toThrow();+ });});describe("cloud: MiniMax H3 Max camera controls (minimax/h3-max/camera-controls)", () => {@@ -268,6 +308,22 @@ describe("Cinema API: Film this path in demo mode", () => {expect(done).toMatchObject({ status: "succeeded", kind: "video" });}, 40_000);+ it("an API caller's path that starts away from the photo is filmed (and remembered) from the photo's pose", async () => {+ const p = cinema.createProject({ name: "API path" });+ const still = upload("still-api.png");+ const sent = [+ { t: 0, azimuth: 90, elevation: 0, distance: 1 },+ { t: 1, azimuth: 180, elevation: 0, distance: 1 },+ ];+ const res = await generateRoute.POST(json({ input: film("cloud", { source: { url: still, kind: "image" }, path: { keys: sent, duration: 5 } }) }), params(p.id));+ expect(res.status).toBe(201);+ const { items } = await res.json();+ expect(items[0].request.params.cameraPath).toEqual([PHOTO_KEY, sent[1]]);+ const take = cinema.listItems(p.id).find((g) => g.id === items[0].id)!.take!;+ expect(take.path?.keys).toEqual([PHOTO_KEY, sent[1]]);+ await settle(items[0].id);+ }, 40_000);+it("refuses a path out of range, a render not uploaded here, and an open run without its render", async () => {const p = cinema.createProject({ name: "Bad paths" });for (const bad of [