Skip to content

armgit / fuobe

Public Imported from GitHub
0

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.

Merge remote-tracking branch 'origin/claude/fuobe-parity-4' into o/nm10-kling-4

Claude6266bdf52589
diff --cc src/lib/catalog/clip-windows.ts
index 0c570e4c,99e3cb81..c178bcc5
--- a/src/lib/catalog/clip-windows.ts
+++ b/src/lib/catalog/clip-windows.ts
@@@ -20,68 -18,33 +20,95 @@@ export function sourceSeconds(modelId:
return SOURCE_SECONDS[modelId] ?? {};
}
+/**
+ * The frame a clip edit takes (Kling 4.0's edit, research part 4: 700–4553 px on each side, width ÷ height 0.40–2.50,
+ * 23.9–60.05 fps).
+ */
+const SOURCE_FRAME: Record<string, { min: number; max: number; ratio: [number, number]; fps: [number, number] }> = {
+ "kling-4": { min: 700, max: 4553, ratio: [0.4, 2.5], fps: [23.9, 60.05] },
+};
+
+/** Why a clip `width`×`height` is outside the sides or shape the model takes, in Generate's words, or null. */
+export function clipSizeProblem(model: { id: string; name: string }, width: number, height: number): string | null {
+ const s = SOURCE_FRAME[model.id];
+ if (!s || !(width > 0) || !(height > 0)) return null;
+ if (Math.min(width, height) < s.min) return `${model.name} needs a clip at least ${s.min} px on each side, and this one is ${width}×${height}: upscale it first or pick another model`;
+ if (Math.max(width, height) > s.max) return `${model.name} takes clips up to ${s.max} px on a side, and this one is ${width}×${height}: scale it down first`;
+ const r = width / height;
+ if (r < s.ratio[0] - 0.005 || r > s.ratio[1] + 0.005) {
+ return `${model.name} takes clips from ${s.ratio[0].toFixed(1)}:1 (tall) to ${s.ratio[1].toFixed(1)}:1 (wide), and this one is ${width}×${height}: crop it first`;
+ }
+ return null;
+}
+
+/** Why a clip at `fps` frames a second is outside the frame rates the model takes (Kling 4.0: 24–60 fps), or null. */
+export function clipFpsProblem(model: { id: string; name: string }, fps: number): string | null {
+ const s = SOURCE_FRAME[model.id];
+ if (!s || !(fps > 0) || (fps >= s.fps[0] && fps <= s.fps[1])) return null;
+ const range = `${Math.round(s.fps[0])}–${Math.round(s.fps[1])} fps`;
+ return `${model.name} takes clips at ${range}, and this one is ${Math.round(fps * 100) / 100} fps: save it at ${fps < s.fps[0] ? Math.round(s.fps[0]) : Math.round(s.fps[1])} fps first`;
+}
+
+/** How long a clip given as one of the model's elements may be (Kling 4.0's video elements: 3–8 s). */
+const ELEMENT_CLIP_SECONDS: Record<string, { min: number; max: number }> = { "kling-4": { min: 3, max: 8 } };
+
+/** Why a clip element `seconds` long is outside what the model takes ("Kling 4.0 takes 3–8 s clips as elements…"), or null. */
+export function elementClipProblem(model: { id: string; name: string }, seconds: number, name?: string): string | null {
+ const w = ELEMENT_CLIP_SECONDS[model.id];
+ if (!w || !(seconds > 0) || (seconds >= w.min - 0.05 && seconds <= w.max + 0.05)) return null;
+ return `${model.name} takes ${w.min}–${w.max} s clips as elements, and ${name ? `${name}'s` : "this one"} is ${secs(seconds)}: trim it, or use its photos instead`;
+}
+
+/** The most reference clips an edit takes beside the clip it edits (Kling 4.0's edit: 4 video_urls, @Video2..). */
+const EDIT_REFERENCE_CLIPS: Record<string, number> = { "kling-4": 4 };
+
+/** Why `count` reference clips are more than the model's edit takes, or null. */
+export function editClipsProblem(model: { id: string; name: string }, count: number): string | null {
+ const max = EDIT_REFERENCE_CLIPS[model.id];
+ if (max === undefined || count <= max) return null;
+ return `${model.name}'s edit takes up to ${max} reference clips beside the clip you edit, and this run has ${count}: remove ${count - max}`;
+}
+
+/**
+ * The most seconds of clips a run takes in all, where the model says (Kling 4.0: "the source, reference and element
+ * videos must total at most 30s").
+ */
+const CLIP_TOTAL_SECONDS: Record<string, number> = { "kling-4": 30 };
+
+/** Why clips `seconds` long in all are too long for the model ("Kling 4.0 takes 30 s of clips in all…"), or null. */
+export function clipTotalProblem(model: { id: string; name: string }, seconds: number): string | null {
+ const max = CLIP_TOTAL_SECONDS[model.id];
+ if (max === undefined || seconds <= max + 0.05) return null;
+ return `${model.name} takes ${max} s of clips in all (the clip you edit, reference clips and clip elements together), and these add up to ${secs(seconds)}: trim them first`;
+}
+
+ /**
+ * Cloud clip edits that keep every frame of a clip sent whole (Edit video, an API call): fal's Wan 2.2 Fun VACE depth
+ * route (Fuobe Shorts, Evolution and Genjutsu Restyle in the cloud, match_input_num_frames on) takes 17–241 frames and
+ * bills them ÷ 16 as "video seconds"; a clip whose rate isn't known counts as 30 fps (the fastest it works unhalved).
+ * Their studios cut their own pieces (src/lib/catalog/shorts.ts) and say the seconds they bill. Cloud only: the GPU
+ * graphs load the clip at 16 fps and keep to their own frame caps.
+ */
+ const VACE_FRAMES = { minFrames: 17, maxFrames: 241, billFps: 16, assumeFps: 30 } as const;
+ type FrameWindow = { minFrames: number; maxFrames: number; billFps: number; assumeFps: number; studio: string };
+ const SOURCE_FRAMES: Record<string, FrameWindow> = {
+ "fuobe-shorts": { ...VACE_FRAMES, studio: "Shorts" },
+ "fuobe-evolution": { ...VACE_FRAMES, studio: "Video tools → Evolution" },
+ "fuobe-genjutsu-restyle": { ...VACE_FRAMES, studio: "Genjutsu" },
+ };
+
+ /** The frame window and billing of a cloud clip edit that is billed by its frames, or undefined. */
+ export function sourceFrames(modelId: string, engine?: string): FrameWindow | undefined {
+ return engine === "open" ? undefined : SOURCE_FRAMES[modelId];
+ }
+
+ /** The seconds a clip `seconds` long is billed for: its frames ÷ 16 on a frame-billed route, else its seconds. */
+ export function billedClipSeconds(modelId: string, seconds: number, fps?: number, engine?: string): number {
+ const f = sourceFrames(modelId, engine);
+ if (!f) return seconds;
+ return Math.round(((seconds * (fps && fps > 0 ? fps : f.assumeFps)) / f.billFps) * 1e6) / 1e6;
+ }
+
const secs = (n: number) => `${Math.round(n * 10) / 10} s`;
/**
diff --cc src/lib/catalog/plan.ts
index fdc13385,f875772b..45a07f7f
--- a/src/lib/catalog/plan.ts
+++ b/src/lib/catalog/plan.ts
@@@ -10,7 -10,7 +10,7 @@@ import type
Preset,
PresetRoute,
} from "./types";
- import { editClipsProblem, sourceSeconds } from "./clip-windows";
-import { billedClipSeconds, sourceSeconds } from "./clip-windows";
++import { billedClipSeconds, editClipsProblem, sourceSeconds } from "./clip-windows";
import { chainGapProblem, chainTiming, FIRST_AT_ZERO, frameTimes, keyframeChain, MAX_KEYFRAMES, spread } from "./keyframes";
import { cloudPath, fitLoras, gated, localOnly, loraCapacity, needsToken, routeLoraField, triggerOf } from "./loras";
import { anglesPrompt, anglesWords, ANGLES_ORIGINAL } from "./open-tools";
@@@ -860,46 -806,10 +861,47 @@@ export function clipEditSeconds(model:
const routes = model.routes.filter((r) => r.op === "v2v");
if (!routes.length || routes.some((r) => r.map?.duration)) return undefined;
const max = sourceSeconds(model.id).max;
- return max !== undefined ? Math.min(seconds, max) : seconds;
+ // fal's Wan 2.2 Fun VACE bills a clip's frames ÷ 16 (a 30 fps clip about 1.9× its length): clip-windows.ts.
+ return billedClipSeconds(model.id, max !== undefined ? Math.min(seconds, max) : seconds, params.sourceFps, model.engine);
}
+/** The edits of a clip that keep its length: the clip goes in whole, and the result is as long (Kling 4.0's edit). */
+const CLIP_EDIT_OPS = new Set<Operation>(["v2v", "video-swap", "video-insert", "remove-object"]);
+
+export interface ClipBilling {
+ /** Seconds of clips going in: the edited clip's and the reference clips'. */
+ input: number;
+ output: number;
+ /** What's billed: input plus output, at least twice the output. */
+ billed: number;
+ /** Per billed second. */
+ rate: number;
+ /** The input's length isn't known yet (no clip header read): priced at the least it bills, twice the output. */
+ guessed: boolean;
+}
+
+/**
+ * How a run with a clip going in is billed, on a model that bills those runs on input plus output (Pricing.clipInput,
+ * Kling 4.0): an edit of a clip (its length, params.sourceDuration, in and out: the edit keeps it), or a run with
+ * reference clips or video elements (params.clipSeconds: their seconds; 0 while they aren't read yet). Undefined for
+ * a run with no clip, or a model that bills them as any other.
+ */
+export function clipBilling(model: Pick<ModelDef, "pricing" | "defaults">, params: GenParams, op?: Operation, now?: PriceClock): ClipBilling | undefined {
+ const p = model.pricing && pricingOn(model.pricing, now);
+ const c = p?.clipInput;
+ if (!c || p.unit !== "second") return undefined;
+ const edit = !!op && CLIP_EDIT_OPS.has(op);
+ if (!edit && params.clipSeconds === undefined) return undefined;
+ const res = params.resolution ?? model.defaults?.resolution;
+ const rate = (res && (c.byResolution?.[res] ?? c.byResolution?.[res.toLowerCase()])) || c.usd;
+ const source = params.sourceDuration && params.sourceDuration > 0 ? params.sourceDuration : undefined;
+ const output = edit ? (source ?? params.duration ?? model.defaults?.duration ?? 5) : (params.duration ?? model.defaults?.duration ?? 5);
+ const refs = Math.max(0, params.clipSeconds ?? 0);
+ const guessed = edit ? !source : !refs;
+ const input = (edit ? (source ?? output) : 0) + refs;
+ return { input, output, billed: Math.max(input + output, 2 * output), rate, guessed };
+}
+
/**
* The seconds a talking avatar is made (and billed) for a voice `seconds` long: as long as the voice, or what a
* frame-count route's limits make of it, in the seconds it bills (fal's InfiniteTalk: 41–721 frames, 25 a second; Wan 2.2
diff --cc src/lib/composer.ts
index bf259c5b,b8deed2b..d5036d69
--- a/src/lib/composer.ts
+++ b/src/lib/composer.ts
@@@ -299,14 -290,7 +299,14 @@@ export function clipBlocker
model: (Pick<ModelDef, "engine" | "options" | "defaults"> & Partial<Pick<ModelDef, "id" | "name">>) | undefined,
ramBytes: number | undefined,
): string | null {
- if (op === "v2v" && model?.id && facts?.duration) return clipWindowProblem({ id: model.id, name: model.name ?? model.id, engine: model.engine }, facts.duration, facts.fps);
+ if (op === "v2v" && model?.id && (facts?.duration || facts?.width)) {
- const named = { id: model.id, name: model.name ?? model.id };
++ const named = { id: model.id, name: model.name ?? model.id, engine: model.engine };
+ return (
- (facts.duration ? clipWindowProblem(named, facts.duration) : null) ??
++ (facts.duration ? clipWindowProblem(named, facts.duration, facts.fps) : null) ??
+ (facts.width && facts.height ? clipSizeProblem(named, facts.width, facts.height) : null) ??
+ (facts.fps ? clipFpsProblem(named, facts.fps) : null)
+ );
+ }
if (!facts?.width || !facts.height || !model) return null;
if (op === "upscale-video") {
const tier = upscaleTier(params.resolution ?? model.defaults?.resolution, model.options.resolutions, { width: facts.width, height: facts.height }, params.resolution !== undefined);
diff --cc src/server/generations.ts
index 9fdaeed2,64f634bb..62b56853
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@@ -12,7 -12,7 +12,7 @@@ import { cueText, type Cue } from "@/li
import { HELPER_FEATURES, HELPER_SUFFIX, isReviewStatus, type AssetUse, type ReviewFilter } from "@/lib/library";
import { upscaleTier } from "@/lib/av/upscale";
import { chainedWaitMessage, framesWait, keyframeChain } from "@/lib/catalog/keyframes";
- import { clipFpsProblem, clipSizeProblem, clipTotalProblem, clipWindowProblem, elementClipProblem } from "@/lib/catalog/clip-windows";
-import { clipWindowProblem, sourceFrames } from "@/lib/catalog/clip-windows";
++import { clipFpsProblem, clipSizeProblem, clipTotalProblem, clipWindowProblem, elementClipProblem, sourceFrames } from "@/lib/catalog/clip-windows";
import { avatarSeconds, clipEditSeconds, estimateCost, inferOperation, movedAppRequest, planGeneration, presetRoute, routeLoras, routesFor, withoutTriggers } from "@/lib/catalog/plan";
import { framedLength, keepMatte } from "@/lib/catalog/payload";
import { fitLoras, loraName, lorasFit } from "@/lib/catalog/loras";
@@@ -1587,43 -1574,16 +1587,46 @@@ async function submitNow
}
// A clip edit of a clip sent as it is (Edit video, an API call; the studios that cut clips keep to the windows
// themselves): one outside the model's window is refused before it's paid for (Happy Horse bills 60 s and returns
- // 15), and one that keeps the clip's length is priced for it once the header is read (a call that didn't say).
+ // 15; fal's Wan 2.2 Fun VACE takes at most 241 frames), and one that keeps the clip's length is priced for it once
+ // the header is read (a call that didn't say). A route billed by frames is priced on the header's rate as well.
if (plan.op === "v2v" && input.sourceDuration && !req.chain?.length && req.params?.duration === undefined && providerId !== "mock" && plan.model.engine !== "open") {
- const problem = clipWindowProblem(plan.model, input.sourceDuration) ?? (input.sourceSize ? clipSizeProblem(plan.model, input.sourceSize.width, input.sourceSize.height) : null);
- const problem = clipWindowProblem(plan.model, input.sourceDuration, input.sourceFps);
++ const problem = clipWindowProblem(plan.model, input.sourceDuration, input.sourceFps) ?? (input.sourceSize ? clipSizeProblem(plan.model, input.sourceSize.width, input.sourceSize.height) : null);
if (problem) throw new Error(problem);
- if (plan.params.sourceDuration === undefined && clipEditSeconds(plan.model, input, plan.op) !== undefined) {
- update(id, { cost_usd: estimateCost(plan.model, { ...plan.params, sourceDuration: input.sourceDuration }, 1, plan.op, plan.loras.length > 0 && !!route.loraEndpoint) });
+ const byFrames = !!sourceFrames(plan.model.id, plan.model.engine) && source.sourceFps !== undefined && source.sourceFps !== plan.params.sourceFps;
+ if ((plan.params.sourceDuration === undefined || byFrames) && clipEditSeconds(plan.model, input, plan.op) !== undefined) {
+ update(id, { cost_usd: estimateCost(plan.model, { ...plan.params, sourceDuration: input.sourceDuration, sourceFps: input.sourceFps }, 1, plan.op, plan.loras.length > 0 && !!route.loraEndpoint) });
}
}
+ const edits = plan.op === "v2v" || plan.op === "video-swap" || plan.op === "video-insert";
+ // An edit whose route sends no length keeps the clip's own (Kling 4.0's edit, swap and insert), whatever the request
- // said: the clip is held to the model's window, sides, shape and frame rate before it's paid for.
- if (edits && !route.map?.duration && !req.chain?.length && providerId !== "mock" && plan.model.engine !== "open") {
++ // said: the clip is held to the model's window, sides, shape and frame rate before it's paid for. Frame-billed routes
++ // (fal's Wan 2.2 Fun VACE) keep the rule above: their studios cut the pieces and say the length.
++ if (edits && !route.map?.duration && !req.chain?.length && providerId !== "mock" && plan.model.engine !== "open" && !sourceFrames(plan.model.id, plan.model.engine)) {
+ const problem =
- (input.sourceDuration ? clipWindowProblem(plan.model, input.sourceDuration) : null) ??
++ (input.sourceDuration ? clipWindowProblem(plan.model, input.sourceDuration, input.sourceFps) : null) ??
+ (input.sourceSize ? clipSizeProblem(plan.model, input.sourceSize.width, input.sourceSize.height) : null) ??
+ (input.sourceFps ? clipFpsProblem(plan.model, input.sourceFps) : null);
+ if (problem) throw new Error(problem);
+ }
+ // Reference clips (and clip elements) billed with the output: refused past the most the model takes in all (with the
+ // clip edited), or a clip element outside its own window, before it's paid for, and priced on their seconds once read
+ // (the plan priced the least they bill). An edit of a clip whose length the caller didn't say is priced on it (in and
+ // out) once its header is read.
+ const read = clipLengths.filter((n): n is number => n !== undefined);
+ const unpricedEdit = edits && !!input.sourceDuration && plan.params.sourceDuration === undefined;
+ if (billsClips && (read.length || unpricedEdit) && providerId !== "mock" && plan.model.engine !== "open") {
+ for (const g of plan.params.elements ?? []) {
+ const seconds = g.video !== undefined ? clipLengths[g.video] : undefined;
+ const problem = seconds !== undefined ? elementClipProblem(plan.model, seconds) : null;
+ if (problem) throw new Error(problem);
+ }
+ const seconds = read.reduce((a, b) => a + b, 0);
+ const problem = clipTotalProblem(plan.model, (edits ? (input.sourceDuration ?? 0) : 0) + seconds);
+ if (problem) throw new Error(problem);
+ if (read.length) input.clipSeconds = seconds;
+ const priced = { ...plan.params, ...(input.sourceDuration !== undefined && { sourceDuration: input.sourceDuration }), ...(read.length && { clipSeconds: seconds }) };
+ update(id, { cost_usd: estimateCost(plan.model, priced, 1, plan.op) });
+ }
// An upscale that wouldn't enlarge the clip (a 1080p clip at a default 1080p; a 4K clip would even shrink):
// a tier the model only defaulted to moves up to the next one it offers, one the caller picked is refused.
if (plan.op === "upscale-video" && input.sourceSize) {