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
Clean dialogue: fal's file-size limits said before upload, the soundtrack extracted lossless
Adarsha44412d6dc44
diff --git a/src/lib/av/clean-dialogue.ts b/src/lib/av/clean-dialogue.tsindex 59a66c4a..17c1c1f2 100644--- a/src/lib/av/clean-dialogue.ts+++ b/src/lib/av/clean-dialogue.ts@@ -61,6 +61,10 @@ export const DEFAULT_CLEANER: Cleaner = "veed";/** VEED Clean Audio takes up to 30 minutes of audio (fal's model page). */export const VEED_MAX_SECONDS = 30 * 60;+/** VEED Clean Audio takes a file of up to 512 MB (fal's veed/clean-audio OpenAPI, audio_url: "Up to 30 minutes and 512 MB"). */+export const VEED_MAX_BYTES = 512 * 1024 * 1024;+/** fal's extract-audio takes a video of up to 100 MB (its OpenAPI, video_url max_file_size 100000000). */+export const EXTRACT_MAX_BYTES = 100_000_000;/** VEED's bill: whole seconds, then up to whole minutes, at least one, at $0.0125 a minute. */export function veedPrice(seconds: number): number {@@ -99,6 +103,8 @@ export interface CleanDialogueInput {remux?: boolean;channels?: number;seconds?: number;+ /** The stored file's size in bytes (fal's cloud steps have size limits). */+ bytes?: number;/** The file has no sound track (from its header). */silent?: boolean;}@@ -113,10 +119,16 @@ export interface CleanDialoguePlan extends ToolPlan {const nameOf = (i: Pick<CleanDialogueInput, "name" | "kind">) => i.name?.trim() || (i.kind === "video" ? "video soundtrack" : "recording");/** What's in the way of a run (in words the page shows), or null. */-export function cleanDialogueProblem(i: Pick<CleanDialogueInput, "engine" | "media" | "kind" | "silent" | "seconds" | "cleaner">): string | null {+export function cleanDialogueProblem(i: Pick<CleanDialogueInput, "engine" | "media" | "kind" | "silent" | "seconds" | "cleaner" | "bytes">): string | null {if (!i.media) return `Add the ${i.kind === "video" ? "video" : "audio"} to clean`;if (i.silent) return i.kind === "video" ? "This video has no sound to clean" : "This file has no sound to clean";if (i.engine === "cloud" && (i.cleaner ?? DEFAULT_CLEANER) === "veed" && i.seconds && i.seconds > VEED_MAX_SECONDS) return "VEED cleans up to 30 minutes — trim it first, or pick another cleaner";+ if (i.engine === "cloud" && i.bytes) {+ const cleaner = cleanerOf(i.cleaner ?? DEFAULT_CLEANER);+ // fal answers file_too_large (422) after the upload: say it before anything is sent.+ if (cleaner.id === "veed" && i.bytes > VEED_MAX_BYTES) return "VEED takes files up to 512 MB — trim or compress it first, or use the open engine";+ if (i.kind === "video" && !cleaner.takesVideo && i.bytes > EXTRACT_MAX_BYTES) return `The cloud takes a video's soundtrack from files up to 100 MB — trim or compress it, or pick ${cleanerOf("veed").label} (up to 512 MB)`;+ }return null;}@@ -185,9 +197,10 @@ export function planCleanDialogue(i: CleanDialogueInput): CleanDialoguePlan {const of = (extract ? 1 : 0) + 1 + (remux ? 1 : 0);let index = 0;if (extract) {+ // Lossless, so the denoiser hears the soundtrack as it is (fal's extract-audio makes a 192k MP3 by default).steps.push({key: "sound",- request: { ...base, modelId: EXTRACT_MODEL, op: "separate-audio", title: `${title} · soundtrack`, inputs: { video: i.media }, params: { ...timed }, step: { label: "The video's soundtrack", index: index++, of } },+ request: { ...base, modelId: EXTRACT_MODEL, op: "separate-audio", title: `${title} · soundtrack`, inputs: { video: i.media }, params: { ...timed, extra: { audio_format: "flac" } }, step: { label: "The video's soundtrack", index: index++, of } },});}const strength = cleaner.id === "veed" && typeof i.strength === "number" && Number.isFinite(i.strength) ? Math.min(1, Math.max(0, i.strength)) : undefined;diff --git a/src/server/audio-tools.ts b/src/server/audio-tools.tsindex 747d9b97..d1e03b5d 100644--- a/src/server/audio-tools.ts+++ b/src/server/audio-tools.ts@@ -1,4 +1,5 @@import "server-only";+import fs from "node:fs";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";@@ -14,7 +15,7 @@ import { ConnectComfyError, previewChained } from "./generations";import { comfyDbsModels, comfyDevice, comfyReuseModels, ownGpu } from "./providers/comfyui";import { engineMode } from "./settings";import { isExampleRef } from "./example-files";-import { storedMedia } from "./storage";+import { absolutePath, filesRel, storedMedia } from "./storage";import { tenant, tenantAccount } from "./tenant";/**@@ -208,6 +209,17 @@ function factsOf(url: string, gone = "That audio file is gone — add it again")return { ...(duration && { duration }), ...(info.channels && { channels: info.channels }), hasAudio: info.hasAudio };}+/** A stored file's size in bytes (after factsOf found it), or undefined (an example input). */+function bytesOf(url: string): number | undefined {+ const rel = isExampleRef(url) ? null : filesRel(url);+ if (rel === null) return undefined;+ try {+ return fs.statSync(/*turbopackIgnore: true*/ absolutePath(rel)).size;+ } catch {+ return undefined;+ }+}+export type AudioToolPlan = ToolPlan & { engine: Engine; split?: ClipFacts; headerChannels?: number };/** Every file a request names (its clip, its clips, the mix and the video it goes on): an account's own, checked first. */@@ -267,7 +279,7 @@ export function planAudioTool(body: AudioToolRequest): AudioToolPlan {const facts = factsOf(body.media);const seconds = facts?.duration ?? body.sourceDuration;const channels = facts?.channels ?? body.channels;- return { engine: body.engine, ...planCleanDialogue({ ...body, seconds, channels, silent: facts?.hasAudio === false }), split: { duration: seconds, channels }, headerChannels: facts?.channels };+ return { engine: body.engine, ...planCleanDialogue({ ...body, seconds, channels, bytes: bytesOf(body.media), silent: facts?.hasAudio === false }), split: { duration: seconds, channels }, headerChannels: facts?.channels };}if (body.tool === "speech-edit") {const facts = factsOf(body.media, body.kind === "video" ? "That video is gone — add it again" : "That recording is gone — add it again");diff --git a/tests/clean-dialogue-size-limits.test.ts b/tests/clean-dialogue-size-limits.test.tsnew file mode 100644index 00000000..06322354--- /dev/null+++ b/tests/clean-dialogue-size-limits.test.ts@@ -0,0 +1,70 @@+import fs from "node:fs";+import { describe, expect, it, vi } from "vitest";+import { tempDir } from "./helpers/temp-dir";++/**+ * fal's file-size limits on Clean dialogue's cloud path, said before anything is uploaded or paid for:+ * - VEED Clean Audio: "Up to 30 minutes and 512 MB" (fal's veed/clean-audio OpenAPI, audio_url). A video goes to VEED as+ * the file itself, so a few minutes of phone 4K were uploaded whole, then refused (file_too_large, 422).+ * - DeepFilterNet 3 on a video: the soundtrack comes from fal's extract-audio first, whose video_url has+ * max_file_size 100000000 (its OpenAPI). A video over 100 MB was uploaded, then refused.+ * fal documents file_too_large as a 422 with ctx.max_size (https://fal.ai/docs/documentation/model-apis/errors).+ * No file is written at that size: the stored file's size is read through fs.statSync, which the last test answers.+ */+const dir = tempDir("fuobe-clean-size-");+process.env.FUOBE_DATA_DIR = dir;+delete process.env.FUOBE_PASSWORD;++const cd = await import("@/lib/av/clean-dialogue");+const { planCleanDialogue, cleanDialogueProblem } = cd;+const { saveFile, absolutePath } = await import("@/server/storage");+const { planAudioTool } = await import("@/server/audio-tools");++const VIDEO = "/api/files/uploads/2026-11-06/vlog.mp4";+const AUDIO = "/api/files/uploads/2026-11-06/take.wav";+const MB = 1024 * 1024;+const ask = cleanDialogueProblem;++describe("fal's file-size limits (Clean dialogue, cloud)", () => {+ it("are fal's documented limits", () => {+ expect(cd.VEED_MAX_BYTES).toBe(512 * MB);+ expect(cd.EXTRACT_MAX_BYTES).toBe(100_000_000);+ });++ it("VEED: a file over 512 MB, audio or video, is refused before anything is sent", () => {+ for (const kind of ["audio", "video"] as const) {+ expect(ask({ engine: "cloud", media: kind === "video" ? VIDEO : AUDIO, kind, cleaner: "veed", bytes: 512 * MB + 1 })).toContain("512 MB");+ expect(ask({ engine: "cloud", media: kind === "video" ? VIDEO : AUDIO, kind, cleaner: "veed", bytes: 512 * MB })).toBeNull();+ }+ });++ it("DeepFilterNet: a video over extract-audio's 100 MB is refused; an audio file of any size is not", () => {+ expect(ask({ engine: "cloud", media: VIDEO, kind: "video", cleaner: "deepfilternet", bytes: 100_000_001 })).toContain("100 MB");+ expect(ask({ engine: "cloud", media: VIDEO, kind: "video", cleaner: "deepfilternet", bytes: 100_000_000 })).toBeNull();+ expect(ask({ engine: "cloud", media: AUDIO, kind: "audio", cleaner: "deepfilternet", bytes: 900 * MB })).toBeNull();+ });++ it("the open engine has no fal limit", () => {+ expect(ask({ engine: "open", media: VIDEO, kind: "video", cleaner: "veed", bytes: 2000 * MB })).toBeNull();+ });++ it("under the limits the plan is unchanged", () => {+ const p = planCleanDialogue({ engine: "cloud", media: VIDEO, kind: "video", cleaner: "deepfilternet", bytes: 50 * MB });+ expect(p.steps.map((s) => s.request.modelId)).toEqual(["extract-soundtrack", "deepfilternet3", "merge-audio-video"]);+ });++ it("the server plans with the stored file's size", () => {+ const asset = saveFile({ data: Buffer.from("not a real mp4"), contentType: "video/mp4", name: "vlog.mp4", source: "upload" });+ const abs = absolutePath(asset.relPath);+ const real = fs.statSync.bind(fs);+ const spy = vi.spyOn(fs, "statSync").mockImplementation(((p: fs.PathLike, o?: fs.StatSyncOptions) => {+ const st = real(p, o as never) as fs.Stats;+ return String(p) === abs ? Object.assign(Object.create(Object.getPrototypeOf(st)), st, { size: 600 * MB }) : st;+ }) as typeof fs.statSync);+ try {+ expect(() => planAudioTool({ tool: "clean-dialogue", engine: "cloud", cleaner: "veed", media: asset.url, kind: "video" } as never)).toThrow(/512 MB/);+ } finally {+ spy.mockRestore();+ }+ });+});