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.

Restore 9: Upscale → Restore archive footage first runs restore, then upscale

Claudeb148c9a7d660
diff --git a/src/components/restore/hooks.ts b/src/components/restore/hooks.ts
index bed04444..701526d8 100644
--- a/src/components/restore/hooks.ts
+++ b/src/components/restore/hooks.ts
@@ -16,6 +16,8 @@ export interface RestoreBody {
hint?: string;
refine?: boolean;
deinterlace?: boolean;
+ /** Upscale after (Upscale → Restore archive footage first). */
+ upscale?: boolean;
reference?: string;
resolution?: string;
/** Client nonce: a repeat of it gets the first answer (see useSubmitGuard). */
diff --git a/src/components/restore/restore-tool.tsx b/src/components/restore/restore-tool.tsx
index 3b632f32..ad5dc688 100644
--- a/src/components/restore/restore-tool.tsx
+++ b/src/components/restore/restore-tool.tsx
@@ -18,7 +18,8 @@ import { Feed } from "@/components/studio/feed";
import { MediaSlot, type SlotValue } from "@/components/studio/media-slot";
import { SelfHostNote } from "@/components/self-host-note";
import { useEngine, useGenerations, useLikelyVisitor } from "@/lib/api";
-import { CLOUD_NOTE, GPU_NOTE, RESTORE, restoreNegative } from "@/lib/catalog/restore";
+import { CLOUD_NOTE, GPU_NOTE, RESTORE, RESTORE_UPSCALE, restoreNegative } from "@/lib/catalog/restore";
+import { THEN_UPSCALE } from "@/lib/catalog/upscale-first";
import { chainState } from "@/lib/catalog/shorts";
import { downloadHref, downloadName } from "@/lib/library";
import { cn } from "@/lib/utils";
@@ -54,6 +55,8 @@ export function RestoreTool({ tabs }: { tabs?: React.ReactNode }) {
const [by, setBy] = useState<string | null>(null);
const [refine, setRefine] = useState(false);
const [deinterlace, setDeinterlace] = useState(false);
+ // Upscale → "Restore archive footage first" arrives with ?then=upscale: the upscale runs after, as one job.
+ const [upscale, setUpscale] = useState(false);
const [reference, setReference] = useState<SlotValue | null>(null);
const [resolution, setResolution] = useState<string>(RESTORE.cloudResolution);
const [run, setRun] = useState<Run | null>(null);
@@ -64,8 +67,10 @@ export function RestoreTool({ tabs }: { tabs?: React.ReactNode }) {
// Hand-off: /video-tools/restore?video=/api/files/… (a result, a Library clip, Upscale's link).
useEffect(() => {
- const video = new URLSearchParams(window.location.search).get("video");
+ const q = new URLSearchParams(window.location.search);
+ const video = q.get("video");
if (video?.startsWith("/api/files/")) source.adopt(video, video.split("/").pop());
+ if (q.get("then") === THEN_UPSCALE) setUpscale(true);
// Once, on arrival.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
@@ -82,6 +87,7 @@ export function RestoreTool({ tabs }: { tabs?: React.ReactNode }) {
...(negative.trim() && negative.trim() !== DEFAULT_NEGATIVE ? { negative: negative.trim() } : {}),
...(open && refine ? { refine: true } : {}),
...(open && deinterlace ? { deinterlace: true } : {}),
+ ...(upscale && !(open && refine) ? { upscale: true } : {}),
...(reference?.ref && !reference.uploading ? { reference: reference.ref } : {}),
...(!open ? { resolution } : {}),
}
@@ -258,6 +264,14 @@ export function RestoreTool({ tabs }: { tabs?: React.ReactNode }) {
disabled={!open}
onChange={setRefine}
/>
+ <Toggle
+ id="restore-upscale"
+ label="Then upscale"
+ hint={`${open ? RESTORE_UPSCALE.open.label : RESTORE_UPSCALE.cloud.label}, after the restoration, in the same run${open ? " (free)" : " (priced in)"}${open && refine ? ". Restore to 4K already doubles the size" : ""}`}
+ checked={upscale && !(open && refine)}
+ disabled={open && refine}
+ onChange={setUpscale}
+ />
<Toggle
id="restore-interlaced"
label="Interlaced source (TV, tape)"
diff --git a/src/components/studio/studio-context.tsx b/src/components/studio/studio-context.tsx
index 462a086f..6e943baa 100644
--- a/src/components/studio/studio-context.tsx
+++ b/src/components/studio/studio-context.tsx
@@ -6,6 +6,7 @@ import type { FeedFilter } from "@/lib/api";
import type { Signature } from "@/lib/catalog/palettes";
import type { FrameAttachment } from "@/lib/composer";
import type { LayoutDraft } from "@/lib/layout-prompt";
+import type { UpscaleFirstStep } from "@/lib/catalog/upscale-first";
import type { SlotValue } from "./media-slot";
export type SlotKey = InputSlot["key"];
@@ -19,6 +20,8 @@ export interface StudioConfig {
subtitle?: string;
/** A studio that does the job in more depth, linked under the hero (Edit video → Genjutsu). */
related?: { href: string; label: string };
+ /** Steps a tool runs before this one, then this one after it, as one job (Upscale → Restore archive footage first). */
+ firstSteps?: UpscaleFirstStep[];
placeholder: string;
kind: MediaKind;
/** Operations whose models appear in the picker. */
diff --git a/src/components/studio/studio-page.tsx b/src/components/studio/studio-page.tsx
index f42f90c5..2168bf70 100644
--- a/src/components/studio/studio-page.tsx
+++ b/src/components/studio/studio-page.tsx
@@ -449,6 +449,25 @@ function StudioBody({ header, tabs, examples }: { header?: React.ReactNode; tabs
<ArrowRight className="size-3" />
</Link>
)}
+ {config.firstSteps?.length ? (
+ <ul aria-label="Before upscaling" className="mt-3 flex max-w-xl flex-col items-center gap-2">
+ {config.firstSteps.map((f) => (
+ <li key={f.id} className="flex flex-col items-center gap-1">
+ <Link
+ href={f.href}
+ aria-describedby={`first-step-${f.id}`}
+ className="inline-flex items-center gap-1 rounded-full bg-muted px-3 py-1 text-[12px] font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none"
+ >
+ {f.label}
+ <ArrowRight className="size-3" />
+ </Link>
+ <span id={`first-step-${f.id}`} className="text-[12px] text-pretty text-muted-foreground">
+ {f.hint}
+ </span>
+ </li>
+ ))}
+ </ul>
+ ) : null}
</div>
)}
</div>
diff --git a/src/lib/catalog/restore.ts b/src/lib/catalog/restore.ts
index ce08425c..76811238 100644
--- a/src/lib/catalog/restore.ts
+++ b/src/lib/catalog/restore.ts
@@ -274,12 +274,13 @@ export function sourceFrames(s: Pick<RestoreSource, "frames" | "duration" | "fps
}
/** Why this run can't start, or null. */
-export function restoreProblem(o: { engine: Engine; source: Pick<RestoreSource, "duration" | "fps" | "frames">; refine?: boolean; resolution?: string }): string | null {
+export function restoreProblem(o: { engine: Engine; source: Pick<RestoreSource, "duration" | "fps" | "frames">; refine?: boolean; resolution?: string; upscale?: boolean }): string | null {
const d = o.source.duration;
if (d === undefined || !o.source.fps) return "Reading the clip… try again in a moment";
if (d > RESTORE.maxSeconds + 0.05) return `Restore takes up to ${RESTORE.maxSeconds / 60} minutes at a time: trim the clip first (Video tools → Trim)`;
if ((sourceFrames(o.source) ?? 0) < RESTORE.minFrames) return "The clip is too short to restore: it needs at least 9 frames";
if (o.refine && o.engine === "cloud") return "Restore to 4K runs on your GPU: the Detail Refine IC-LoRA is an LTX-2.5 LoRA, and no cloud host runs LTX-2.5 with LoRAs";
+ if (o.refine && o.upscale) return "Restore to 4K already doubles the size: pick it or Then upscale, not both";
if (o.engine === "cloud" && o.resolution && !(RESTORE.cloudResolutions as readonly string[]).includes(o.resolution)) return `Pick ${RESTORE.cloudResolutions.join(" or ")}`;
return null;
}
@@ -302,8 +303,20 @@ export interface RestorePlanInput {
/** Cloud tier (720p or 1080p). */
resolution?: string;
seed?: number;
+ /** Upscale the restored clip after (Upscale → "Restore archive footage first"): the engine's video upscaler. */
+ upscale?: boolean;
}
+/**
+ * The upscaler a restoration hands its result to (Upscale video's defaults): Topaz Video in the cloud, SeedVR2 on
+ * your GPU, both to 2160p (the factor comes from the restored clip at submit). Restore to 4K already doubles the size
+ * on the GPU, so the two don't go together.
+ */
+export const RESTORE_UPSCALE = {
+ cloud: { modelId: "topaz-video", params: { resolution: "2160p" }, label: "Topaz Video, to 2160p" },
+ open: { modelId: "oss-seedvr2", params: { resolution: "2160p" }, label: "SeedVR2, to 2160p" },
+} as const;
+
export interface RestorePlan {
steps: PlanStep[];
final: string;
@@ -431,7 +444,7 @@ export function planRestore(input: RestorePlanInput): RestorePlan {
});
picture = joinEncoded(steps, rkeys, "join4k", sound ? helper : { ...base, title: input.title }, "Join the 4K windows");
}
- const final = sound ? putSoundBack(steps, picture, base, input.title, source, "open") : picture;
+ const final = thenUpscale(steps, sound ? putSoundBack(steps, picture, base, input.title, source, "open") : picture, input);
const covered = refine ? frameWindows(framesCovered(windows), REFINE_WINDOW).reduce((a, b) => a + b, 0) : framesCovered(windows);
return { steps, final, pieces: n, canvas, refined, dropped: total - covered, sound };
}
@@ -486,11 +499,40 @@ export function planRestore(input: RestorePlanInput): RestorePlan {
let picture = keys[0];
if (n > 1) picture = foldJoin(steps, keys, sound ? helper : { ...base, title: input.title });
const end = pieces[n - 1].end;
- const final = sound ? putSoundBack(steps, picture, base, input.title, source, "cloud", end) : picture;
+ const final = thenUpscale(steps, sound ? putSoundBack(steps, picture, base, input.title, source, "cloud", end) : picture, input);
const covered = pieces.reduce((a, p) => a + (p.frames ?? 0), 0);
return { steps, final, pieces: n, canvas: { width: cw, height: ch }, dropped: Math.max(0, total - covered), sound };
}
+/**
+ * Upscale → "Restore archive footage first": the restored clip (sound and all) goes to the engine's upscaler, which
+ * becomes the run's finished video; the restored one turns into a step.
+ */
+function thenUpscale(steps: PlanStep[], final: string, input: RestorePlanInput): string {
+ if (!input.upscale) return final;
+ const last = steps.find((s) => s.key === final)!;
+ const { title, ...rest } = last.request;
+ const batchTitle = rest.batchTitle;
+ last.request = { ...rest, feature: RESTORE.stepFeature };
+ const u = RESTORE_UPSCALE[input.engine];
+ steps.push({
+ key: "upscale",
+ request: {
+ feature: RESTORE.feature,
+ batchTitle,
+ title: title ?? input.title,
+ modelId: u.modelId,
+ engine: input.engine,
+ op: "upscale-video",
+ params: { ...u.params },
+ step: { label: "Upscale", index: 1300, of: 1000 },
+ },
+ after: [final],
+ chain: [{ slot: "video" }],
+ });
+ return "upscale";
+}
+
/** The open join: the windows share one size and frame rate, so they're joined packet by packet (no decode, no resize). */
function joinEncoded(steps: PlanStep[], keys: string[], key: string, who: Pick<GenerationRequest, "feature" | "batchTitle" | "title">, what: string): string {
if (keys.length === 1) return keys[0];
diff --git a/src/lib/catalog/upscale-first.ts b/src/lib/catalog/upscale-first.ts
new file mode 100644
index 00000000..8d926ca4
--- /dev/null
+++ b/src/lib/catalog/upscale-first.ts
@@ -0,0 +1,25 @@
+/**
+ * Upscale → Video's "before upscaling" steps: one list, so each finishing package adds its row here (archive-restore:
+ * Restore archive footage first; n7-3's Regenerate in 2K is meant to be the next). A row opens its tool with the
+ * step that upscales after it already on, so the tool runs both as one job (Restore & colourise: `?then=upscale`).
+ */
+export interface UpscaleFirstStep {
+ id: string;
+ label: string;
+ /** One line under the label: what the step does and that the upscale follows it. */
+ hint: string;
+ /** The tool that runs the step, then the upscale. */
+ href: string;
+}
+
+export const UPSCALE_FIRST_STEPS: UpscaleFirstStep[] = [
+ {
+ id: "restore",
+ label: "Restore archive footage first",
+ hint: "Old scans, tape or black and white: cleaned and colourised by Fuobe Restore, then upscaled, in one run",
+ href: "/video-tools/restore?then=upscale",
+ },
+];
+
+/** The query a tool reads to switch its "then upscale" step on. */
+export const THEN_UPSCALE = "upscale";
diff --git a/src/lib/studios.ts b/src/lib/studios.ts
index c69c9c83..783ccc30 100644
--- a/src/lib/studios.ts
+++ b/src/lib/studios.ts
@@ -1,6 +1,7 @@
import { getModel } from "@/lib/catalog";
import { SIGNATURE_MODELS } from "@/lib/catalog/palettes";
import { FACE_MOSAIC_MODELS } from "@/lib/catalog/open-tools";
+import { UPSCALE_FIRST_STEPS } from "@/lib/catalog/upscale-first";
import type { Preset } from "@/lib/catalog/types";
import type { StudioConfig } from "@/components/studio/studio-context";
@@ -143,7 +144,7 @@ export const VIDEO_UPSCALE_STUDIO: StudioConfig = {
hero: "Sharper, bigger, cleaner video",
subtitle: "Upscale a clip to 1080p, 4K or up to 8K, and restore faces, textures and text.",
// Archive footage (scans, tape, black and white) is restored and colourised first: Fuobe Restore rebuilds it, then upscales.
- related: { href: "/video-tools/restore", label: "Old or black-and-white footage? Restore archive footage first" },
+ firstSteps: UPSCALE_FIRST_STEPS,
slots: [{ key: "video", label: "Video", accept: "video", required: true }],
defaultModels: { cloud: "topaz-video", open: "oss-seedvr2" },
clipFacts: true,
diff --git a/src/server/restore.ts b/src/server/restore.ts
index a4ae5285..6ff39a9c 100644
--- a/src/server/restore.ts
+++ b/src/server/restore.ts
@@ -11,6 +11,7 @@ import {
PROMPT_SYSTEM,
promptRequest,
RESTORE,
+ RESTORE_UPSCALE,
restoreNegative,
restoreProblem,
restoreTitle,
@@ -64,8 +65,10 @@ export const RestoreBodySchema = z.object({
hint: z.string().max(600).optional(),
/** GPU only: Restore to 4K (the Detail Refine pass). */
refine: z.boolean().optional(),
- /** GPU only: keep one field of interlaced frames first. */
+ /** GPU only: keep one field of interlaced frames first (ComfyUI has no fieldmatch / yadif / decimate node). */
deinterlace: z.boolean().optional(),
+ /** Upscale the restored clip after (Upscale → Restore archive footage first): Topaz Video in the cloud, SeedVR2 on your GPU. */
+ upscale: z.boolean().optional(),
/** A reference picture (true colours, a face, a sign). */
reference: fileUrl.optional(),
resolution: z.string().max(10).optional(),
@@ -155,7 +158,7 @@ function planInput(body: z.infer<typeof RestoreBodySchema>, info: Awaited<Return
hasAudio: probed ? (info.hasAudio ?? false) : (body.source.hasAudio ?? false),
};
const resolution = engine === "cloud" ? (body.resolution ?? RESTORE.cloudResolution) : undefined;
- const problem = restoreProblem({ engine, source: src, refine: body.refine, resolution });
+ const problem = restoreProblem({ engine, source: src, refine: body.refine, resolution, upscale: body.upscale });
if (problem) throw new ShortsError(problem, 422);
if (engine === "cloud" && body.deinterlace) throw new ShortsError("Deinterlacing runs on your GPU: the cloud endpoint takes the clip as it is", 422);
const notes: string[] = [];
@@ -163,9 +166,11 @@ function planInput(body: z.infer<typeof RestoreBodySchema>, info: Awaited<Return
notes.push(GPU_NOTE);
if (body.deinterlace) notes.push("Deinterlacing keeps one field of each frame (ComfyUI has no field-matching filter; telecined film keeps its repeated frames)");
if (body.refine) notes.push("Restore to 4K adds a detail pass at twice the size with Lightricks' Detail Refine IC-LoRA (1.3 GB, also gated): restore first, refine second");
+ if (body.upscale) notes.push(`Then upscaled on your GPU with ${RESTORE_UPSCALE.open.label} (free)`);
} else {
notes.push(CLOUD_NOTE);
notes.push("Each piece of up to 97 frames starts from the last restored frame of the one before, so the colour carries over");
+ if (body.upscale) notes.push(`Then upscaled with ${RESTORE_UPSCALE.cloud.label}, priced in`);
}
if (body.reference) notes.push(engine === "open" ? "Your reference picture goes to every window at frame_idx −1 (true colours, faces, signs)" : "In the cloud your picture is the first frame: give the clip's first frame already in colour");
if (!hasHfToken()) notes.push(GATED_NOTE);
@@ -183,6 +188,7 @@ function planInput(body: z.infer<typeof RestoreBodySchema>, info: Awaited<Return
...(body.reference ? { reference: body.reference } : {}),
...(resolution ? { resolution } : {}),
...(body.seed !== undefined ? { seed: body.seed } : {}),
+ ...(body.upscale ? { upscale: true } : {}),
},
};
}
diff --git a/tests/restore-api.test.ts b/tests/restore-api.test.ts
index f408684d..5089a29b 100644
--- a/tests/restore-api.test.ts
+++ b/tests/restore-api.test.ts
@@ -83,6 +83,14 @@ describe("Restore: estimates", () => {
expect(hd.costUsd).toBeGreaterThan(e.costUsd * 1.8);
});
+ it("prices Then upscale in: Topaz Video after the pieces, joins and sound", async () => {
+ const plain = await (await estimateRoute.POST(json(body({ engine: "cloud" })))).json();
+ const up = await (await estimateRoute.POST(json(body({ engine: "cloud", upscale: true })))).json();
+ expect(up.steps).toBe(plain.steps + 1);
+ expect(up.costUsd).toBeGreaterThan(plain.costUsd);
+ expect(up.notes.join(" ")).toMatch(/Then upscaled with Topaz Video, to 2160p, priced in/);
+ });
+
it("refuses a paid cloud restoration before it starts while no Hugging Face token is set (the LoRA goes as Fuobe's copy)", async () => {
setSetting("huggingfaceDownloadToken", "");
const before = (db().prepare("SELECT COUNT(*) AS n FROM generations").get() as { n: number }).n;
@@ -135,6 +143,15 @@ describe("Restore: runs in demo mode", () => {
expect(req.title).toMatch(/^Restored · A harbour in the 1930s · reel$/);
});
+ it("GPU, Then upscale: SeedVR2 after the sound is back, and the upscaled clip is the result", async () => {
+ const out = await (await createRoute.POST(json(body({ upscale: true })))).json();
+ const rows = batchOf(out.final.id);
+ expect(rows.at(-1)).toMatchObject({ model_id: "oss-seedvr2", op: "upscale-video", feature: "restore" });
+ expect(rows.filter((r) => r.feature === "restore")).toHaveLength(1);
+ expect(out.final.id).toBe(rows.at(-1)!.id);
+ expect((await settle(out.final.id)).status).toBe("succeeded");
+ });
+
it("cloud: cut pieces, a hand-off frame, the join and the sound, written words kept", async () => {
const res = await createRoute.POST(json(body({ engine: "cloud", prompt: "", hint: "a harbour" })));
const out = await res.json();
diff --git a/tests/restore.test.ts b/tests/restore.test.ts
index e8c3ea40..7608bd56 100644
--- a/tests/restore.test.ts
+++ b/tests/restore.test.ts
@@ -23,6 +23,8 @@ import {
tileGrid,
} from "@/lib/catalog/restore";
import { restoreGraph, restoreGraphLoras, restoreJob } from "@/lib/restore-graph";
+import { THEN_UPSCALE, UPSCALE_FIRST_STEPS } from "@/lib/catalog/upscale-first";
+import { VIDEO_UPSCALE_STUDIO } from "@/lib/studios";
import type { ComfyWorkflow } from "@/lib/comfy";
import { getModel, getPreset } from "@/lib/catalog";
import { onEngine } from "@/lib/catalog/engines";
@@ -237,6 +239,27 @@ describe("Restore & colourise: the pipeline", () => {
expect(cloudShape(720, 576)).toBe("4:3");
});
+ it("Then upscale (Upscale → Restore archive footage first): the restored clip goes to the engine's upscaler, which is the result", () => {
+ for (const [engine, model] of [
+ ["open", "oss-seedvr2"],
+ ["cloud", "topaz-video"],
+ ] as const) {
+ const plan = planRestore({ engine, title: "Restored", source, ...words, upscale: true });
+ expect(plan.final, engine).toBe("upscale");
+ const up = plan.steps[plan.steps.length - 1];
+ expect(up, engine).toMatchObject({ key: "upscale", after: ["final"], chain: [{ slot: "video" }] });
+ expect(up.request, engine).toMatchObject({ modelId: model, engine, op: "upscale-video", feature: "restore", title: "Restored", params: { resolution: "2160p" } });
+ // The restored clip with its sound is now a step: one finished video per run.
+ expect(plan.steps.filter((s) => s.request.feature === "restore").map((s) => s.key), engine).toEqual(["upscale"]);
+ expect(plan.steps.find((s) => s.key === "final")!.request.title, engine).toBeUndefined();
+ }
+ expect(restoreProblem({ engine: "open", source: { duration: 4, fps: 24 }, refine: true, upscale: true })).toMatch(/Restore to 4K already doubles the size/);
+ expect(restoreProblem({ engine: "open", source: { duration: 4, fps: 24 }, upscale: true })).toBeNull();
+ // Upscale → Video lists it among its first steps, opening Restore with the upscale on.
+ expect(VIDEO_UPSCALE_STUDIO.firstSteps).toEqual(UPSCALE_FIRST_STEPS);
+ expect(UPSCALE_FIRST_STEPS.find((f) => f.id === "restore")).toMatchObject({ label: "Restore archive footage first", href: `/video-tools/restore?then=${THEN_UPSCALE}` });
+ });
+
it("prices a cloud piece per megapixel of video on the LoRA endpoint; free on the GPU", () => {
const m = getModel("fuobe-restore")!;
const cloud = onEngine(m, "cloud");