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.

Mixed Media: Per frame or Fast on the cloud, the price per frame before you render, and frame-by-frame progress

Claude62ddeaa31f97
diff --git a/src/app/(studio)/mixed-media/page.tsx b/src/app/(studio)/mixed-media/page.tsx
index 14d96c95..ef092228 100644
--- a/src/app/(studio)/mixed-media/page.tsx
+++ b/src/app/(studio)/mixed-media/page.tsx
@@ -1,13 +1,15 @@
import type { Metadata } from "next";
import { MixedStudio } from "@/components/mixed-media/mixed-studio";
-import { MIXED_MODELS } from "@/lib/catalog/mixed-media";
+import { MIXED_FRAME_MODELS, MIXED_MODELS } from "@/lib/catalog/mixed-media";
import { modelInfos } from "@/lib/catalog/shorts-models";
export const metadata: Metadata = { title: "Mixed Media" };
-/** The restyle models per engine, slimmed on the server so the page ships no catalog. */
+/** The restyle models per engine (cloud: Fast), slimmed on the server so the page ships no catalog. */
const MODELS = { cloud: modelInfos(MIXED_MODELS.cloud), open: modelInfos(MIXED_MODELS.open) };
+/** The cloud image editors that redraw each frame (Per frame). */
+const FRAME_MODELS = modelInfos([...MIXED_FRAME_MODELS]);
export default function Page() {
- return <MixedStudio models={MODELS} />;
+ return <MixedStudio models={MODELS} frameModels={FRAME_MODELS} />;
}
diff --git a/src/app/api/mixed-media/progress/route.ts b/src/app/api/mixed-media/progress/route.ts
new file mode 100644
index 00000000..4cdfcddd
--- /dev/null
+++ b/src/app/api/mixed-media/progress/route.ts
@@ -0,0 +1,11 @@
+import { framesProgress } from "@/server/mixed-media";
+import { handle } from "@/server/shorts-schemas";
+
+/** How far a per-frame render's frame edits are (?batch=<the render's batch id>): counts, and the first frame that failed. */
+export async function GET(request: Request) {
+ return handle(() => {
+ const batch = new URL(request.url).searchParams.get("batch")?.trim() ?? "";
+ if (!batch || batch.length > 64) return Response.json({ error: "Which render?" }, { status: 400 });
+ return Response.json(framesProgress(batch));
+ });
+}
diff --git a/src/components/mixed-media/history.tsx b/src/components/mixed-media/history.tsx
index 23bfe04e..6997e370 100644
--- a/src/components/mixed-media/history.tsx
+++ b/src/components/mixed-media/history.tsx
@@ -14,7 +14,7 @@ import { chainState } from "@/lib/catalog/shorts";
import type { Generation } from "@/lib/catalog/types";
import { timeAgo } from "@/lib/format";
import { downloadHref, downloadName, userTitle } from "@/lib/library";
-import { renderSteps, useMixedActions } from "./hooks";
+import { isFrameRender, renderSteps, useFramesProgress, useMixedActions } from "./hooks";
/** The finished videos and their helper steps (a failed render shows the failing step's own error). */
const FILTER = { features: [MIXED_FEATURE, MIXED_STEP_FEATURE], limit: 150 };
@@ -85,8 +85,14 @@ export function MixedHistory({ onStart }: { onStart: () => void }) {
<PendingTile g={state.status === "working" ? (chain.find((x) => x.status !== "succeeded") ?? g) : g} ratio={1} />
) : (
<div className="flex size-full flex-col justify-center gap-1 border border-dashed p-3">
- <p className="text-[13px] font-medium">{heading}</p>
- {reason && reason !== heading && <p className="line-clamp-4 text-[12px] break-words text-muted-foreground">{reason}</p>}
+ {g.status !== "canceled" && isFrameRender(chain) && g.batchId ? (
+ <FrameFailure batchId={g.batchId} heading={heading} reason={reason} />
+ ) : (
+ <>
+ <p className="text-[13px] font-medium">{heading}</p>
+ {reason && reason !== heading && <p className="line-clamp-4 text-[12px] break-words text-muted-foreground">{reason}</p>}
+ </>
+ )}
<button
type="button"
onClick={() => retry(g.id)}
@@ -117,3 +123,16 @@ export function MixedHistory({ onStart }: { onStart: () => void }) {
</>
);
}
+
+/** A per-frame render that failed: the frame that failed and why (the steps after it only say an earlier step didn't finish). */
+function FrameFailure({ batchId, heading, reason }: { batchId: string; heading: string; reason?: string | null }) {
+ const failed = useFramesProgress(batchId, false).data?.failed;
+ const title = failed ? `${failed.label} failed` : heading;
+ const why = failed?.error ?? reason;
+ return (
+ <>
+ <p className="text-[13px] font-medium">{title}</p>
+ {why && why !== title && <p className="line-clamp-4 text-[12px] break-words text-muted-foreground">{why}</p>}
+ </>
+ );
+}
diff --git a/src/components/mixed-media/hooks.ts b/src/components/mixed-media/hooks.ts
index bfa590f1..528f9040 100644
--- a/src/components/mixed-media/hooks.ts
+++ b/src/components/mixed-media/hooks.ts
@@ -2,7 +2,7 @@
import { keepPreviousData, useMutation, useQueries, useQuery, useQueryClient } from "@tanstack/react-query";
import { useDeferredValue } from "react";
-import type { MixedResolution, MixedValues } from "@/lib/catalog/mixed-media";
+import type { MixedMode, MixedResolution, MixedValues } from "@/lib/catalog/mixed-media";
import type { Engine, Generation } from "@/lib/catalog/types";
import { useGenerationEvents } from "@/lib/api";
import { send } from "@/components/shorts/hooks";
@@ -18,6 +18,8 @@ export interface MixedBody {
fps: number;
resolution: MixedResolution;
modelId?: string;
+ /** Cloud: frame by frame (default) or Fast. */
+ mode?: MixedMode;
anchor?: string;
frameUrl?: string;
/** Client nonce: a repeat of it gets the first answer (see useSubmitGuard). */
@@ -29,10 +31,31 @@ export interface MixedEstimate {
previewUsd: number | null;
demo: boolean;
frames: number;
+ /** The rate frames are taken at (cloud Per frame: the clip's own over a whole number). */
fps: number;
+ mode?: MixedMode;
+ /** Cloud Per frame: what one redrawn frame costs. */
+ perFrameUsd?: number | null;
notes: string[];
}
+export interface FramesProgress {
+ total: number;
+ done: number;
+ running: number;
+ failed?: { label: string; error: string };
+}
+
+/** A per-frame render's frame edits (counts and the first failure), polled while `live`; read once otherwise. */
+export function useFramesProgress(batchId: string | null | undefined, live: boolean) {
+ return useQuery({
+ queryKey: ["mixed-media", "frames", batchId],
+ queryFn: async () => send<FramesProgress>(`/api/mixed-media/progress?batch=${encodeURIComponent(batchId!)}`, "GET"),
+ enabled: !!batchId,
+ refetchInterval: live ? 2000 : false,
+ });
+}
+
export function useMixedEstimate(body: MixedBody | null) {
const key = useDeferredValue(body ? JSON.stringify(body) : null);
return useQuery({
@@ -77,20 +100,38 @@ export function useWatchedChain(ids: string[]): (Generation | undefined)[] {
}).map((q) => q.data);
}
+/** What a step of a render is doing (a per-frame render's assembly waits while the frames are redrawn). */
+function stepLabel(g: Generation): string {
+ switch (g.op) {
+ case "trim":
+ return "Cutting the clip";
+ case "mux":
+ return "Putting the sound back";
+ case "extract-frames":
+ return "Taking the frames";
+ case "images-to-video":
+ return g.status === "queued" && !g.progress ? "Redrawing the frames" : "Putting the frames together";
+ case "concat":
+ return "Joining the clips";
+ default:
+ return "Restyling";
+ }
+}
+
/** What each step of a render is doing, for chainState(). */
export function renderSteps(chain: (Generation | undefined)[]): { g?: Generation; label: string }[] {
- return chain.map((g) => ({
- g,
- label: !g ? "A step" : g.op === "trim" ? "Cutting the clip" : g.op === "mux" ? "Putting the sound back" : "Restyling",
- }));
+ return chain.map((g) => ({ g, label: g ? stepLabel(g) : "A step" }));
}
+/** A per-frame render (its frames were taken by an extract step). */
+export const isFrameRender = (chain: (Generation | undefined)[]) => chain.some((g) => g?.op === "extract-frames");
+
export function useMixedActions() {
const qc = useQueryClient();
const seed = (g: Generation) => qc.setQueryData(["mixed-media", "generation", g.id], g);
return {
render: useMutation({
- mutationFn: (b: MixedBody) => send<{ final: Generation; items: Generation[] }>("/api/mixed-media", "POST", b),
+ mutationFn: (b: MixedBody) => send<{ final: Generation; items: Generation[]; frames?: number }>("/api/mixed-media", "POST", b),
onSuccess: (r) => {
r.items.forEach(seed);
void qc.invalidateQueries({ queryKey: ["generations"] });
@@ -102,7 +143,7 @@ export function useMixedActions() {
}),
/** Run a finished-or-failed render again with the same settings (History's "Try again"). */
retry: useMutation({
- mutationFn: (v: { id: string; requestId?: string }) => send<{ final: Generation; items: Generation[] }>("/api/mixed-media/retry", "POST", v),
+ mutationFn: (v: { id: string; requestId?: string }) => send<{ final: Generation; items: Generation[]; frames?: number }>("/api/mixed-media/retry", "POST", v),
onSuccess: (r) => {
r.items.forEach(seed);
void qc.invalidateQueries({ queryKey: ["generations"] });
diff --git a/src/components/mixed-media/mixed-studio.tsx b/src/components/mixed-media/mixed-studio.tsx
index 2823a071..31ef2219 100644
--- a/src/components/mixed-media/mixed-studio.tsx
+++ b/src/components/mixed-media/mixed-studio.tsx
@@ -23,6 +23,7 @@ import {
mixedPreview,
mixedRangeProblem,
nearestResolution,
+ type MixedMode,
type MixedPreset,
type MixedResolution,
type MixedValues,
@@ -34,7 +35,7 @@ import { downloadHref, downloadName } from "@/lib/library";
import type { TrimRange } from "@/lib/trim-range";
import { cn } from "@/lib/utils";
import { MixedHistory } from "./history";
-import { renderSteps, useMixedActions, useMixedEstimate, useWatchedChain, useWatchedGeneration, type MixedBody } from "./hooks";
+import { isFrameRender, renderSteps, useFramesProgress, useMixedActions, useMixedEstimate, useWatchedChain, useWatchedGeneration, type MixedBody } from "./hooks";
import { AdvancedSettings, loadSaved } from "./settings";
type Tab = "presets" | "history" | "how";
@@ -48,11 +49,11 @@ const HOW = [
{ step: "Choose a preset", text: "Browse 33 mixed-media looks — sketch, comic, paper, neon, marble — and pick the one that fits your clip." },
{ step: "Upload your video", text: "Add a clip and trim it to up to 10 seconds. It needs at least 4 frames per second." },
{ step: "Customize settings", text: "Each preset has its own colours, materials and intensity. Save them per preset; they stay in this browser." },
- { step: "Generate & preview", text: "Make one preview frame first to check the look, then render the whole video. The open engine restyles it frame by frame at the rate you pick; cloud models restyle it as smooth video." },
+ { step: "Generate & preview", text: "Make one preview frame first to check the look, then render the whole video, frame by frame at the rate you pick. On the cloud, Fast restyles it in one video-to-video pass instead." },
];
/** Mixed Media: pick a look, add a ≤10 s clip, tune the settings, preview one frame, render. */
-export function MixedStudio({ models }: { models: Record<Engine, RestyleModelInfo[]> }) {
+export function MixedStudio({ models, frameModels }: { models: Record<Engine, RestyleModelInfo[]>; frameModels: RestyleModelInfo[] }) {
const [tab, setTab] = useState<Tab>("presets");
const [engine, setEngine] = useEngine();
useEffect(() => {
@@ -102,10 +103,10 @@ export function MixedStudio({ models }: { models: Record<Engine, RestyleModelInf
<p className="text-[12px] font-semibold tracking-[0.14em] text-brand-text uppercase">No prompts, just vibe</p>
<h2 className="mt-2 font-heading text-display text-balance">Turn any video into mixed-media art</h2>
<p className="mx-auto mt-2 max-w-[560px] text-body text-pretty text-muted-foreground">
- 33 looks, each with its own colours and materials. Preview one frame first, then render the clip — frame by frame at the rate you choose on the open engine.
+ 33 looks, each with its own colours and materials. Preview one frame first, then render the clip frame by frame at the rate you choose.
</p>
</div>
- <Workspace engine={engine} models={models[engine]} />
+ <Workspace engine={engine} models={models[engine]} frameModels={frameModels} />
</>
)}
</div>
@@ -129,8 +130,9 @@ function How({ onStart }: { onStart: () => void }) {
<div className="mt-6 rounded-2xl bg-muted/60 p-5 text-[13px] text-muted-foreground">
<p className="font-medium text-foreground">Cost</p>
<p className="mt-1">
- On the open engine a render is counted in frames: seconds × frame rate, rounded down (10 s at 8 FPS = 80 frames), and every frame runs on your GPU for free.
- Cloud models restyle the clip as video and are priced by the model (per second or per video); the estimate shows before you generate.
+ A render is counted in frames: seconds × frame rate, rounded down (10 s at 8 FPS = 80 frames). On the open engine every frame runs on your GPU for free; on the
+ cloud each frame is redrawn by an image model and priced per frame (Nano Banana 2 or Seedream 5.0 Flash). Fast restyles the clip in one video-to-video pass,
+ priced by the model. The estimate shows before you generate.
</p>
</div>
<div className="mt-6 text-center">
@@ -142,7 +144,7 @@ function How({ onStart }: { onStart: () => void }) {
);
}
-function Workspace({ engine, models }: { engine: Engine; models: RestyleModelInfo[] }) {
+function Workspace({ engine, models, frameModels }: { engine: Engine; models: RestyleModelInfo[]; frameModels: RestyleModelInfo[] }) {
const [presetId, setPresetId] = useState<string | null>(null);
const preset = MIXED_PRESETS.find((p) => p.id === presetId) ?? null;
const [values, setValues] = useState<MixedValues>({});
@@ -218,7 +220,7 @@ function Workspace({ engine, models }: { engine: Engine; models: RestyleModelInf
)}
</section>
<aside ref={panel} id="mm-editor" className="scrollbar-none min-w-0 scroll-mt-16 lg:sticky lg:top-16 lg:max-h-[calc(100svh-4.5rem)] lg:overflow-y-auto lg:overscroll-contain lg:rounded-2xl">
- <Editor engine={engine} models={models} preset={preset} values={values} setValues={setValues} />
+ <Editor engine={engine} models={models} frameModels={frameModels} preset={preset} values={values} setValues={setValues} />
</aside>
{preset && !panelVisible && (
<div className="fixed inset-x-3 bottom-[max(0.75rem,env(safe-area-inset-bottom))] z-30 lg:hidden">
@@ -244,13 +246,15 @@ type FpsChoice = number | "manual";
function Editor({
engine,
- models,
+ models: restyleModels,
+ frameModels,
preset,
values,
setValues,
}: {
engine: Engine;
models: RestyleModelInfo[];
+ frameModels: RestyleModelInfo[];
preset: MixedPreset | null;
values: MixedValues;
setValues: (v: MixedValues) => void;
@@ -269,12 +273,19 @@ function Editor({
const [fpsChoice, setFpsChoice] = useState<FpsChoice>(MIXED.defaultFps as number);
const [manual, setManual] = useState<number>(MIXED.defaultFps);
const [resolution, setResolution] = useState<MixedResolution>("1K");
- const [pickedModel, setModel] = useState<Record<Engine, string>>({ cloud: "", open: "" });
- const modelId = pickedModel[engine] || models[0]?.id;
+ // Cloud: frame by frame (the default, priced per frame) or Fast (one video-to-video pass).
+ const [mode, setMode] = useState<MixedMode>("frames");
+ const cloud = engine === "cloud";
+ const frameMode = cloud && mode === "frames";
+ const models = frameMode ? frameModels : restyleModels;
+ const slot = frameMode ? "frames" : engine;
+ const [pickedModel, setModel] = useState<Record<Engine | "frames", string>>({ cloud: "", open: "", frames: "" });
+ const modelId = pickedModel[slot] || models[0]?.id;
const model = models.find((m) => m.id === modelId);
const [previewId, setPreviewId] = useState<string | null>(null);
- // Every step of the latest render (cut → restyle → sound), so a failed step shows its own error.
+ // Every main step of the latest render (cut → frames or restyle → sound), so a failed step shows its own error.
const [renderIds, setRenderIds] = useState<string[]>([]);
+ const [renderFrames, setRenderFrames] = useState(0);
const [anchorOff, setAnchorOff] = useState(false);
const [grabbing, setGrabbing] = useState(false);
const actions = useMixedActions();
@@ -292,20 +303,25 @@ function Editor({
const seconds = mmRange ? mmRange.end - mmRange.start : 0;
const problem = mmRange ? mixedRangeProblem(mmRange, duration, sourceFps) : null;
const frames = mmRange ? mixedFrames(seconds, fps) : 0;
- // Cloud models restyle the cut as video: the frame rate is the open engine's, and the resolution
- // is the model's own setting nearest to 1K / 2K / 4K (choices that land on the same one are off).
- const cloud = engine === "cloud";
- const lengthIssue = (m: RestyleModelInfo) => (cloud && seconds ? clipLengthProblem(m, seconds) : null);
+ // Fast restyles the cut as video: the resolution is the model's own setting nearest to 1K / 2K / 4K
+ // (choices that land on the same one are off). Per frame draws each frame at 1K–4K (Seedream up to 2K).
+ const fast = cloud && !frameMode;
+ const lengthIssue = (m: RestyleModelInfo) => (fast && seconds ? clipLengthProblem(m, seconds) : null);
const resOptions = MIXED.resolutions.map((r, i) => {
- const at = cloud ? nearestResolution(model?.resolutions, r) : undefined;
- const prev = i > 0 && cloud ? nearestResolution(model?.resolutions, MIXED.resolutions[i - 1]) : undefined;
- return { value: r, label: r, hint: at, disabled: cloud && !!at && at === prev, title: cloud && at === prev ? `${model?.name} renders up to ${at}` : at };
+ if (frameMode) {
+ const capped = r === "4K" && modelId === "seedream-5-flash";
+ return { value: r, label: r, hint: undefined, disabled: capped, title: capped ? `${model?.name} draws frames up to 2K` : `Each frame at ${r}` };
+ }
+ const at = fast ? nearestResolution(model?.resolutions, r) : undefined;
+ const prev = i > 0 && fast ? nearestResolution(model?.resolutions, MIXED.resolutions[i - 1]) : undefined;
+ return { value: r, label: r, hint: at, disabled: fast && !!at && at === prev, title: fast && at === prev ? `${model?.name} renders up to ${at}` : at };
});
- const showResolution = !cloud || resOptions.some((o) => o.hint && !o.disabled && o.value !== "1K");
+ const showResolution = !fast || resOptions.some((o) => o.hint && !o.disabled && o.value !== "1K");
const resShown: MixedResolution = resOptions.find((o) => o.value === resolution)?.disabled ? ([...resOptions].reverse().find((o) => !o.disabled)?.value ?? "1K") : resolution;
- const modelRes = cloud ? nearestResolution(model?.resolutions, resShown) : undefined;
+ const modelRes = fast ? nearestResolution(model?.resolutions, resShown) : undefined;
const previewImage = preview?.status === "succeeded" ? preview.outputs.find((o) => o.kind === "image") : undefined;
- const anchor = engine === "cloud" && model?.image && previewImage && !anchorOff ? previewImage.url : undefined;
+ // Per frame always starts from the approved preview; Fast only when the model takes a still.
+ const anchor = cloud && (frameMode || model?.image) && previewImage && !anchorOff ? previewImage.url : undefined;
const body: MixedBody | null =
preset && mmRange && !problem
@@ -318,14 +334,15 @@ function Editor({
fps,
resolution: resShown,
modelId,
+ ...(cloud ? { mode } : {}),
...(anchor ? { anchor } : {}),
}
: null;
const estimate = useMixedEstimate(body);
const est = estimate.data;
- // A new clip, preset or engine starts without a preview.
- const key = `${preset?.id}|${clip?.preview}|${engine}`;
+ // A new clip, preset or engine starts without a preview (and so does another frame editor: the preview is its own work).
+ const key = `${preset?.id}|${clip?.preview}|${engine}|${frameMode ? modelId : ""}`;
const [lastKey, setLastKey] = useState(key);
if (key !== lastKey) {
setLastKey(key);
@@ -385,6 +402,7 @@ function Editor({
.then((r) => {
if (!r) return;
setRenderIds(r.items.map((g) => g.id));
+ setRenderFrames(r.frames ?? 0);
toast("Rendering your video", { description: "It shows up in History too." });
})
.catch((e: Error) => toast.error(e.message));
@@ -442,7 +460,21 @@ function Editor({
)}
</Field>
- {!cloud && (
+ {cloud && (
+ <Field label="Restyle" hint={frameMode ? "Every frame redrawn · priced per frame" : "One video-to-video pass · priced by the model"}>
+ <Segmented<MixedMode>
+ label="Restyle"
+ value={mode}
+ onChange={setMode}
+ options={[
+ { value: "frames", label: "Per frame", title: "Each frame is redrawn by an image model, looking at the frame before it" },
+ { value: "fast", label: "Fast", title: "A video model restyles the whole clip in one pass" },
+ ]}
+ />
+ </Field>
+ )}
+
+ {(!cloud || frameMode) && (
<Field label="Frame rate" hint={sourceFps ? `Uploaded video has ${Math.round(sourceFps)} FPS` : "8 FPS is the classic stop-motion look"}>
<Segmented<FpsChoice>
label="Frame rate"
@@ -551,7 +583,7 @@ function Editor({
)}
{anchor && (
<p className="flex items-center gap-1.5 text-[12px] text-brand-text">
- <Wand2 className="size-3.5 shrink-0" /> {model?.name} follows this frame for the whole video
+ <Wand2 className="size-3.5 shrink-0" /> {frameMode ? "Every frame is matched to this one" : `${model?.name} follows this frame for the whole video`}
<button type="button" onClick={() => setAnchorOff(true)} className="ml-auto text-muted-foreground underline-offset-2 hover:underline">
Don&apos;t use it
</button>
@@ -575,13 +607,18 @@ function Editor({
<div className="space-y-3 border-t pt-4">
<div className="flex items-baseline justify-between gap-2">
<span className="text-[13px] text-muted-foreground">
- {!mmRange ? "Estimate" : cloud ? `${seconds.toFixed(1)} s${modelRes ? ` · ${modelRes}` : ""}` : `${frames} frames · ${fps} FPS`}
+ {!mmRange ? "Estimate" : fast ? `${seconds.toFixed(1)} s${modelRes ? ` · ${modelRes}` : ""}` : `${est?.frames ?? frames} frames · ${+(est?.fps ?? fps).toFixed(2)} FPS`}
</span>
<span className="flex items-center gap-1.5 font-mono text-[13px] font-medium tabular-nums" aria-live="polite">
{estimate.isFetching && <Loader2 className="size-3 animate-spin text-muted-foreground" />}
{body ? costText(est, engine) : "—"}
</span>
</div>
+ {frameMode && est && !est.demo && typeof est.perFrameUsd === "number" && (
+ <p className="text-[12px] text-muted-foreground tabular-nums">
+ {est.frames} frames × ${est.perFrameUsd.toFixed(3).replace(/0$/, "")} a frame ({model?.name}), plus a few cents to cut and rebuild the clip
+ </p>
+ )}
{clip?.url && !clip.uploading && !clip.error && clip.info && clip.info.hasAudio === undefined && (
<p className="flex gap-1.5 text-[12px] leading-snug text-muted-foreground">
<Info className="mt-0.5 size-3.5 shrink-0" />
@@ -613,17 +650,28 @@ function Editor({
{blocker}
</p>
)}
- {render.length > 0 && <LatestRender chain={render} />}
+ {render.length > 0 && <LatestRender chain={render} frames={renderFrames} />}
</div>
</div>
);
}
-/** The latest render: its steps' progress, the failing step's own error, or the video. */
-function LatestRender({ chain }: { chain: (Generation | undefined)[] }) {
+/** The latest render: its steps' progress (a per-frame render counts its frames), the failing step's own error, or the video. */
+function LatestRender({ chain, frames }: { chain: (Generation | undefined)[]; frames: number }) {
const g = chain[chain.length - 1];
// Steps still loading read as working, not as deleted.
- const state = chain.some((x) => !x) ? ({ status: "working", label: "Rendering", progress: 0 } as const) : chainState(renderSteps(chain));
+ const steps = chain.some((x) => !x) ? null : chainState(renderSteps(chain));
+ const perFrame = frames > 0 && isFrameRender(chain);
+ const redrawing = perFrame && steps?.status === "working" && steps.label === "Redrawing the frames";
+ const progress = useFramesProgress(perFrame ? g?.batchId : null, redrawing || steps?.status === "failed").data;
+ let state = steps ?? ({ status: "working", label: "Rendering", progress: 0 } as const);
+ if (redrawing && progress?.total) {
+ // The frames are most of the work: show them as the bar between taking and rebuilding them.
+ const at = chain.findIndex((x) => x?.op === "images-to-video");
+ state = { ...state, label: `Redrawing frames · ${progress.done} of ${progress.total}`, progress: (at + progress.done / progress.total) / chain.length };
+ }
+ // A frame that failed: say which and why (the steps after it only say an earlier step didn't finish).
+ if (state.status === "failed" && progress?.failed) state = { ...state, label: `${progress.failed.label} failed`, error: progress.failed.error };
const out = g?.status === "succeeded" ? g.outputs.find((o) => o.kind === "video") : undefined;
return (
<div className="space-y-2 rounded-xl bg-muted/50 p-3" aria-live="polite">
diff --git a/src/server/mixed-media.ts b/src/server/mixed-media.ts
index 99c34bdd..449c4cb6 100644
--- a/src/server/mixed-media.ts
+++ b/src/server/mixed-media.ts
@@ -218,6 +218,31 @@ export function retryMixed(id: string): { final: Generation; items: Generation[]
return { final: p.byKey[id], ...followed(p) };
}
+export interface FramesProgress {
+ /** Frame edits in the render. */
+ total: number;
+ done: number;
+ running: number;
+ /** The first frame that failed or was canceled, with its own error (the steps after it only say an earlier step didn't finish). */
+ failed?: { label: string; error: string };
+}
+
+/** A per-frame render's frame edits at a glance (the page follows the main steps, not hundreds of frames). */
+export function framesProgress(batchId: string): FramesProgress {
+ const rows = db().prepare("SELECT status, COUNT(*) AS n FROM generations WHERE batch_id = ? AND feature = ? GROUP BY status").all(batchId, MIXED_FRAME_FEATURE) as { status: string; n: number }[];
+ const count = (...s: string[]) => rows.filter((r) => s.includes(r.status)).reduce((a, r) => a + r.n, 0);
+ const out: FramesProgress = { total: count("queued", "running", "succeeded", "failed", "canceled"), done: count("succeeded"), running: count("running") };
+ if (count("failed", "canceled")) {
+ // The first one to fail, not the frames after it that only waited for it.
+ const bad = db()
+ .prepare("SELECT status, error, request_json FROM generations WHERE batch_id = ? AND feature = ? AND status IN ('failed', 'canceled') ORDER BY (error LIKE '%earlier step%') ASC, created_at ASC LIMIT 1")
+ .get(batchId, MIXED_FRAME_FEATURE) as { status: string; error: string | null; request_json: string };
+ const label = (JSON.parse(bad.request_json) as { step?: { label?: string } }).step?.label ?? "A frame";
+ out.failed = { label, error: bad.status === "canceled" ? "Canceled" : (bad.error ?? "Something went wrong") };
+ }
+ return out;
+}
+
/** One frame with the current settings. */
export async function createMixedPreview(body: MixedBody): Promise<Generation> {
const { input } = await planInput(body, { probe: true });
diff --git a/tests/shorts-api.test.ts b/tests/shorts-api.test.ts
index 43c1ce25..ed2e1003 100644
--- a/tests/shorts-api.test.ts
+++ b/tests/shorts-api.test.ts
@@ -28,6 +28,7 @@ const mixedRoute = await import("@/app/api/mixed-media/route");
const mixedPreviewRoute = await import("@/app/api/mixed-media/preview/route");
const mixedEstimateRoute = await import("@/app/api/mixed-media/estimate/route");
const mixedRetryRoute = await import("@/app/api/mixed-media/retry/route");
+const mixedProgressRoute = await import("@/app/api/mixed-media/progress/route");
const json = (method: string, body?: unknown) =>
new Request("http://x/api", { method, headers: { "Content-Type": "application/json" }, body: body === undefined ? undefined : JSON.stringify(body) });
@@ -463,5 +464,17 @@ describe("Mixed Media renders", () => {
expect(redo.map((g) => g.request.chainFilled)).toEqual([undefined, undefined, undefined, undefined]);
expect(await settle(again.final.id)).toMatchObject({ status: "succeeded" });
expect(gens.getGeneration(redo[3].id)!.request.inputs?.images).toHaveLength(2);
+ expect(mixed.framesProgress(again.final.batchId)).toEqual({ total: 4, done: 4, running: 0 });
+ });
+
+ it("says which frame failed and why, not just that an earlier step didn't finish", async () => {
+ const { final } = await mixed.createMixed(mm({ engine: "cloud", range: { start: 1, end: 2 }, fps: 4 }) as never);
+ const edits = gens.listGenerations({ batchId: final.batchId!, features: ["mixed-media-frame-step"], limit: 50 }).sort((a, b) => a.request.step!.index - b.request.step!.index);
+ await gens.cancelGeneration(edits[1].id);
+ expect(await settle(final.id)).toMatchObject({ status: "failed" });
+ const res = await mixedProgressRoute.GET(new Request(`http://x/api/mixed-media/progress?batch=${final.batchId}`));
+ const progress = await res.json();
+ expect(progress).toMatchObject({ total: 4, failed: { label: "Frame 2 of 4", error: "Canceled" } });
+ expect((await mixedProgressRoute.GET(new Request("http://x/api/mixed-media/progress"))).status).toBe(400);
});
});