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
Faceless: Regenerate to 1080p redraws each scene on your GPU, then joins and mixes it again
Claude9c387bd1535a
diff --git a/src/app/api/faceless/episodes/[id]/[action]/route.ts b/src/app/api/faceless/episodes/[id]/[action]/route.tsindex 415d3774..89f4b908 100644--- a/src/app/api/faceless/episodes/[id]/[action]/route.ts+++ b/src/app/api/faceless/episodes/[id]/[action]/route.ts@@ -1,4 +1,4 @@-import { episodeView, handle, renderEpisode, retryEpisode, rewriteEpisode, undoChange, upscaleEpisode } from "@/server/faceless";+import { episodeView, handle, regenerateEpisode, renderEpisode, retryEpisode, rewriteEpisode, undoChange, upscaleEpisode } from "@/server/faceless";const ACTIONS = {/** Render the reviewed script. */@@ -11,6 +11,8 @@ const ACTIONS = {undo: undoChange,/** Upscale the finished film to 1080p (cloud). */upscale: upscaleEpisode,+ /** Redraw every scene at 1080p with Open-H3 Regenerate, then join and mix again (open engine). */+ regenerate: regenerateEpisode,} as const;export async function POST(request: Request, ctx: RouteContext<"/api/faceless/episodes/[id]/[action]">) {diff --git a/src/components/faceless/episode-view.tsx b/src/components/faceless/episode-view.tsxindex e6e1d88f..c5e938c4 100644--- a/src/components/faceless/episode-view.tsx+++ b/src/components/faceless/episode-view.tsx@@ -18,6 +18,7 @@ import {Music,Pencil,RotateCcw,+ Sparkles,Trash2,Undo2,Wand2,@@ -55,7 +56,8 @@ import {type StepView,} from "@/lib/catalog/faceless";import type { Generation } from "@/lib/catalog/types";-import { useIsVisitor } from "@/lib/api";+import { useEngineMode, useIsVisitor } from "@/lib/api";+import { FACELESS_REGEN_COPY } from "@/lib/catalog/faceless";import { timeAgo } from "@/lib/format";import { downloadHref, downloadName } from "@/lib/library";import { cn } from "@/lib/utils";@@ -466,6 +468,7 @@ export function EpisodeView({ id, backHref, backLabel }: { id: string; backHref:const router = useRouter();const { data: view, error, isLoading } = useEpisode(id);const action = useEpisodeAction(id);+ const engineMode = useEngineMode();const update = useUpdateEpisode(id);const del = useDeleteEpisode();const [renaming, setRenaming] = useState(false);@@ -475,12 +478,17 @@ export function EpisodeView({ id, backHref, backLabel }: { id: string; backHref:if (error && /not found/i.test((error as Error).message)) return <NotFoundState title="This episode doesn't exist">It may have been deleted. Its videos are still in your library.</NotFoundState>;const ep = view?.episode;- // The download is the 1080p copy once it's made, else the film.+ // The download is the 1080p copy once it's made (the newer of the upscaled and the regenerated film), else the film.const upscaled = view?.upscaled?.status === "succeeded" ? view.upscaled : null;const upscaling = !!view?.upscaled && active(view.upscaled);- const film = upscaled ?? view?.final;+ const regenerated = view?.regenerated?.status === "succeeded" ? view.regenerated : null;+ const regenerating = view?.regenerating ?? null;+ // Regenerate runs on your GPU only: Engine mode "Paid APIs only" hides it.+ const regenOffer = engineMode !== "cloud" ? view?.regenerate : null;+ const sharp = [upscaled, regenerated].filter((g): g is Generation => !!g).sort((a, b) => b.createdAt - a.createdAt)[0] ?? null;+ const film = sharp ?? view?.final;const filmOut = film?.outputs.find((o) => o.kind === "video");- const run = (a: "retry" | "rewrite" | "undo" | "upscale", ok?: string) => action.mutate(a, { onSuccess: () => ok && toast.success(ok), onError: (e) => toastError(e) });+ const run = (a: "retry" | "rewrite" | "undo" | "upscale" | "regenerate", ok?: string) => action.mutate(a, { onSuccess: () => ok && toast.success(ok), onError: (e) => toastError(e) });return (<div className="flex min-h-svh min-w-0 flex-col">@@ -497,10 +505,15 @@ export function EpisodeView({ id, backHref, backLabel }: { id: string; backHref:<Loader2 className="size-3 animate-spin" /> Upscaling to 1080p</span>)}+ {regenerating && (+ <span className="hidden items-center gap-1.5 text-[12px] text-muted-foreground sm:inline-flex" aria-live="polite">+ <Loader2 className="size-3 animate-spin" /> Regenerating · {regenerating.done} of {regenerating.of} steps+ </span>+ )}{filmOut && film && (<Button asChild variant="outline" size="sm">- <a href={downloadHref(filmOut.url, downloadName(film, filmOut, 0))} download aria-label={upscaled ? "Download (1080p)" : "Download"}>- <Download /> <span className="hidden sm:inline">{upscaled ? "Download 1080p" : "Download"}</span>+ <a href={downloadHref(filmOut.url, downloadName(film, filmOut, 0))} download aria-label={sharp ? "Download (1080p)" : "Download"}>+ <Download /> <span className="hidden sm:inline">{sharp ? "Download 1080p" : "Download"}</span></a></Button>)}@@ -535,6 +548,20 @@ export function EpisodeView({ id, backHref, backLabel }: { id: string; backHref:</span></DropdownMenuItem>)}+ {regenOffer && !regenerated && (+ <DropdownMenuItem+ disabled={!!regenerating || action.isPending}+ onClick={() => run("regenerate", "Regenerating each scene at 1080p — the download switches to it when it's done")}+ className="items-start"+ >+ <Sparkles className="mt-0.5" />+ <span className="flex min-w-0 flex-col">+ <span>{regenerating ? `Regenerating… ${regenerating.done} of ${regenerating.of}` : FACELESS_REGEN_COPY.label}</span>+ <span className="max-w-56 text-[11.5px] leading-snug text-muted-foreground">Sharper, may redraw · {FACELESS_REGEN_COPY.time(regenOffer.scenes)}</span>+ </span>+ <span className="ml-auto pl-3 font-mono text-[11px] text-muted-foreground tabular-nums">Free</span>+ </DropdownMenuItem>+ )}<DropdownMenuItem variant="destructive" onClick={() => setTimeout(() => setConfirm(true))}><Trash2 /> Delete episode</DropdownMenuItem>diff --git a/src/components/faceless/hooks.ts b/src/components/faceless/hooks.tsindex cf0ebbcd..d87f5354 100644--- a/src/components/faceless/hooks.ts+++ b/src/components/faceless/hooks.ts@@ -127,14 +127,15 @@ export function useEpisode(id: string) {refetchInterval: (q) => {const s = q.state.data?.episode.status;const up = q.state.data?.upscaled?.status;- if (up === "queued" || up === "running") return connected ? 8000 : 2000;+ const regen = q.state.data?.regenerated?.status;+ if (up === "queued" || up === "running" || regen === "queued" || regen === "running") return connected ? 8000 : 2000;if (!s || !inFlight(s)) return false;return s === "writing" ? 1500 : connected ? 8000 : 2000;},});useEffect(() => {const plan = q.data?.episode.plan;- ids.current = new Set([...Object.values(plan?.ids ?? {}), ...(plan?.upscaled ? [plan.upscaled] : [])]);+ ids.current = new Set([...Object.values(plan?.ids ?? {}), ...(plan?.upscaled ? [plan.upscaled] : []), ...Object.values(plan?.regenerated?.ids ?? {})]);}, [q.data]);return q;}@@ -158,7 +159,7 @@ export function useUpdateEpisode(id: string) {}export function useEpisodeAction(id: string) {- return useEpisodeMutation(id, (action: "render" | "retry" | "rewrite" | "undo" | "upscale") => send<EpisodeView>(`/api/faceless/episodes/${id}/${action}`, "POST"));+ return useEpisodeMutation(id, (action: "render" | "retry" | "rewrite" | "undo" | "upscale" | "regenerate") => send<EpisodeView>(`/api/faceless/episodes/${id}/${action}`, "POST"));}export interface ChangeDraft {diff --git a/src/lib/catalog/faceless.ts b/src/lib/catalog/faceless.tsindex aa582fbd..77033097 100644--- a/src/lib/catalog/faceless.ts+++ b/src/lib/catalog/faceless.ts@@ -1,6 +1,7 @@import { describeMove, KEN_BURNS_FPS, sceneMoves } from "@/lib/av/ken-burns";import { COPY_JOIN_VIDEOS, lengthRange, plannedDurations } from "./clip-lengths";import { estimateCost } from "./plan";+import { REGEN_FINISH_TIER, REGEN_MODEL, regenFinishSteps, sixteenFpsModel, type FinishStep } from "./regenerate";import { pricingAt } from "./promo";import type { ChainSlot, Engine, Generation, GenerationRequest, ModelDef } from "./types";@@ -630,6 +631,11 @@ export interface EngineModels {sourceStill?: string;/** "Upscale to 1080p" on a finished episode (cloud: SeedVR2; open: Real-ESRGAN in passes of a few frames, so memory stays flat). */upscale?: string;+ /**+ * "Regenerate to 1080p (sharper, may redraw)": each scene redrawn by Open-H3 Regenerate before the join and the music+ * (open engine only: nobody hosts the open refiner, so the cloud keeps its upscaler and shows no Regenerate).+ */+ regenerate?: string;write: string;}@@ -684,6 +690,7 @@ export const ENGINE_MODELS: Record<Engine, EngineModels> = {captionsUseWords: true,sourceStill: "oss-qwen-image-21-turbo",upscale: "oss-upscale-video-esrgan",+ regenerate: REGEN_MODEL,write: "oss-text-llm",},};@@ -1243,6 +1250,91 @@ export function buildEpisodeGraph(input: GraphInput, lookup: ModelLookup): Graph/** The step whose output is the finished episode. */export const finalKey = (graph: Pick<GraphStep, "key">[]) => (graph.some((s) => s.key === "captions") ? "captions" : "mix");+// ---------------------------------------------------------------------------+// "Regenerate to 1080p" (package n7-10; docs/research/new-models-7.md §2.10)++/** Keys of the regenerated film's steps (beside the episode's own). */+export const REGEN_PREFIX = "regen-";++export const FACELESS_REGEN_COPY = {+ label: "Regenerate to 1080p",+ hint: "Sharper, may redraw: each scene is redrawn at 1080p from its own words, then joined under the same voice and music.",+ /** The GPU time a visitor sees (no install detail). */+ time: (scenes: number) => `Runs on your GPU · about ${Math.max(1, Math.round(scenes * 1.5))} min`,+ done: "Regenerated (1080p)",+} as const;++/**+ * The regenerated film from an episode's graph: each clip (one scene, or one shot of it; never over 15 s) is redrawn by+ * Open-H3 Regenerate at 1080p with the 576p preset and start sigma 0.8, from the scene's own words (its picture's+ * prompt, and its motion for an animated scene); a 16 fps clip (Wan) goes through RIFE to 24 fps first. Then the clips+ * are joined the way the episode joins them, at 1080p, and the same narration, music bed and subtitles go on top: the+ * steps reuse the episode's narration, bed and timing (their keys stay as they are, for `existing`). `joinMax` is the+ * episode's fold size (resolveModels).+ */+export function regeneratePlan(graph: GraphStep[], o: { engine: Engine; joinMax: number; lookup: ModelLookup }): { steps: FinishStep[]; final: string } {+ const regen = ENGINE_MODELS[o.engine].regenerate;+ if (!regen) throw new Error("Regenerate runs on your GPU (open source): switch the episode to open source to use it");+ const byKey = new Map(graph.map((s) => [s.key, s]));+ const steps: FinishStep[] = [];+ const clips: string[] = [];+ for (const c of graph.filter((s) => s.part === "clip")) {+ const still = c.after?.length ? byKey.get(c.after[0]) : undefined;+ const words = [still?.request.prompt, c.request.op === "i2v" ? c.request.prompt : undefined].filter((w): w is string => !!w?.trim()).join(" ");+ const seconds = c.seconds ?? c.request.params?.duration ?? 5;+ const plan = regenFinishSteps({+ key: `${REGEN_PREFIX}${c.key}`,+ clip: { key: c.key },+ prompt: words || c.request.prompt || "",+ seconds,+ fps: sixteenFpsModel(c.request.modelId) ? 16 : undefined,+ draftFrom: "other",+ helper: { feature: c.request.feature, batchTitle: c.request.batchTitle },+ label: c.label,+ });+ steps.push(...plan.steps);+ clips.push(plan.final);+ }+ if (!clips.length) throw new Error("The episode has no scenes to regenerate");+ // The joins: the episode's own join model, folded the same way, at 1080p where it takes a size.+ const join = graph.find((s) => s.part === "join");+ let film = clips[0];+ if (join) {+ const sized = o.lookup(join.request.modelId)?.options.resolutions?.includes(REGEN_FINISH_TIER);+ const name = (k: string) => (clips.includes(k) ? k : `${REGEN_PREFIX}${k}`);+ for (const level of foldJoins(clips, o.joinMax)) {+ for (const j of level) {+ steps.push({+ key: name(j.key),+ request: { ...join.request, params: { ...join.request.params, ...(sized && { resolution: REGEN_FINISH_TIER }) }, step: { label: j.key === "join" ? "Joining the redrawn scenes" : "Joining scenes", index: 0, of: 1 } },+ after: j.after.map(name),+ chain: j.after.map(() => ({ slot: "videos" as const })),+ });+ }+ }+ if (clips.length > 1) film = `${REGEN_PREFIX}join`;+ }+ // The same voice, bed and subtitles as the episode.+ const mix = graph.find((s) => s.key === "mix");+ if (!mix) throw new Error("The episode has no mix to put on the redrawn scenes");+ const swap = (k: string) => (k === mix.after?.[0] ? film : k);+ steps.push({ key: `${REGEN_PREFIX}mix`, request: { ...mix.request, title: undefined }, after: (mix.after ?? []).map(swap), chain: mix.chain });+ const captions = graph.find((s) => s.key === "captions");+ if (captions) {+ steps.push({ key: `${REGEN_PREFIX}captions`, request: captions.request, after: (captions.after ?? []).map((k) => (k === "mix" ? `${REGEN_PREFIX}mix` : k)), chain: captions.chain });+ }+ const final = captions ? `${REGEN_PREFIX}captions` : `${REGEN_PREFIX}mix`;+ const last = steps.find((s) => s.key === final)!;+ last.request = { ...last.request, title: `${graph[0]?.request.batchTitle ?? "Episode"} · 1080p` };+ return { steps, final };+}++/** The episode steps a regenerated film reads as they are (its clips, narration, timing and bed). */+export function regenerateReuses(steps: FinishStep[]): string[] {+ const own = new Set(steps.map((s) => s.key));+ return [...new Set(steps.flatMap((s) => s.after ?? []).filter((k) => !own.has(k)))];+}+/** Keys that wait (directly or not) on any of `keys`. */export function descendants(graph: Pick<GraphStep, "key" | "after">[], keys: Iterable<string>): Set<string> {const out = new Set<string>();@@ -2063,6 +2155,8 @@ export interface EpisodePlan {lastFinal?: string;/** "Upscale to 1080p": the upscaled copy of the finished film. */upscaled?: string;+ /** "Regenerate to 1080p" (open engine): its steps by key, and the finished film's generation. */+ regenerated?: { ids: Record<string, string>; final: string };changes: EpisodeChange[];}@@ -2111,6 +2205,12 @@ export interface EpisodeView {upscaled: Generation | null;/** What "Upscale to 1080p" would cost (null: not offered on this engine). */upscale: { costUsd: number | null; demo: boolean } | null;+ /** The film with every scene regenerated at 1080p, once asked for. */+ regenerated: Generation | null;+ /** While it renders: its steps done of all. */+ regenerating: { done: number; of: number } | null;+ /** "Regenerate to 1080p" on this engine (null: not offered, as on the cloud): free on your GPU. */+ regenerate: { scenes: number; demo: boolean } | null;}/** One item in the Explainer's history or a channel's episode list. */diff --git a/src/lib/catalog/regenerate.ts b/src/lib/catalog/regenerate.tsindex 6eb00fc5..9842dab7 100644--- a/src/lib/catalog/regenerate.ts+++ b/src/lib/catalog/regenerate.ts@@ -7,7 +7,7 @@* Nobody hosts the open model, so Regenerate · creative is GPU-only: the cloud engine says it runs on your GPU, and* Engine mode "Paid APIs only" hides it (the owner's rule of 10-30).*/-import type { Generation, GenerationRequest, LoraRef } from "./types";+import type { ChainSlot, Generation, GenerationRequest, LoraRef } from "./types";export const REGEN_MODEL = "oss-h3-regenerate";export const REGEN_WORKFLOW = "video-regenerate-h3";@@ -107,6 +107,111 @@ export function regenOnePassRefusal(seconds: number): string {return `Regenerate redraws up to 15 s in one pass, and this clip runs ${Math.round(seconds * 10) / 10} s. Open the finished clip and pick Regenerate in 2K: it is redrawn in 15 s parts and joined`;}+// ---------------------------------------------------------------------------+// Finishing passes inside other tools (package n7-10): Faceless scenes, Shorts segments, Edit video results++/** The start noise a finishing pass uses (rdh: 0.8 "stays closer to the draft"; Creativity's Balanced). */+export const REGEN_FINISH_SIGMA = 0.8;+/** The size a scene or a segment is finished at (the shorter edge). */+export const REGEN_FINISH_TIER = "1080p";+/** RIFE (FPS Boost's graph): a 16 fps clip is brought to Regenerate's 24 fps first, so no frame is redrawn twice. */+export const REGEN_SMOOTH_MODEL = "oss-rife";++/** Whether a clip at this frame rate goes through RIFE first (Prepare Draft would otherwise repeat frames to reach 24). */+export function needsSmoothing(fps: number | undefined): boolean {+ return typeof fps === "number" && fps > 0 && fps < REGEN_FPS - 0.5;+}++/** Wan 2.x and the tools built on it (Wan VACE restyles) make 16 fps clips. */+export function sixteenFpsModel(modelId: string | undefined): boolean {+ return !!modelId && /(^|-)wan(\d|-|$)|vace/.test(modelId);+}++/** A clip a finishing pass reads: a stored file, or what an earlier step makes (its key). */+export type FinishClip = { url: string } | { key: string };++export interface FinishStepsInput {+ /** The steps' key prefix (unique in the plan). */+ key: string;+ clip: FinishClip;+ /** The words the pass redraws from (the scene's or the segment's own). */+ prompt: string;+ /** The clip's length (at most 15 s: one pass). */+ seconds: number;+ /** The clip's frame rate: below 24, RIFE runs first. */+ fps?: number;+ /** The draft preset: "h3" (768p, an H3 draft) or "other" (576p). */+ draftFrom: "h3" | "other";+ tier?: (typeof REGEN_TIERS)[number];+ /** Fields every step shares (feature, batch title). */+ helper: Pick<GenerationRequest, "feature" | "batchTitle">;+ label: string;+ seed?: number;+}++/** A plan step (src/lib/catalog/shorts.ts PlanStep's shape, kept here so this module stays free of the tools). */+export interface FinishStep {+ key: string;+ request: GenerationRequest;+ after?: string[];+ chain?: ChainSlot[];+}++/** Why a finishing pass can't take this clip (one pass redraws at most 15 s), or null. */+export function finishLengthProblem(seconds: number | undefined): string | null {+ if (seconds === undefined || !(seconds > 0)) return null;+ return seconds > REGEN_WINDOW_SECONDS + 0.05 ? `Regenerate redraws up to ${REGEN_WINDOW_SECONDS} s in one pass, and this part runs ${Math.round(seconds * 10) / 10} s. Pick a shorter part` : null;+}++/**+ * One finishing pass of a clip: RIFE to 24 fps first when it is slower (a Wan VACE restyle's 16 fps), then Open-H3+ * Regenerate at 1080p from the clip's own words, near the draft (start sigma 0.8), with the preset asked for. Returns+ * the steps and the key of the finished clip.+ */+export function regenFinishSteps(o: FinishStepsInput): { steps: FinishStep[]; final: string } {+ const problem = finishLengthProblem(o.seconds);+ if (problem) throw new Error(problem);+ const steps: FinishStep[] = [];+ let clip = o.clip;+ if (needsSmoothing(o.fps)) {+ const key = `${o.key}-smooth`;+ steps.push({+ key,+ request: {+ ...o.helper,+ modelId: REGEN_SMOOTH_MODEL,+ op: "interpolate",+ ...("url" in clip ? { inputs: { video: clip.url } } : {}),+ params: { targetFps: REGEN_FPS, numOutputs: 1 },+ step: { label: `${o.label} · to ${REGEN_FPS} fps`, index: 0, of: 2 },+ },+ ...("key" in clip ? { after: [clip.key], chain: [{ slot: "video" as const }] } : {}),+ });+ clip = { key };+ }+ const key = `${o.key}-regen`;+ steps.push({+ key,+ request: {+ ...o.helper,+ modelId: REGEN_MODEL,+ op: "upscale-video",+ prompt: o.prompt.trim().slice(0, HANDOFF_PROMPT),+ ...("url" in clip ? { inputs: { video: clip.url } } : {}),+ params: {+ resolution: o.tier ?? REGEN_FINISH_TIER,+ sourceDuration: Math.round(o.seconds * 1000) / 1000,+ numOutputs: 1,+ ...(o.seed !== undefined ? { seed: o.seed } : {}),+ extra: { startSigma: REGEN_FINISH_SIGMA, draftFrom: o.draftFrom },+ },+ step: { label: `${o.label} · redraw at ${o.tier ?? REGEN_FINISH_TIER}`, index: steps.length, of: steps.length + 1 },+ },+ ...("key" in clip ? { after: [clip.key], chain: [{ slot: "video" as const }] } : {}),+ });+ return { steps, final: key };+}+/** The note for a clip that isn't 16:9 or 9:16. */export function regenCropNote(width: number, height: number): string {return `Regenerate makes ${regenShape(width, height)} video, so this ${width}×${height} clip is cropped to ${regenShape(width, height)} at the centre`;diff --git a/src/server/faceless.ts b/src/server/faceless.tsindex 4c1d4b40..de9143cf 100644--- a/src/server/faceless.ts+++ b/src/server/faceless.ts@@ -31,6 +31,8 @@ import {plannedTiming,planRerun,previewLine,+ regeneratePlan,+ regenerateReuses,resolveModels,sameCameraMove,sceneSpans,@@ -86,6 +88,7 @@ import { PdfError, pdfText } from "./assist/pdf";import { db } from "./db";import { listElements } from "./elements";import { connectRefusal } from "./connect-refusal";+import { createPipeline } from "./chains";import { cancelGeneration, chooseRoute, ConnectComfyError, createGenerations, getGeneration, previewChained } from "./generations";import { provider } from "./providers";import type { JsonSpec } from "./llm";@@ -673,7 +676,7 @@ function stopEpisode(ep: FacelessEpisode): Promise<void>[] {w.abort.abort();writing().delete(ep.id);}- const ids = new Set([...Object.values(ep.plan?.ids ?? {}), ...Object.values(ep.plan?.previous?.ids ?? {}), ...(ep.plan?.upscaled ? [ep.plan.upscaled] : [])]);+ const ids = new Set([...Object.values(ep.plan?.ids ?? {}), ...Object.values(ep.plan?.previous?.ids ?? {}), ...(ep.plan?.upscaled ? [ep.plan.upscaled] : []), ...Object.values(ep.plan?.regenerated?.ids ?? {})]);return [...ids].map((g) => cancelGeneration(g).catch(() => {}));}@@ -1035,8 +1038,9 @@ export function applyChange(id: string, c: ChangeInput): FacelessEpisode {stillEdits,previous: { ids: p.ids, blocks: ep.script.blocks, stillEdits: p.stillEdits, timing: p.timing, untimed: p.untimed, awaiting: p.awaiting },lastFinal: final?.status === "succeeded" ? final.id : p.lastFinal,- // A new version: its upscale is made again on request.+ // A new version: its upscale (or regenerated film) is made again on request.upscaled: undefined,+ regenerated: undefined,changes: [...p.changes, { at: Date.now(), blocks: ids, part: c.part, instruction: c.part === "narration" ? (c.narration ?? []).join(" / ") : (c.instruction ?? ""), costUsd: est.unknown ? null : est.total }].slice(-50),};updateEpisodeRow(id, { status: "rendering", error: null, plan_json: JSON.stringify(updated), script_json: JSON.stringify({ ...ep.script, blocks }) });@@ -1063,6 +1067,7 @@ export function undoChange(id: string): FacelessEpisode {previous: undefined,lastFinal: undefined,upscaled: undefined,+ regenerated: undefined,changes,};updateEpisodeRow(id, { status: "rendering", error: null, plan_json: JSON.stringify(plan), script_json: JSON.stringify({ ...ep.script, blocks: prev.blocks }) });@@ -1114,6 +1119,60 @@ export function upscaleEpisode(id: string): FacelessEpisode {return mustEpisode(id);}+// ---------------------------------------------------------------------------+// Regenerate to 1080p (open engine)++/** "Regenerate to 1080p" on this episode: offered on the open engine once the film is done (null otherwise). */+function regenerateOffer(ep: FacelessEpisode, scenes: number): EpisodeView["regenerate"] {+ const modelId = ENGINE_MODELS[ep.settings.engine].regenerate;+ if (!modelId || !getModel(modelId)) return null;+ let demo = false;+ try {+ demo = runsAsDemo(modelId, "upscale-video");+ } catch {+ // Nothing connected runs it yet: offered, and the click opens the connect card.+ }+ return { scenes, demo };+}++/**+ * "Regenerate to 1080p": every scene redrawn by Open-H3 Regenerate (RIFE first for a 16 fps clip), joined at 1080p, with+ * the episode's own narration, music bed and subtitles put back on (regeneratePlan). Runs on your GPU only; the finished+ * film becomes the download once it's done, beside "Upscale to 1080p".+ */+export function regenerateEpisode(id: string): FacelessEpisode {+ const ep = mustEpisode(id);+ if (!ENGINE_MODELS[ep.settings.engine].regenerate) throw new FacelessError("Regenerate runs on your GPU (open source): switch the episode to open source to use it", 422);+ const final = finalOf(ep);+ if (!ep.plan || !final) throw new FacelessError("Wait for the episode to finish first", 409);+ const had = ep.plan.regenerated ? getGeneration(ep.plan.regenerated.final) : null;+ if (had && had.status !== "failed" && had.status !== "canceled") return ep;+ const graph = currentGraph(ep);+ const models = resolveModels(withOfferedVideo(ep.settings), narrationText(ep.script.blocks).length, getModel);+ let plan: ReturnType<typeof regeneratePlan>;+ try {+ plan = regeneratePlan(graph, { engine: ep.settings.engine, joinMax: models.joinMax, lookup: getModel });+ } catch (e) {+ throw new FacelessError((e as Error).message, 422);+ }+ const existing: Record<string, string> = {};+ for (const k of regenerateReuses(plan.steps)) {+ const gid = ep.plan.ids[k];+ if (!gid || getGeneration(gid)?.status !== "succeeded") throw new FacelessError(`“${graph.find((s) => s.key === k)?.label ?? k}” has no result to reuse — retry the episode first`, 409);+ existing[k] = gid;+ }+ let made: Record<string, string>;+ try {+ const pipeline = createPipeline(plan.steps, { batchId: ep.plan.batchId, existing });+ made = Object.fromEntries(plan.steps.map((s) => [s.key, pipeline.byKey[s.key].id]));+ } catch (e) {+ if (e instanceof ConnectComfyError) throw e;+ throw new FacelessError((e as Error).message, 422);+ }+ updateEpisodeRow(id, { plan_json: JSON.stringify({ ...ep.plan, regenerated: { ids: made, final: made[plan.final] } } satisfies EpisodePlan) });+ return mustEpisode(id);+}+// ---------------------------------------------------------------------------// Reading, and the sweep that starts stage two@@ -1216,6 +1275,8 @@ export function episodeView(id: string): EpisodeView {const spent = [...gens.values()].reduce((n, g) => n + (g && g.status !== "failed" && g.status !== "canceled" ? (g.costUsd ?? 0) : 0), 0);const spans = sceneSpans(graph, current.script.blocks.length);const upscaled = plan?.upscaled ? getGeneration(plan.upscaled) : null;+ const regenIds = Object.values(plan?.regenerated?.ids ?? {});+ const regenerated = plan?.regenerated ? getGeneration(plan.regenerated.final) : null;return {episode: current,channel: current.channelId ? getChannel(current.channelId) : null,@@ -1229,6 +1290,9 @@ export function episodeView(id: string): EpisodeView {timing: plan?.timing && !plan.untimed ? "narration" : "planned",upscaled,upscale: final ? upscaleOffer(current, spans.reduce((n, s) => n + s.seconds, 0)) : null,+ regenerated,+ regenerating: regenerated && (regenerated.status === "queued" || regenerated.status === "running") ? { done: regenIds.filter((g) => getGeneration(g)?.status === "succeeded").length, of: regenIds.length } : null,+ regenerate: final ? regenerateOffer(current, steps.filter((s) => s.part === "clip").length) : null,};}diff --git a/tests/faceless-api.test.ts b/tests/faceless-api.test.tsindex 391a572a..dfa472f5 100644--- a/tests/faceless-api.test.ts+++ b/tests/faceless-api.test.ts@@ -256,6 +256,28 @@ describe("Episodes", () => {expect(up.request.params?.resolution).toBe("1080p");const upscalingOpen: EpisodeView = await (await actionRoute.POST(json("POST"), params({ id: openId, action: "upscale" }))).json();expect(gens.getGeneration(upscalingOpen.episode.plan!.upscaled!)).toMatchObject({ op: "upscale-video", modelId: "oss-upscale-video-esrgan", engine: "open" });+ // Regenerate to 1080p (open engine only): every scene redrawn by Open-H3 Regenerate, joined and mixed again with the+ // episode's own narration and subtitles timing; the cloud shows no Regenerate.+ expect(doneCloud.regenerate).toBeNull();+ expect(doneOpen.regenerate).toEqual({ scenes: 6, demo: true });+ expect((await actionRoute.POST(json("POST"), params({ id: cloudId, action: "regenerate" }))).status).toBe(422);+ const regenOpen: EpisodeView = await (await actionRoute.POST(json("POST"), params({ id: openId, action: "regenerate" }))).json();+ const rIds = regenOpen.episode.plan!.regenerated!.ids;+ const redraws = Object.entries(rIds).filter(([k]) => k.endsWith("-regen")).map(([, g]) => gens.getGeneration(g)!);+ expect(redraws).toHaveLength(6);+ for (const g of redraws) {+ expect(g).toMatchObject({ modelId: "oss-h3-regenerate", op: "upscale-video", engine: "open" });+ expect(g.request.params).toMatchObject({ resolution: "1080p", extra: { startSigma: 0.8, draftFrom: "other" } });+ expect(g.request.prompt?.length).toBeGreaterThan(20);+ }+ // The narration, its timing and the bed are the episode's own: nothing is read or timed again.+ expect(gens.getGeneration(rIds["regen-mix"])).toMatchObject({ op: "mux" });+ expect(Object.keys(rIds).filter((k) => !k.startsWith("regen-"))).toEqual([]);+ expect(Object.values(rIds)).not.toContain(doneOpen.episode.plan!.ids.narration);+ expect(regenOpen.episode.plan!.regenerated!.final).toBe(rIds["regen-captions"]);+ // A second click while it renders starts nothing new.+ const again: EpisodeView = await (await actionRoute.POST(json("POST"), params({ id: openId, action: "regenerate" }))).json();+ expect(again.episode.plan!.regenerated!.ids).toEqual(rIds);// Timeline editor: change scene 3's picture.const target = doneCloud.episode.script.blocks[2].id;diff --git a/tests/regenerate-more.test.ts b/tests/regenerate-more.test.tsnew file mode 100644index 00000000..750e9cc1--- /dev/null+++ b/tests/regenerate-more.test.ts@@ -0,0 +1,104 @@+import { describe, expect, it } from "vitest";+import { getModel } from "@/lib/catalog";+import { buildEpisodeGraph, defaultSettings, ENGINE_MODELS, genreInfo, REGEN_PREFIX, regeneratePlan, regenerateReuses, resolveModels, narrationText, type EpisodeSettings, type ScriptBlock } from "@/lib/catalog/faceless";+import { finishLengthProblem, needsSmoothing, REGEN_FINISH_SIGMA, REGEN_MODEL, REGEN_SMOOTH_MODEL, regenFinishSteps, sixteenFpsModel } from "@/lib/catalog/regenerate";++const block = (i: number, seconds = 6): ScriptBlock => ({ id: `b${i}`, narration: `Line ${i} of the story, read slowly and clearly.`, visual: `A lighthouse at dusk, scene ${i}`, motion: "slow push-in", seconds });++function plan(s: Partial<EpisodeSettings>, blocks: ScriptBlock[]) {+ const settings = { ...defaultSettings(s.engine ?? "open", genreInfo("education")), ...s };+ const graph = buildEpisodeGraph({ feature: "faceless", title: "Lighthouses", genre: genreInfo("education"), settings, blocks, fallbackVoice: "/api/files/uploads/demo-voice.wav" }, getModel);+ const models = resolveModels(settings, narrationText(blocks).length, getModel);+ return { graph, ...regeneratePlan(graph, { engine: settings.engine, joinMax: models.joinMax, lookup: getModel }) };+}++describe("finishing passes (shared)", () => {+ it("runs RIFE first only for clips slower than 24 fps, and refuses a pass over 15 s", () => {+ expect(needsSmoothing(16)).toBe(true);+ expect(needsSmoothing(24)).toBe(false);+ expect(needsSmoothing(30)).toBe(false);+ expect(needsSmoothing(undefined)).toBe(false);+ expect(sixteenFpsModel("oss-wan22-14b-fast")).toBe(true);+ expect(sixteenFpsModel("oss-minimax-h3")).toBe(false);+ expect(finishLengthProblem(15)).toBeNull();+ expect(finishLengthProblem(15.4)).toMatch(/up to 15 s in one pass/);+ const helper = { feature: "shorts-step", batchTitle: "A short" };+ const slow = regenFinishSteps({ key: "s0", clip: { key: "look" }, prompt: "A comic-book city at night", seconds: 5.06, fps: 16, draftFrom: "other", helper, label: "Segment 1" });+ expect(slow.steps.map((s) => [s.key, s.request.modelId, s.after, s.chain])).toEqual([+ ["s0-smooth", REGEN_SMOOTH_MODEL, ["look"], [{ slot: "video" }]],+ ["s0-regen", REGEN_MODEL, ["s0-smooth"], [{ slot: "video" }]],+ ]);+ expect(slow.steps[0].request).toMatchObject({ op: "interpolate", params: { targetFps: 24 } });+ expect(slow.final).toBe("s0-regen");+ expect(slow.steps[1].request).toMatchObject({ op: "upscale-video", prompt: "A comic-book city at night", params: { resolution: "1080p", sourceDuration: 5.06, extra: { startSigma: REGEN_FINISH_SIGMA, draftFrom: "other" } } });+ // A stored clip at 24 fps: one pass on the file itself.+ const file = regenFinishSteps({ key: "e", clip: { url: "/api/files/uploads/a.mp4" }, prompt: "x", seconds: 4, fps: 24, draftFrom: "h3", helper, label: "Edit" });+ expect(file.steps).toHaveLength(1);+ expect(file.steps[0]).toMatchObject({ key: "e-regen", request: { inputs: { video: "/api/files/uploads/a.mp4" }, params: { extra: { draftFrom: "h3" } } } });+ expect(file.steps[0].after).toBeUndefined();+ expect(() => regenFinishSteps({ key: "x", clip: { key: "k" }, prompt: "x", seconds: 20, draftFrom: "other", helper, label: "Long" })).toThrow(/15 s/);+ });+});++describe("Faceless · Regenerate to 1080p", () => {+ it("is offered on the open engine only (the cloud keeps its SeedVR upscale)", () => {+ expect(ENGINE_MODELS.open.regenerate).toBe(REGEN_MODEL);+ expect(ENGINE_MODELS.cloud.regenerate).toBeUndefined();+ expect(ENGINE_MODELS.cloud.upscale).toBe("seedvr-video");+ expect(ENGINE_MODELS.open.upscale).toBe("oss-upscale-video-esrgan");+ expect(() => plan({ engine: "cloud" }, [block(1), block(2)])).toThrow(/runs on your GPU/);+ });++ it("redraws each scene from its own words at 1080p (576p preset, sigma 0.8), then joins and mixes again", () => {+ const blocks = [block(1), block(2), block(3), block(4), block(5)];+ const { graph, steps, final } = plan({ engine: "open", videoModel: "oss-minimax-h3", animation: "animated" }, blocks);+ const clips = graph.filter((s) => s.part === "clip");+ const regens = steps.filter((s) => s.request.modelId === REGEN_MODEL);+ expect(regens).toHaveLength(clips.length);+ // H3 clips are 24 fps: no RIFE.+ expect(steps.some((s) => s.request.modelId === REGEN_SMOOTH_MODEL)).toBe(false);+ for (const [i, r] of regens.entries()) {+ const c = clips[i];+ expect(r.after).toEqual([c.key]);+ expect(r.request.params).toMatchObject({ resolution: "1080p", extra: { startSigma: 0.8, draftFrom: "other" } });+ expect(r.request.params?.sourceDuration).toBeLessThanOrEqual(15);+ // The scene's own words: its picture's prompt and its motion.+ const still = graph.find((s) => s.key === c.after![0])!;+ expect(r.request.prompt).toContain(still.request.prompt!.slice(0, 40));+ expect(r.request.prompt).toContain(c.request.prompt!.slice(0, 20));+ }+ // MiniMax H3 scenes join packet by packet (every redrawn clip has the same size and rate), as the episode does.+ const joins = steps.filter((s) => s.request.op === "concat");+ expect(joins.map((j) => [j.key, j.request.modelId])).toEqual([[`${REGEN_PREFIX}join`, graph.find((s) => s.key === "join")!.request.modelId]]);+ expect(joins[0].after).toEqual(regens.map((r) => r.key));+ // The same narration, bed and subtitles go back on.+ const mix = steps.find((s) => s.key === `${REGEN_PREFIX}mix`)!;+ expect(mix.after![0]).toBe(`${REGEN_PREFIX}join`);+ expect(mix.after!.slice(1)).toEqual(graph.find((s) => s.key === "mix")!.after!.slice(1));+ expect(final).toBe(`${REGEN_PREFIX}captions`);+ expect(steps.find((s) => s.key === final)!.after).toEqual([`${REGEN_PREFIX}mix`, "words"]);+ expect(regenerateReuses(steps).sort()).toEqual([...clips.map((c) => c.key), "narration", "words", ...(graph.some((s) => s.key === "music") ? ["music"] : [])].sort());+ });++ it("brings Wan's 16 fps scenes to 24 fps with RIFE first, and folds the joins at 1080p", () => {+ const { steps, graph } = plan({ engine: "open", videoModel: "oss-wan22-14b-fast", animation: "animated" }, [block(1, 5), block(2, 5), block(3, 5), block(4, 5), block(5, 5)]);+ const clips = graph.filter((s) => s.part === "clip");+ const smooth = steps.filter((s) => s.request.modelId === REGEN_SMOOTH_MODEL);+ expect(smooth).toHaveLength(clips.length);+ expect(smooth[0].after).toEqual([clips[0].key]);+ expect(steps.find((s) => s.key === `${REGEN_PREFIX}${clips[0].key}-regen`)!.after).toEqual([smooth[0].key]);+ // The episode's join takes four clips at a time; the redrawn film folds the same way, at 1080p.+ const joins = steps.filter((s) => s.request.op === "concat");+ expect(joins.map((j) => j.key)).toEqual(graph.filter((s) => s.part === "join").map((j) => `${REGEN_PREFIX}${j.key}`));+ expect(joins.length).toBeGreaterThan(1);+ for (const j of joins) expect(j.request.params?.resolution).toBe("1080p");+ });++ it("keeps one scene unjoined and mixes it straight", () => {+ const { steps } = plan({ engine: "open", videoModel: "oss-minimax-h3", animation: "animated", subtitles: false }, [block(1, 8)]);+ expect(steps.some((s) => s.request.op === "concat")).toBe(false);+ const mix = steps.find((s) => s.key === `${REGEN_PREFIX}mix`)!;+ expect(mix.after![0]).toMatch(/-regen$/);+ expect(mix.request.title).toBe("Lighthouses · 1080p");+ });+});