Skip to content

Drive Google Flow from Claude, Codex or a local control panel, on Mac or Windows — using your Google AI subscription credits instead of the pay-per-use video API. No browser extension.

Captions: highlight 0.12 s earlier so words no longer light up late; size slider

GTAI-141d3840e9c09
diff --git a/CLAUDE.md b/CLAUDE.md
index 31b51c7..9b66a06 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -469,3 +469,9 @@ The preview tool could not read the project while it lived in ~/Desktop; check t
downloads. Tested with a local stand-in server (HOME pointed at an empty folder): first use, two callers at once
(one download), a second download in the same panel process, and an unreachable server (clear error, no leftovers).
The real huggingface download has not been run from this code.
+- Caption timing (2026-10-11, "words light up a bit late"): measured on the First Ascent narration against each word's
+ real onset in the sound (words after a pause): whisper's token start was 0.00 s for about half and 0.13-0.18 s LATE
+ for the rest (one outlier 0.53). AV sync tolerance is asymmetric (ITU-R BT.1359: a picture lagging its sound shows from
+ ~45 ms, one leading it goes unnoticed to ~125 ms), so every caption state now starts LEAD = 0.12 s early (`lead`
+ option, -0.5..0.5, MCP only). The .srt shifts with it (first cue 0.22 -> 0.10). Size is now a percentage too
+ (`size` small|medium|large or 40-250; the panel has a 50-180 % slider; old saved presets map to 80/100/120).
diff --git a/README.md b/README.md
index 59aa154..853e6b4 100644
--- a/README.md
+++ b/README.md
@@ -159,7 +159,7 @@ Eight tabs, in the order you would use them:
sound down so the narration sits on top.
- **Captions**: put the spoken words on screen, the way short-form videos do, on wide or vertical videos.
Pick a video, choose a style (Bold pop, Highlight, Word by word, Clean, Boxed), where it sits (bottom,
- middle, top, an exact height, or tap the preview), its size, its letters (normal, CAPS or lowercase) and
+ middle, top, an exact height, or tap the preview), its size (a slider), its letters (normal, CAPS or lowercase) and
highlight colour, and see it on a real frame of your video before anything is made. Fix any misheard
word in the text box and it keeps its timing; press Enter to start a new caption. Saves `<name>-captions.mp4` plus an `.srt` for YouTube.
Everything happens on your computer; nothing is uploaded.
@@ -203,7 +203,7 @@ agree on what is running. That API listens on 127.0.0.1 only and needs a per-run
| `flow_techniques` | 39 film-technique prompt presets (camera moves, product shots, transitions, image commands); pass an id as a scene's `technique` |
| `flow_narrate` | Free narration audio, any length: `gemini` (Google AI Studio text-to-speech, with the same voices Flow has, plus a `style` note) or `mac` (a voice installed on this computer, no key needed) |
| `flow_voices` | Narrator voices available, and whether a Google key is set up |
-| `flow_captions` | Burn spoken-word captions into any video, landscape or vertical, in one of five styles, at any height, in normal, capital or lowercase letters; returns the transcript so a misheard word can be fixed and the call repeated (local whisper.cpp, Chrome and FFmpeg, no credits) |
+| `flow_captions` | Burn spoken-word captions into any video, landscape or vertical, in one of five styles, at any height and size, in normal, capital or lowercase letters; returns the transcript so a misheard word can be fixed and the call repeated (local whisper.cpp, Chrome and FFmpeg, no credits) |
| `flow_assemble` | Join clips into one MP4 (a project's clips, or any you list, in order) with optional music and voiceover, and separate volume for the clips' own sound (local FFmpeg, no credits) |
**Continuity between shots:** `chain_previous` (this clip starts on the last frame of the previous
diff --git a/src/captions.ts b/src/captions.ts
index c9ccb7a..624f457 100644
--- a/src/captions.ts
+++ b/src/captions.ts
@@ -52,7 +52,8 @@ export const CAPTION_STYLES = {
export type CaptionStyle = keyof typeof CAPTION_STYLES;
// A preset, or how far down the frame the middle of the caption sits: 0 = top edge, 100 = bottom edge.
export type CaptionPosition = "bottom" | "middle" | "top" | number;
-export type CaptionSize = "small" | "medium" | "large";
+// A preset, or a percentage of the style's normal size (100 = medium).
+export type CaptionSize = "small" | "medium" | "large" | number;
// as_said keeps whisper's own capitals (sentence starts, names); capitals and lowercase are looks, and both drop
// trailing commas and full stops the way short-form captions do.
export type CaptionLetters = "as_said" | "capitals" | "lowercase";
@@ -63,6 +64,8 @@ export interface CaptionOptions {
size: CaptionSize;
color?: string;
letters?: CaptionLetters;
+ // Seconds the highlight runs ahead of the voice (see LEAD).
+ lead?: number;
text?: string;
language?: string;
}
@@ -73,6 +76,13 @@ const lettersOf = (o: { style: CaptionStyle; letters?: CaptionLetters }): Captio
const FONT = { bold: 7.2, highlight: 6.2, reveal: 6.4, clean: 4.6, boxed: 4.6 };
const CHAR_EM = { bold: 0.74, highlight: 0.56, reveal: 0.56, clean: 0.52, boxed: 0.52 };
const SIZE = { small: 0.82, medium: 1, large: 1.2 };
+const scaleOf = (size: CaptionSize) => (typeof size === "number" ? Math.min(2.5, Math.max(0.4, size / 100)) : SIZE[size]);
+
+// Measured on the First Ascent narration (2026-10-11): against where each word really starts in the sound, whisper
+// put about half the words on time and the other half 0.13-0.18 s late - and a late highlight shows. People notice a
+// picture that lags its sound from about 0.05 s, but not one that runs up to about 0.12 s ahead (ITU-R BT.1359),
+// so every caption moves 0.12 s earlier: the late words land almost exactly, the on-time ones stay unnoticeably early.
+const LEAD = 0.12;
/* ---------- hearing the words ---------- */
@@ -334,9 +344,10 @@ function paginate(words: Word[], maxWords: number, maxChars: number): Word[][] {
return pages;
}
-function layout(words: Word[], style: CaptionStyle, width: number, height: number, size: CaptionSize, letters: CaptionLetters): { pages: Word[][]; states: State[] } {
+function layout(heard: Word[], style: CaptionStyle, width: number, height: number, size: CaptionSize, letters: CaptionLetters, lead: number): { pages: Word[][]; states: State[] } {
+ const words = heard.map((w) => ({ ...w, start: Math.max(0, w.start - lead), end: Math.max(0, w.end - lead) }));
const s = CAPTION_STYLES[style];
- const u = (Math.min(width, height) / 100) * SIZE[size];
+ const u = (Math.min(width, height) / 100) * scaleOf(size);
// Capitals are wider than small letters, so fewer of them fit on a line.
const wide = CHAR_EM[style] * (letters === "capitals" && style !== "bold" ? 1.2 : letters !== "capitals" && style === "bold" ? 0.85 : 1);
const perLine = Math.max(8, Math.floor(boxWidth(style, width, height) / (FONT[style] * u * wide)));
@@ -389,7 +400,7 @@ function textOn(hex: string): string {
function pageHtml(style: CaptionStyle, o: { width: number; height: number; position: CaptionPosition; size: CaptionSize; color: string; letters: CaptionLetters; background?: string }): string {
const { width: W, height: H } = o;
const vertical = H > W;
- const font = FONT[style] * (Math.min(W, H) / 100) * SIZE[o.size];
+ const font = FONT[style] * (Math.min(W, H) / 100) * scaleOf(o.size);
const place =
typeof o.position === "number"
? `top:${Math.min(96, Math.max(4, o.position))}%;transform:translate(-50%,-50%)`
@@ -479,7 +490,7 @@ async function timedWords(video: string, o: CaptionOptions): Promise<{ transcrip
export async function previewCaptions(video: string, o: CaptionOptions): Promise<{ image: string; at: number }> {
const info = await probe(video);
const { words } = await timedWords(video, o);
- const { pages, states } = layout(words, o.style, info.width, info.height, o.size, lettersOf(o));
+ const { pages, states } = layout(words, o.style, info.width, info.height, o.size, lettersOf(o), o.lead ?? LEAD);
// A caption of a few words, about a third of the way in, mid-sentence.
const want = (pages[0]?.[0].start ?? 0) + ((pages.at(-1)?.at(-1)?.end ?? 0) - (pages[0]?.[0].start ?? 0)) * 0.33;
const page = pages.filter((p) => p.length >= Math.min(2, CAPTION_STYLES[o.style].maxWords)).sort((p, q) => Math.abs(p[0].start - want) - Math.abs(q[0].start - want))[0] ?? pages[0];
@@ -520,7 +531,7 @@ export interface CaptionResult {
export async function burnCaptions(video: string, o: CaptionOptions, output: string): Promise<CaptionResult> {
const info = await probe(video);
const { transcript, words } = await timedWords(video, o);
- const { pages, states } = layout(words, o.style, info.width, info.height, o.size, lettersOf(o));
+ const { pages, states } = layout(words, o.style, info.width, info.height, o.size, lettersOf(o), o.lead ?? LEAD);
if (!states.length) throw new Error("There are no words to put on screen.");
const work = mkdtempSync(join(tmpdir(), "flow-captions-"));
diff --git a/src/core.ts b/src/core.ts
index a7dc885..181b800 100644
--- a/src/core.ts
+++ b/src/core.ts
@@ -63,7 +63,16 @@ const captionFields = {
.union([z.enum(["bottom", "middle", "top"]), z.number().min(0).max(100)])
.default("bottom")
.describe("bottom, middle or top - or a number for an exact height: how far down the frame the middle of the caption sits, 0 = top edge, 100 = bottom edge."),
- size: z.enum(["small", "medium", "large"]).default("medium"),
+ size: z
+ .union([z.enum(["small", "medium", "large"]), z.number().min(40).max(250)])
+ .default("medium")
+ .describe("small, medium, large, or a percentage of the style's normal size (100 = medium, 150 = half again as big)."),
+ lead: z
+ .number()
+ .min(-0.5)
+ .max(0.5)
+ .optional()
+ .describe("Seconds the highlight runs ahead of the voice. Default 0.12; raise it if words still light up late, lower it if early."),
color: z.string().regex(/^#[0-9a-fA-F]{6}$/).optional().describe("Highlight colour as #RRGGBB, for bold, highlight and reveal."),
letters: z
.enum(["as_said", "capitals", "lowercase"])
diff --git a/studio/index.html b/studio/index.html
index bd8ee2c..b0a49a5 100644
--- a/studio/index.html
+++ b/studio/index.html
@@ -373,7 +373,7 @@ audio{width:100%;margin-top:8px;filter:invert(1) hue-rotate(180deg)}
<div class="capstyles" id="cap_styles"></div>
<div class="grid2">
<div><label class="f">Position</label><div class="seg" data-seg="cap_pos"></div></div>
- <div><label class="f">Size</label><div class="seg" data-seg="cap_size"></div></div>
+ <div><label class="f" for="cap_size">Size <span id="cap_sizeOut" style="text-transform:none;letter-spacing:0"></span></label><input type="range" id="cap_size" min="50" max="180" step="5" value="100"></div>
</div>
<label class="f">Letters</label><div class="seg" data-seg="cap_letters"></div>
<label class="f">Exact height <span id="cap_yOut" style="text-transform:none;letter-spacing:0"></span></label>
@@ -455,7 +455,7 @@ const DEFAULTS = {
shots: { project: "MyFilm", model: "Omni 1.1 Flash", aspect: "16:9", duration: 8, resolution: "720p", variants: 1, quality: "original", max: 25, scenes: [blank()] },
narrate: { project: "MyFilm", engine: "gemini", geminiVoice: "Charon", macVoice: "Zoe (Premium)", text: "", style: "" },
cut: { project: "MyFilm", music: null, voiceover: null, hold: true, clips: [] },
- captions: { video: null, style: "bold", position: "bottom", size: "medium", colors: {}, text: "" },
+ captions: { video: null, style: "bold", position: "bottom", size: 100, colors: {}, text: "" },
};
const S = Object.assign(structuredClone(DEFAULTS), JSON.parse(localStorage.getItem("flow-studio-v2") || "{}"));
const save = () => localStorage.setItem("flow-studio-v2", JSON.stringify(S));
@@ -488,7 +488,6 @@ const SEGS = {
s_quality: { get: () => S.shots.quality, set: (v) => (S.shots.quality = v), opts: ["original", "upscaled"], labels: { original: "720p", upscaled: "1080p" } },
s_variants: { get: () => S.shots.variants, set: (v) => (S.shots.variants = +v), opts: [1, 2, 3, 4] },
cap_pos: { get: () => (typeof S.captions.position === "string" ? S.captions.position : ""), set: (v) => { S.captions.position = v; capPreviewSoon(); }, opts: ["bottom", "middle", "top"], labels: { bottom: "Bottom", middle: "Middle", top: "Top" } },
- cap_size: { get: () => S.captions.size, set: (v) => { S.captions.size = v; capPreviewSoon(); }, opts: ["small", "medium", "large"], labels: { small: "Small", medium: "Medium", large: "Large" } },
cap_letters: { get: () => capLetters(S.captions.style), set: (v) => { (S.captions.letters ??= {})[S.captions.style] = v; capPreviewSoon(); }, opts: ["as_said", "capitals", "lowercase"], labels: { as_said: "Normal", capitals: "CAPS", lowercase: "lower" } },
n_engine: { get: () => S.narrate.engine, set: (v) => (S.narrate.engine = v), opts: ["gemini", "mac"], labels: { gemini: "Google AI Studio", get mac() { return PLACE.local_engine; } } },
};
@@ -847,8 +846,10 @@ const capColor = (style) => S.captions.colors?.[style] ?? CAP_COLORS[style]?.[0]
// Bold pop is capitals unless the user picks otherwise; every other style keeps the words as said.
const capLetters = (style) => S.captions.letters?.[style] ?? (style === "bold" ? "capitals" : "as_said");
const CASE_CSS = { as_said: "none", capitals: "uppercase", lowercase: "lowercase" };
+// Size is a percentage of the style's normal size; older saved settings said small, medium or large.
+const capSize = () => (typeof S.captions.size === "number" ? S.captions.size : { small: 80, medium: 100, large: 120 }[S.captions.size] ?? 100);
function capOpts() {
- const c = S.captions, o = { video: c.video.path, style: c.style, position: c.position, size: c.size };
+ const c = S.captions, o = { video: c.video.path, style: c.style, position: c.position, size: capSize() };
if (CAP_COLORS[c.style]) o.color = capColor(c.style);
o.letters = capLetters(c.style);
const t = $("#cap_text").value;
@@ -866,6 +867,8 @@ function renderCaptions() {
// Presets show where they put the words on this video's shape; a number is the user's own height.
const y = typeof c.position === "number" ? c.position : { top: capVertical ? 18 : 12, middle: 50, bottom: capVertical ? 75 : 87 }[c.position];
$("#cap_y").value = y;
+ $("#cap_size").value = capSize();
+ $("#cap_sizeOut").textContent = `· ${capSize()}%`;
$("#cap_yOut").textContent = typeof c.position === "number" ? `· ${y}% down` : `· ${c.position}`;
$("#cap_go").disabled = !c.video;
}
@@ -924,6 +927,7 @@ $("#cap_film").onclick = () => openFilms("captions");
$("#cap_pathgo").onclick = () => { const p = $("#cap_path").value.trim().replace(/^["']|["']$/g, ""); if (!p) return; $("#cap_path").value = ""; setCapVideo({ path: p, name: p.split(/[\\/]/).pop() }); };
const capPlace = (y) => { S.captions.position = Math.round(Math.min(95, Math.max(5, y))); save(); renderSegs(); renderCaptions(); capPreviewSoon(); };
$("#cap_y").addEventListener("input", (e) => capPlace(+e.target.value));
+$("#cap_size").addEventListener("input", (e) => { S.captions.size = +e.target.value; save(); $("#cap_sizeOut").textContent = `· ${S.captions.size}%`; capPreviewSoon(); });
$("#cap_preview").addEventListener("click", (e) => { const r = e.target.getBoundingClientRect(); capPlace(((e.clientY - r.top) / r.height) * 100); });
$("#cap_preview").addEventListener("load", (e) => { const v = e.target.naturalHeight > e.target.naturalWidth; if (v !== capVertical) { capVertical = v; renderCaptions(); } });
$("#cap_path").addEventListener("keydown", (e) => { if (e.key === "Enter") $("#cap_pathgo").click(); });