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
Merge main into claude/fuobe-r5-batch-7
Claude1beaabbabab3
diff --cc docs/public-signup.mdindex 1e0421e5,9318756c..1fe07e35--- a/docs/public-signup.md+++ b/docs/public-signup.md@@@ -30,9 -30,9 +30,12 @@@ it (files, uploads, projects, settingsEvery change a guest sends (generate, upload, save a setting, create a project…) answers 401. Thestudio shows a "Create a free account to run this" card with **Sign up** and **Log in**. Pricechecks (the estimate routes, and `?preview=1` on the run routes that support it) stay open, so the- studios can show prices. They don't reveal the owner's library: the turnaround video's price check- (`/api/turnaround/estimate`, or `/api/turnaround?preview=1`) answers 404 "Character not found" for- any character a visitor names, whether it exists or not.+ studios can show prices. A guest may send 120 price checks a minute (per visitor behind a trusted+ reverse proxy; see below), and so may each account. A price check reads only the header of a file-it names, and only of the asker's own files: a guest owns none.++it names, and only of the asker's own files: a guest owns none. Nor does a price check reveal the++owner's library: the turnaround video's price check (`/api/turnaround/estimate`, or++`/api/turnaround?preview=1`) answers 404 "Character not found" for any character a visitor names,++whether it exists or not.## Accountsdiff --cc src/lib/media-probe.tsindex 5307f319,434da39a..613ef902--- a/src/lib/media-probe.ts+++ b/src/lib/media-probe.ts@@@ -70,8 -66,9 +76,9 @@@ export async function probeMediaRanges(try {const head = await read(0, Math.min(size, HEAD_BYTES));if (head.length < 12) return null;- if (!ISO_TOP.includes(fourcc(head, 4))) return size <= head.length ? probeMedia(head) : null;+ if (!ISO_TOP.includes(fourcc(head, 4))) return size <= head.length ? probeMedia(head) : headerSays(head) ? probeMedia(head, size) : null;- for (let o = 0; o + 8 <= size; ) {+ for (let o = 0, n = 0; o + 8 <= size; n++) {+ if (n >= MAX_TOP_BOXES) return null;const h = o + 16 <= head.length ? head.subarray(o, o + 16) : await read(o, Math.min(size, o + 16));if (h.length < 8) return null;const d = new DataView(h.buffer, h.byteOffset, h.byteLength);@@@ -277,10 -247,9 +322,10 @@@ function probeIsoBmff(data: Uint8Array)// ---------------------------------------------------------------------------// WAV, FLAC, MP3- function probeWav(data: Uint8Array, total: number): MediaInfo | null {+ function probeWav(data: Uint8Array, total = data.length): MediaInfo | null {const d = new DataView(data.buffer, data.byteOffset, data.byteLength);let byteRate = 0;+ let channels = 0;for (let o = 12; o + 8 <= data.length; ) {const id = fourcc(data, o);let size = d.getUint32(o + 4, true);diff --cc src/server/audio-tools.tsindex 11810a4a,90449750..791776bd--- a/src/server/audio-tools.ts+++ b/src/server/audio-tools.ts@@@ -1,22 -1,17 +1,20 @@@import "server-only";- import fs from "node:fs/promises";import { z } from "zod";import { planJoin, planLoop, CROSSFADE_MAX, JOIN_MAX_CLIPS, LOOP_MAX_SECONDS, type AudioToolPreview, type ToolPlan } from "@/lib/av/audio-tools";+import { CLOUD_ONLY_PROBLEM, DBS_MODELS, dbsChannelsFor, hostPick, missingDbs, planRemux, planSplit, splitTime } from "@/lib/av/split";import type { Engine, Generation } from "@/lib/catalog/types";import { createPipeline } from "./chains";import { previewChained } from "./generations";- import { fileInfo } from "./media-facts";+import { comfyDbsModels, comfyDevice } from "./providers/comfyui";import { engineMode } from "./settings";- import { absolutePath } from "./storage";+ import { storedMedia } from "./storage";/**- * The Audio hub's Loop / extend and Join tools on the server: each clip's length is read from its own header- * (the browser's figure is the fallback for containers the probe doesn't read), the plan from- * src/lib/av/audio-tools.ts is priced step by step, and a run is one createPipeline batch, so its result- * lands in the Library like any generation.+ * The Audio hub's Loop / extend, Join and Split soundtrack tools on the server: each clip's length is read from its own+ * header (the browser's figure is the fallback for containers the probe doesn't read), the plan from+ * src/lib/av/audio-tools.ts or src/lib/av/split.ts is priced step by step, and a run is one createPipeline batch, so its+ * results land in the Library like any generation. Split soundtrack runs on the open engine only (DBS isn't hosted);+ * its mix goes back on the video with a "remux" run on either engine.*/const FileUrl = z.string().startsWith("/api/files/").max(500);@@@ -68,91 -43,27 +66,68 @@@ export type AudioToolRequest = z.infer<export class AudioToolError extends Error {}+/** What a clip's header says. */+interface ClipFacts {+ duration?: number;+ channels?: number;+ /** False when the header says the file has no sound track (a silent video). */+ hasAudio?: boolean;+}+- declare global {- var __fuobeAudioFacts: Map<string, ClipFacts | null> | undefined;- }/**- * Lengths already read, by file and version (path, size, modified time): the page asks for a price after- * every settled change, and a Join of big WAVs would read every file again each time.+ * A clip's length from its header (WAV, FLAC, MP3, M4A), else the browser's. Only the header is read, once per file+ * (storedMedia caches it: the page asks for a price after every settled change). A visitor's price check reads only its+ * own files: another's answers like one that is gone.*/- const lengths = (globalThis.__fuobeAudioFacts ??= new Map<string, ClipFacts | null>());- const LENGTHS_KEPT = 500;-- /** A clip's length from its header (WAV, FLAC, MP3, M4A), else the browser's. Read without blocking the server. */- async function lengthOf(url: string, given?: number): Promise<number | undefined> {- return (await factsOf(url))?.duration ?? given;+ function lengthOf(url: string, given?: number): number | undefined {+ const found = storedMedia(url);+ if (!found) throw new AudioToolError("That audio file is gone — add it again");+ const d = found.info?.duration;+ return d && d > 0 ? Math.round(d * 1000) / 1000 : given;}- /** Throws `gone` unless the file is still in storage. */- async function present(url: string, gone: string): Promise<void> {- try {- if (!(await fs.stat(absolutePath(decodeURIComponent(url.slice("/api/files/".length))))).isFile()) throw new Error("not a file");- } catch {- throw new AudioToolError(gone);- }-async function plan(body: AudioToolRequest): Promise<ToolPlan & { engine: Engine }> {++/** Throws `gone` unless the file is still in storage (and, in a visitor's price check, the visitor's own). */++function present(url: string, gone: string): void {++ if (!storedMedia(url)) throw new AudioToolError(gone);+}++/**- * A clip's length, channel count and whether it has sound, from its header (cached by file version; read in ranges, so a- * file of any size costs a few small reads), or null when no reader knows the file.++ * A clip's length, channel count and whether it has sound, from its header (read as {@link lengthOf} reads it, through++ * storedMedia: only the asker's own files), or null when no reader knows the file.+ */- async function factsOf(url: string): Promise<ClipFacts | null> {- let file: string;- let key: string;- try {- file = absolutePath(decodeURIComponent(url.slice("/api/files/".length)));- const st = await fs.stat(file);- if (!st.isFile()) throw new Error("not a file");- key = `${file}:${st.size}:${st.mtimeMs}`;- } catch {- throw new AudioToolError("That audio file is gone — add it again");- }- if (!lengths.has(key)) {- let info: Awaited<ReturnType<typeof fileInfo>>;- try {- info = await fileInfo(file);- } catch {- throw new AudioToolError("That audio file is gone — add it again");- }- if (lengths.size >= LENGTHS_KEPT) lengths.delete(lengths.keys().next().value!);- const duration = info?.duration && info.duration > 0 ? Math.round(info.duration * 1000) / 1000 : undefined;- lengths.set(key, info ? { ...(duration && { duration }), ...(info.channels && { channels: info.channels }), hasAudio: info.hasAudio } : null);- }- return lengths.get(key) ?? null;++function factsOf(url: string): ClipFacts | null {++ const found = storedMedia(url);++ if (!found) throw new AudioToolError("That audio file is gone — add it again");++ const info = found.info;++ if (!info) return null;++ const duration = info.duration && info.duration > 0 ? Math.round(info.duration * 1000) / 1000 : undefined;++ return { ...(duration && { duration }), ...(info.channels && { channels: info.channels }), hasAudio: info.hasAudio };+}++async function plan(body: AudioToolRequest): Promise<ToolPlan & { engine: Engine; split?: ClipFacts; headerChannels?: number }> {const mode = engineMode();+ // Split soundtrack runs on the open engine only: an install set to paid APIs only says why, whichever engine was asked for.+ if (body.tool === "split" && mode === "cloud") throw new AudioToolError(CLOUD_ONLY_PROBLEM);if (mode !== "both" && body.engine !== mode) throw new AudioToolError(mode === "open" ? "This install is set to open source only (Settings → Engine mode)" : "This install is set to paid cloud APIs only (Settings → Engine mode)");try {+ if (body.tool === "split") {- const facts = await factsOf(body.media);++ const facts = factsOf(body.media);+ // A clip made without sound (a silent text-to-video take): nothing to split, said before anything is queued.+ if (facts?.hasAudio === false) throw new AudioToolError(body.kind === "video" ? "This video has no sound to split" : "This file has no sound to split");+ const seconds = facts?.duration ?? body.sourceDuration;+ const channels = facts?.channels ?? body.channels;+ return { engine: body.engine, ...planSplit({ ...body, seconds, channels }), split: { duration: seconds, channels }, headerChannels: facts?.channels };+ }+ if (body.tool === "remux") {- await present(body.audio, "That mix is gone — export it again");- await present(body.video, "That video is gone — add it again");++ present(body.audio, "That mix is gone — export it again");++ present(body.video, "That video is gone — add it again");+ return { engine: body.engine, ...planRemux(body) };+ }if (body.tool === "loop") {- const sourceDuration = await lengthOf(body.audio, body.sourceDuration);+ const sourceDuration = lengthOf(body.audio, body.sourceDuration);return { engine: body.engine, ...planLoop({ ...body, sourceDuration: sourceDuration ?? 0 }) };}- const clips = await Promise.all(body.clips.map(async (c) => ({ ...c, duration: await lengthOf(c.url, c.duration) })));+ const clips = body.clips.map((c) => ({ ...c, duration: lengthOf(c.url, c.duration) }));return { engine: body.engine, ...planJoin({ ...body, clips }) };} catch (e) {throw e instanceof AudioToolError ? e : new AudioToolError((e as Error).message);