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.

Genjutsu: a run's facts state its part length and the canvas it makes

Adarsh8bf0b2f9d5a5
diff --git a/src/lib/openjutsu-graphs.ts b/src/lib/openjutsu-graphs.ts
index 2030c98a..92f36f38 100644
--- a/src/lib/openjutsu-graphs.ts
+++ b/src/lib/openjutsu-graphs.ts
@@ -461,9 +461,14 @@ export interface PictureVideoSettings {
/** The two renderers' fixed steps: Solar's four-step LoRA, H3's DMAD at six. */
export const PICTURE_STEPS = { solar: 4, h3: 6 } as const;
+/** The canvas a picture brought to life on a clip makes: the clip's shape at the quality's short edge, at most 2048 px. */
+export function pictureCanvas(width: number, height: number, quality: string): [number, number] {
+ return clampCanvas(canvasSize(width, height, quality === "720p" ? "736p" : "480p"));
+}
+
export function pictureVideo(source: ComfyWorkflow, s: PictureVideoSettings): ComfyWorkflow {
const graph = clone(source);
- const [width, height] = clampCanvas(canvasSize(s.width, s.height, s.quality === "720p" ? "736p" : "480p"));
+ const [width, height] = pictureCanvas(s.width, s.height, s.quality);
const length = pictureFrames(s.seconds);
if (s.renderer === "solar" && length < 22) throw new Error("Pick a part of at least one second.");
graph["1"].inputs.frame_load_cap = length;
diff --git a/src/server/hosted.ts b/src/server/hosted.ts
index 392f00fa..e30ad676 100644
--- a/src/server/hosted.ts
+++ b/src/server/hosted.ts
@@ -3,6 +3,7 @@ import { getModel } from "@/lib/catalog";
import { computeDimensions, fitCanvas } from "@/lib/comfy";
import { requestWorkflowId } from "@/lib/comfy-variants";
import { h3Canvas, isH3Graph } from "@/lib/h3-prompt";
+import { pictureCanvas } from "@/lib/openjutsu-graphs";
import { imageSize } from "@/lib/image-size";
import type { GenerationRequest } from "@/lib/catalog/types";
import type { Place } from "@/lib/place-name";
@@ -586,6 +587,21 @@ export function requestMegapixels(req: GenerationRequest, kind: RunFacts["kind"]
return megapixelsOf(w && h ? { width: w, height: h } : byAsk());
}
+/**
+ * A Genjutsu run's own size, which its request keeps in params.extra.openjutsu: the part's length in seconds, and for a
+ * picture brought to life on a clip (op motion-transfer), the megapixels of the canvas it makes from the clip's size
+ * (params.sourceSize) at its quality. Null where the request names neither (not a Genjutsu run).
+ */
+export function genjutsuSize(req: GenerationRequest): { seconds: number | null; megapixels: number | null } | null {
+ const raw = (req.params?.extra as Record<string, unknown> | undefined)?.openjutsu;
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
+ const o = raw as Record<string, unknown>;
+ const src = (req.params as { sourceSize?: { width?: unknown; height?: unknown } } | undefined)?.sourceSize;
+ const [w, h] = [positive(src?.width), positive(src?.height)];
+ const canvas = req.op === "motion-transfer" && w && h && typeof o.quality === "string" ? pictureCanvas(w, h, o.quality) : null;
+ return { seconds: positive(o.seconds), megapixels: canvas ? megapixelsOf({ width: canvas[0], height: canvas[1] }) : null };
+}
+
/**
* A run's own step, then the other steps it makes beside it (a 2K take's finish), each model and operation once with its
* count: the shape of RunFacts.steps.
@@ -625,6 +641,8 @@ export function runFacts(
// The graph an open-engine run resolves to, its options' variant picked as the pre-flight and the provider pick it.
const graphs = p.model.engine === "open" && p.providerId === "comfyui" && endpoint ? loadIndex().workflows : null;
const workflow = graphs && endpoint ? requestWorkflowId(endpoint, req, { op: p.op, gpu: p.gpu ?? undefined, h3: p.h3 ?? undefined, has: (id) => !!graphs[id] }).id : null;
+ // A Genjutsu run states its own length and canvas (genjutsuSize); every other run, as its request and workflow say.
+ const genjutsu = genjutsuSize(req);
return {
place: "pool",
model: p.model.id,
@@ -637,8 +655,8 @@ export function runFacts(
provider: p.providerId,
jobs: p.jobs,
outputsPerJob: p.jobs > 0 ? Math.max(1, Math.round(p.outputs / p.jobs)) : 1,
- megapixels: requestMegapixels(req, kind, p.model.id, p.providerId === "comfyui" ? endpoint : undefined),
- seconds: req.params?.duration ?? (kind === "video" ? (model?.defaults?.duration ?? null) : null),
+ megapixels: genjutsu?.megapixels ?? requestMegapixels(req, kind, p.model.id, p.providerId === "comfyui" ? endpoint : undefined),
+ seconds: genjutsu?.seconds ?? req.params?.duration ?? (kind === "video" ? (model?.defaults?.duration ?? null) : null),
fps: req.params?.fps ?? null,
loras: p.loras.applied.length,
inputs: inputCounts(req),
diff --git a/tests/genjutsu-run-facts.test.ts b/tests/genjutsu-run-facts.test.ts
new file mode 100644
index 00000000..d6ca11f4
--- /dev/null
+++ b/tests/genjutsu-run-facts.test.ts
@@ -0,0 +1,41 @@
+import { describe, expect, it } from "vitest";
+import type { GenerationRequest } from "@/lib/catalog/types";
+import { pictureCanvas } from "@/lib/openjutsu-graphs";
+import { tempDir } from "./helpers/temp-dir";
+
+// A Genjutsu run keeps its own length and quality in params.extra.openjutsu: the facts the billing hook gets for it say
+// that length, and for a picture brought to life on a clip, the canvas that run makes (not the picture's own size).
+process.env.FUOBE_DATA_DIR = tempDir("fuobe-genjutsu-facts-");
+const { genjutsuSize, runFacts } = await import("@/server/hosted");
+
+const motion = (quality: string, seconds: number, extra: Record<string, unknown> = {}): GenerationRequest =>
+ ({
+ feature: "genjutsu",
+ modelId: "oss-h3-motion",
+ op: "motion-transfer",
+ params: { resolution: quality, sourceSize: { width: 1308, height: 736 }, extra: { openjutsu: { seconds, quality, motion: 0, scene: "" }, ...extra } },
+ inputs: { images: ["file:picture"], video: "file:clip" },
+ }) as unknown as GenerationRequest;
+
+describe("genjutsuSize", () => {
+ it("a picture on a clip: the part's seconds and the canvas it makes at its quality", () => {
+ expect(pictureCanvas(1308, 736, "720p")).toEqual([1312, 736]);
+ expect(pictureCanvas(1308, 736, "480p")).toEqual([864, 480]);
+ expect(genjutsuSize(motion("720p", 12.3))).toEqual({ seconds: 12.3, megapixels: 0.97 });
+ expect(genjutsuSize(motion("480p", 5))).toEqual({ seconds: 5, megapixels: 0.41 });
+ });
+
+ it("another Genjutsu run: its seconds only; no clip size: its seconds only; not Genjutsu: null", () => {
+ const swap = { ...motion("720p", 8), op: "character-swap" } as unknown as GenerationRequest;
+ expect(genjutsuSize(swap)).toEqual({ seconds: 8, megapixels: null });
+ const noSize = motion("720p", 6);
+ delete (noSize.params as { sourceSize?: unknown }).sourceSize;
+ expect(genjutsuSize(noSize)).toEqual({ seconds: 6, megapixels: null });
+ expect(genjutsuSize({ feature: "video", modelId: "x", params: { duration: 5 } } as unknown as GenerationRequest)).toBeNull();
+ });
+
+ it("the billing facts of a picture on a clip carry them", () => {
+ const f = runFacts(motion("720p", 12.3), { model: { id: "oss-h3-motion", kind: "video", engine: "open" }, op: "motion-transfer", jobs: 1, outputs: 1, providerId: "comfyui", costUsd: 0, loras: { applied: [] } }, "video");
+ expect(f).toMatchObject({ seconds: 12.3, megapixels: 0.97, op: "motion-transfer", studio: "genjutsu" });
+ });
+});