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
Captions: the style controls and preview follow what the chosen burner draws
Claudef3491c0730e9
diff --git a/src/components/captions/captions-studio.tsx b/src/components/captions/captions-studio.tsxindex c80038a2..b65b1918 100644--- a/src/components/captions/captions-studio.tsx+++ b/src/components/captions/captions-studio.tsx@@ -16,7 +16,24 @@ import { Panel, ToolHero, ToolShell } from "@/components/av/tool-shell";import { useGeneration } from "@/components/av/use-generation";import { useCreateGeneration, useEngine, useGenerations, useHydrated } from "@/lib/api";import { cueProblems } from "@/lib/av/cue-edit";-import { burnRequest, burnRouteFor, CAPTION_STYLES, OPEN_FONT_SIZE, previewText, styleById, transcribeRequest, usesCues, type CaptionLook, type CaptionPosition, type CaptionSize } from "@/lib/av/captions";+import {+ BURN_CAPS,+ burnNote,+ burnPricePerMinute,+ burnRequest,+ burnRouteFor,+ CAPTION_STYLES,+ lookFor,+ OPEN_FONT_SIZE,+ previewText,+ styleById,+ transcribeRequest,+ usesCues,+ type BurnRoute,+ type CaptionLook,+ type CaptionPosition,+ type CaptionSize,+} from "@/lib/av/captions";import { parseCues, toSrt, toVtt, type Cue } from "@/lib/cues";import { cn } from "@/lib/utils";@@ -145,7 +162,7 @@ function Editor({ video, restored, onReplace }: { video: SlotValue; restored: Saif (usesCues(route) && problems.length) return void toast(problems[0], { id: "captions-blocker" });let req;try {- req = burnRequest({ route, video: video.ref, cues, look, sourceLanguage: source });+ req = burnRequest({ route, video: video.ref, cues, look: lookFor(route, look), sourceLanguage: source });} catch (e) {return void toast((e as Error).message);}@@ -160,14 +177,14 @@ function Editor({ video, restored, onReplace }: { video: SlotValue; restored: Sareturn (<div className="grid gap-4 pt-4 lg:grid-cols-[minmax(0,6fr)_minmax(0,5fr)]"><div className="min-w-0 space-y-3 lg:sticky lg:top-20 lg:self-start">- <Preview video={video} cues={cues} look={look} player={player} onTime={setTime} onDuration={setDuration} />+ <Preview video={video} cues={cues} look={lookFor(route, look)} route={route} player={player} onTime={setTime} onDuration={setDuration} /><div className="flex flex-wrap items-center gap-1.5"><p className="min-w-0 flex-1 truncate text-[13px] text-muted-foreground">{video.name}</p><Button variant="ghost" size="sm" className="rounded-full" onClick={() => onReplace(null)}>Another video</Button></div>- <StylePanel look={look} onChange={setLook} />+ <StylePanel look={look} route={route} onChange={setLook} /></div><div className="min-w-0 space-y-3">@@ -226,8 +243,14 @@ function Editor({ video, restored, onReplace }: { video: SlotValue; restored: Sa<Panel title="Burn in">{engine === "cloud" && (<div role="radiogroup" aria-label="Burner" className="mb-3 grid gap-2 sm:grid-cols-2">- <RouteCard on={!quick} onClick={() => setQuick(false)} icon={<Flame className="size-4" />} title="Your lines" note="VEED Subtitles burns your edited lines in your style (≈ $0.10 per minute)." />- <RouteCard on={quick} onClick={() => setQuick(true)} icon={<Wand2 className="size-4" />} title="Quick karaoke" note="Auto Subtitle transcribes again and burns word-by-word captions — your edits aren't used." />+ <RouteCard+ on={!quick}+ onClick={() => setQuick(false)}+ icon={<Flame className="size-4" />}+ title="Your lines"+ note={`VEED Subtitles burns your edited lines in your style (≈ $${burnPricePerMinute("veed", look.style).toFixed(2)} per minute${burnPricePerMinute("veed", look.style) > 0.1 ? ` — ${styleById(look.style).name} is one of VEED's dynamic styles` : ""}).`}+ />+ <RouteCard on={quick} onClick={() => setQuick(true)} icon={<Wand2 className="size-4" />} title="Quick karaoke" note="Auto Subtitle transcribes again and burns word-by-word captions, the spoken word highlighted (≈ $0.03 per minute) — your edits aren't used." /></div>)}{engine === "open" && <p className="mb-3 text-[12px] text-muted-foreground">ComfyUI's caption burn-in draws your lines into the frames chunk by chunk and keeps the sound (CPU is fine, no model).</p>}@@ -266,6 +289,7 @@ function Preview({video,cues,look,+ route,player,onTime,onDuration,@@ -273,6 +297,7 @@ function Preview({video: SlotValue;cues: Cue[];look: CaptionLook;+ route: BurnRoute;player: React.RefObject<HTMLVideoElement | null>;onTime: (t: number) => void;onDuration: (t: number) => void;@@ -287,8 +312,10 @@ function Preview({return () => ro.disconnect();}, [player]);const style = styleById(look.style);- const shown = previewText(cues, t, look);+ const shown = previewText(cues, t, look, route);const color = look.color ?? style.color;+ // Only what this burner draws: no box on the open engine, no highlight where the spoken word isn't marked.+ const box = style.box && BURN_CAPS[route].box;const words = useMemo(() => shown?.text.split(" ") ?? [], [shown]);return (<div className="relative overflow-hidden rounded-2xl border bg-media">@@ -315,13 +342,13 @@ function Preview({className={cn("pointer-events-none absolute inset-x-[6%] flex justify-center text-center", look.position === "top" ? "top-[8%]" : look.position === "center" ? "top-1/2 -translate-y-1/2" : "bottom-[14%]")}><span- className={cn("leading-tight", style.box && "rounded-md bg-black/60 px-2 py-0.5")}+ className={cn("leading-tight", box && "rounded-md bg-black/60 px-2 py-0.5")}style={{fontFamily: `${style.font}, var(--font-sans), sans-serif`,fontWeight: style.weight,fontSize: Math.max(11, (h * OPEN_FONT_SIZE[look.size]) / 100),color,- textShadow: style.box ? undefined : "0 0 3px #000, 0 0 3px #000, 0 1px 2px #000",+ textShadow: box ? undefined : "0 0 3px #000, 0 0 3px #000, 0 1px 2px #000",}}>{words.map((w, i) => (@@ -344,8 +371,10 @@ const POSITIONS: { id: CaptionPosition; label: string }[] = [{ id: "bottom", label: "Bottom" },];-function StylePanel({ look, onChange }: { look: CaptionLook; onChange: (l: CaptionLook) => void }) {- const seg = (on: boolean) => cn("h-7 rounded-full px-3 text-[12px] font-medium transition", on ? "bg-background text-foreground shadow-soft" : "text-muted-foreground hover:text-foreground");+function StylePanel({ look, route, onChange }: { look: CaptionLook; route: BurnRoute; onChange: (l: CaptionLook) => void }) {+ const seg = (on: boolean) => cn("h-7 rounded-full px-3 text-[12px] font-medium transition disabled:pointer-events-none disabled:opacity-40", on ? "bg-background text-foreground shadow-soft" : "text-muted-foreground hover:text-foreground");+ const caps = BURN_CAPS[route];+ const position = lookFor(route, look).position;return (<Panel title="Style"><div role="radiogroup" aria-label="Caption style" className="grid grid-cols-3 gap-2 sm:grid-cols-6">@@ -358,10 +387,10 @@ function StylePanel({ look, onChange }: { look: CaptionLook; onChange: (l: CaptionClick={() => onChange({ ...look, style: s.id, color: undefined })}className={cn("flex flex-col items-center gap-1 rounded-xl border p-2 transition-colors", look.style === s.id ? "border-primary bg-brand-faint" : "hover:bg-accent")}>- <span className={cn("grid h-9 w-full place-items-center rounded-md bg-[oklch(0.3_0.02_260)] text-[13px] leading-none", s.box && "px-1")} style={{ fontWeight: s.weight, fontFamily: `${s.font}, var(--font-sans), sans-serif` }}>- <span className={cn(s.box && "rounded bg-black/70 px-1 py-0.5")} style={{ color: s.color, textShadow: s.box ? undefined : "0 0 2px #000" }}>+ <span aria-hidden className={cn("grid h-9 w-full place-items-center rounded-md bg-[oklch(0.3_0.02_260)] text-[13px] leading-none", s.box && caps.box && "px-1")} style={{ fontWeight: s.weight, fontFamily: `${s.font}, var(--font-sans), sans-serif` }}>+ <span className={cn(s.box && caps.box && "rounded bg-black/70 px-1 py-0.5")} style={{ color: s.color, textShadow: s.box && caps.box ? undefined : "0 0 2px #000" }}>{s.upper ? "AA" : "Aa"}- {s.karaoke && <span style={{ color: s.highlight }}>a</span>}+ {s.karaoke && <span style={caps.highlight !== "none" ? { color: s.highlight } : undefined}>a</span>}</span></span><span className="text-[11px] font-medium">{s.name}</span>@@ -369,24 +398,38 @@ function StylePanel({ look, onChange }: { look: CaptionLook; onChange: (l: Capti))}</div><div className="mt-3 flex flex-wrap items-center gap-x-4 gap-y-2">- <div className="flex items-center gap-2">- <span className="text-[12px] text-muted-foreground">Size</span>- <div role="radiogroup" aria-label="Size" className="inline-flex rounded-full bg-muted p-0.5">- {SIZES.map((s) => (- <button key={s} type="button" role="radio" aria-checked={look.size === s} onClick={() => onChange({ ...look, size: s })} className={seg(look.size === s)}>- {s}- </button>- ))}+ {caps.sizes && (+ <div className="flex items-center gap-2">+ <span className="text-[12px] text-muted-foreground">Size</span>+ <div role="radiogroup" aria-label="Size" className="inline-flex rounded-full bg-muted p-0.5">+ {SIZES.map((s) => (+ <button key={s} type="button" role="radio" aria-checked={look.size === s} onClick={() => onChange({ ...look, size: s })} className={seg(look.size === s)}>+ {s}+ </button>+ ))}+ </div></div>- </div>+ )}<div className="flex items-center gap-2"><span className="text-[12px] text-muted-foreground">Position</span><div role="radiogroup" aria-label="Position" className="inline-flex rounded-full bg-muted p-0.5">- {POSITIONS.map((p) => (- <button key={p.id} type="button" role="radio" aria-checked={look.position === p.id} onClick={() => onChange({ ...look, position: p.id })} className={seg(look.position === p.id)}>- {p.label}- </button>- ))}+ {POSITIONS.map((p) => {+ const can = caps.positions.includes(p.id);+ return (+ <button+ key={p.id}+ type="button"+ role="radio"+ aria-checked={position === p.id}+ disabled={!can}+ title={can ? undefined : "This burner draws at the top or the bottom"}+ onClick={() => onChange({ ...look, position: p.id })}+ className={seg(position === p.id)}+ >+ {p.label}+ </button>+ );+ })}</div></div><label className="flex items-center gap-2 text-[12px] text-muted-foreground">@@ -400,7 +443,7 @@ function StylePanel({ look, onChange }: { look: CaptionLook; onChange: (l: Capti/></label></div>- <p className="mt-3 text-[12px] text-muted-foreground">Karaoke styles show a few words at a time on the open engine and highlight the spoken word on the cloud. The open burner places text at the top or the bottom.</p>+ <p className="mt-3 text-[12px] text-muted-foreground">{burnNote(route)}</p></Panel>);}diff --git a/src/lib/av/captions.ts b/src/lib/av/captions.tsindex 390316fa..60cc81f6 100644--- a/src/lib/av/captions.ts+++ b/src/lib/av/captions.ts@@ -100,6 +100,47 @@ export const burnRouteFor = (engine: Engine, quick: boolean): BurnRoute => (engi/** Whether a route burns your edited lines (Auto Subtitle transcribes again by itself). */export const usesCues = (route: BurnRoute) => route !== "auto";+/** What each burner can draw, so the controls and the live preview promise only that. */+export interface BurnCaps {+ positions: CaptionPosition[];+ /** S / M / L reaches the burner (VEED sizes the text by its preset). */+ sizes: boolean;+ /** It draws a box behind the text (the open burner outlines it). */+ box: boolean;+ /** What a karaoke style's highlight colour marks: the spoken word, the burner's own key words, or nothing. */+ highlight: "spoken" | "keywords" | "none";+ /** Karaoke styles show this many words at a time (0: the whole line). */+ karaokeWords: number;+}++export const BURN_CAPS: Record<BurnRoute, BurnCaps> = {+ open: { positions: ["top", "bottom"], sizes: true, box: false, highlight: "none", karaokeWords: 3 },+ veed: { positions: ["top", "center", "bottom"], sizes: false, box: true, highlight: "keywords", karaokeWords: 0 },+ auto: { positions: ["top", "center", "bottom"], sizes: true, box: true, highlight: "spoken", karaokeWords: 3 },+};++/** The look a burner will actually draw: a position it lacks falls back to the bottom. */+export function lookFor(route: BurnRoute, look: CaptionLook): CaptionLook {+ return BURN_CAPS[route].positions.includes(look.position) ? look : { ...look, position: "bottom" };+}++/** VEED's dynamic presets bill twice the basic rate. */+const VEED_DYNAMIC = new Set(["glass", "whisper", "glide2", "fusion", "glide", "terminal", "handwritten", "backdrop", "backdrop2"]);++/** The burn's price per minute of video (USD), for the route's note; 0 on the open engine. */+export function burnPricePerMinute(route: BurnRoute, style: string): number {+ if (route === "open") return 0;+ if (route === "auto") return 0.03;+ return VEED_DYNAMIC.has(styleById(style).veed) ? 0.2 : 0.1;+}++/** What the style controls mean on this burner, in one line. */+export function burnNote(route: BurnRoute): string {+ if (route === "open") return "The open burner draws outlined text at the top or the bottom; karaoke styles show 3 words at a time, without a highlight.";+ if (route === "veed") return "VEED sizes the text by its preset; in karaoke styles the highlight colour marks the words VEED finds key, not the spoken one.";+ return "Auto Subtitle shows 3 words at a time and highlights the spoken word in karaoke styles.";+}+const upper = (cues: Cue[], on?: boolean) => (on ? cues.map((c) => ({ ...c, text: c.text.toUpperCase() })) : cues);/** The burn job for a style: the model, its settings (params.extra) and the cues it takes. */@@ -172,16 +213,22 @@ export function transcribeRequest(o: { engine: Engine; video: string; modelId?:};}-/** The words shown at time `t` (karaoke styles show a few words at a time), for the live preview. */-export function previewText(cues: Cue[], t: number, look: CaptionLook): { text: string; highlight?: number } | null {+/**+ * The words shown at time `t`, the way the route's burner shows them (for the live preview): karaoke+ * styles show a few words at a time where the burner does, and the spoken word is highlighted only+ * where the burner highlights it.+ */+export function previewText(cues: Cue[], t: number, look: CaptionLook, route: BurnRoute = "auto"): { text: string; highlight?: number } | null {const c = cues.find((x) => t >= x.start && t < x.end);if (!c) return null;const style = styleById(look.style);+ const caps = BURN_CAPS[route];const text = style.upper ? c.text.toUpperCase() : c.text;- if (!style.karaoke) return { text };+ if (!style.karaoke || !caps.karaokeWords) return { text };const words = text.split(/\s+/).filter(Boolean);if (!words.length) return null;+ const n = caps.karaokeWords;const i = Math.min(words.length - 1, Math.floor(((t - c.start) / Math.max(0.01, c.end - c.start)) * words.length));- const group = Math.floor(i / 3) * 3;- return { text: words.slice(group, group + 3).join(" "), highlight: i - group };+ const group = Math.floor(i / n) * n;+ return { text: words.slice(group, group + n).join(" "), ...(caps.highlight === "spoken" && { highlight: i - group }) };}diff --git a/tests/av-tools.test.ts b/tests/av-tools.test.tsindex 66c12e27..60bbf609 100644--- a/tests/av-tools.test.ts+++ b/tests/av-tools.test.ts@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";import { buildPayload, extractOutputs } from "@/lib/catalog/payload";import { getModel, getPreset } from "@/lib/catalog";import { planGeneration } from "@/lib/catalog/plan";-import { burnRequest, burnRouteFor, CAPTION_STYLES, nearestColorName, OPEN_FONT_SIZE, previewText, styleById, usesCues, type CaptionLook } from "@/lib/av/captions";+import { BURN_CAPS, burnPricePerMinute, burnRequest, burnRouteFor, CAPTION_STYLES, lookFor, nearestColorName, OPEN_FONT_SIZE, previewText, styleById, usesCues, type CaptionLook } from "@/lib/av/captions";import { animateSpinHref, model3dRequest, model3dView, MODELS_3D } from "@/lib/av/model3d";import { frameParams, frameRequest } from "@/lib/av/frames";import type { Cue } from "@/lib/cues";@@ -74,6 +74,25 @@ describe("caption style → burn params", () => {expect(previewText(cues, 0.5, look())?.text).toBe("hello there friends");expect(previewText(cues, 5, look())).toBeNull();});++ it("the controls and the preview promise only what each burner draws", () => {+ // Open: top or bottom only (Middle falls back), no box, karaoke in 3-word groups without a highlight.+ expect(lookFor("open", look({ position: "center" })).position).toBe("bottom");+ expect(lookFor("veed", look({ position: "center" })).position).toBe("center");+ expect(BURN_CAPS.open).toMatchObject({ box: false, highlight: "none", karaokeWords: 3 });+ const karaoke = look({ style: "karaoke" });+ const six: Cue[] = [{ start: 0, end: 3, text: "hello there friends how are you" }];+ expect(previewText(six, 0.6, karaoke, "open")).toEqual({ text: "HELLO THERE FRIENDS" });+ expect(previewText(six, 0.6, karaoke, "auto")).toEqual({ text: "HELLO THERE FRIENDS", highlight: 1 });+ // VEED renders the whole line (its preset animates it) and sizes text itself: Size isn't offered.+ expect(previewText(six, 0.6, karaoke, "veed")).toEqual({ text: "HELLO THERE FRIENDS HOW ARE YOU" });+ expect(BURN_CAPS.veed.sizes).toBe(false);+ expect(burnRequest({ route: "veed", video: "/v.mp4", cues, look: look({ size: "L" }) }).params?.extra).not.toHaveProperty("font_size");+ // Karaoke, Boxed and Neon map to VEED's dynamic presets, which cost twice as much.+ expect(CAPTION_STYLES.filter((s) => burnPricePerMinute("veed", s.id) === 0.2).map((s) => s.id)).toEqual(["karaoke", "boxed", "neon"]);+ expect(burnPricePerMinute("veed", "clean")).toBe(0.1);+ expect(burnPricePerMinute("open", "karaoke")).toBe(0);+ });});describe("3D viewer data flow", () => {