Captions Burned 1
Captions. A layer that reads the skill's timeline (scenes with word timings) and shows short cards: each scene split at punctuation and balanced into lines of about 34 characters (26 vertical), a card showing from its first word's start to the next card's start: utility beat.
Use it in a prompt
Use the video/captions-burned video frame from the FunnelDNA library in my brand (landscape and vertical). Follow the video skill. Ask me for the script facts, voice and images you need; do not invent proof.
Paste into Claude or ChatGPT with FunnelDNA connected (MCP setup), or alongside the skill.
Use it in code
- Save
component.tsx(Code tab) ascomponents/funneldna/video/captions-burned.tsx. - Import it and pass your copy and images (Props tab):
import { CaptionsBurned } from "@/components/funneldna/video/captions-burned"
It restyles from the theme tokens on any wrapper (Theme tab). The specimen source is a complete working example.
pieces/video/captions-burned/component.tsx 166 lines
import * as React from "react"
import { useCurrentFrame, useVideoConfig } from "remotion"
import {
CaptionBand, HOLD, MarkerSwipe, StagePhoto, T, VideoStage, springAt, SPRINGS, useStage,
type VideoFormat, type VideoMeta, type Word,
} from "../fx/video-kit"
export const video = { fps: 30, durationInFrames: 460, formats: ["landscape", "vertical"], poster: 60 } satisfies VideoMeta
/** One voiced scene of the skill's timeline.json: `start` (seconds from the video start; omitted = after the previous
* scene) and its words in seconds from that start. */
export type CaptionScene = { id?: string; start?: number; words: Word[] }
export type CaptionStyle = "box" | "karaoke" | "big-word"
export type CaptionCard = { from: number; to: number; text: string; words: { w: string; at: number }[] }
const STOP = /^(a|an|the|as|of|to|at|on|in|and|i|you|so|my|your|with|that|it|for|is|me|by|from|or|but|their|his|her|its|our|we|are|be|this|no)$/i
const TIME = /^(a\.m\.?|p\.m\.?)[,.?!]?$/i
const txt = (ws: Word[]) => ws.map((w) => w.w).join(" ")
/** Split a phrase into lines of at most `max` characters, never ending a line on a small word or before "a.m.". */
function balance(ws: Word[], max: number): Word[][] {
if (txt(ws).length <= max || ws.length < 2) return [ws]
let best = -1, score = Infinity
for (let k = 1; k < ws.length; k++) {
if (STOP.test(ws[k - 1].w.replace(/[^a-z']/gi, "")) || TIME.test(ws[k].w)) continue
const d = Math.abs(txt(ws.slice(0, k)).length - txt(ws.slice(k)).length)
if (d < score) { score = d; best = k }
}
if (best < 0) best = Math.ceil(ws.length / 2)
return [...balance(ws.slice(0, best), max), ...balance(ws.slice(best), max)]
}
/** Two or three words at a time (big-word style), kept short. */
function groups(ws: Word[], max: number): Word[][] {
const out: Word[][] = []
let cur: Word[] = []
for (const w of ws) {
const next = [...cur, w]
if (cur.length && (cur.length >= 3 || txt(next).length > max || (TIME.test(w.w) ? false : /[,.?!;:]$/.test(cur[cur.length - 1].w)))) {
// Never end a group on a small word: it moves to the next group.
const carry: Word[] = []
while (cur.length > 1 && STOP.test(cur[cur.length - 1].w)) carry.unshift(cur.pop()!)
out.push(cur); cur = [...carry, w]
} else cur = next
}
if (cur.length) out.push(cur)
// A lone small word joins its neighbour.
return out.flatMap((g, i) => (g.length === 1 && STOP.test(g[0].w) && out[i + 1] ? (out[i + 1].unshift(g[0]), []) : [g]))
}
/** Absolute scene starts in seconds: given, or 0.6 s in for the first and 0.75 s after the previous scene's last word. */
function starts(timeline: CaptionScene[]) {
let t = 0.6
return timeline.map((sc) => {
const s = sc.start ?? t
t = s + (sc.words.length ? sc.words[sc.words.length - 1].e : 0) + 0.75
return s
})
}
/**
* Caption cards in absolute frames, from the timeline: each scene split at punctuation, then balanced into lines of
* about `maxChars` (34 landscape, 26 vertical; big-word: 2–3 words). A card shows from its first word to the next
* card's first word; a scene's last card ends 0.4 s after its last word. Cards never overlap.
*/
export function captionCards(timeline: CaptionScene[], { maxChars = 34, fps = 30, style = "box" as CaptionStyle } = {}): CaptionCard[] {
const out: CaptionCard[] = []
const at0 = starts(timeline)
timeline.forEach((sc, si) => {
const phrases: Word[][] = []
let cur: Word[] = []
for (const w of sc.words) {
cur.push(w)
if (/[,!?:;]$|[^.]\.$/.test(w.w) && !TIME.test(w.w) && txt(cur).length > 10) { phrases.push(cur); cur = [] }
}
if (cur.length) phrases.length && txt(cur).length < 8 ? phrases[phrases.length - 1].push(...cur) : phrases.push(cur)
const lines = phrases.flatMap((p) => (style === "big-word" ? groups(p, Math.min(maxChars, 18)) : balance(p, maxChars)))
lines.forEach((l, i) => {
const next = lines[i + 1]?.[0]
const end = next ? next.s : l[l.length - 1].e + 0.4
out.push({
from: Math.round((at0[si] + l[0].s) * fps), to: Math.round((at0[si] + end) * fps), text: txt(l),
words: l.map((w) => ({ w: w.w, at: Math.round((at0[si] + w.s) * fps) })),
})
})
})
out.sort((a, b) => a.from - b.from)
for (let i = 1; i < out.length; i++) if (out[i].from < out[i - 1].to) out[i - 1].to = out[i].from
return out.filter((c) => c.to > c.from)
}
/** The same cards as a WebVTT track, so the burned captions and the track never disagree. */
export function toVtt(timeline: CaptionScene[], { maxChars = 34, fps = 30 } = {}) {
const ts = (f: number) => {
const ms = Math.round((f / fps) * 1000), h = Math.floor(ms / 3600000), m = Math.floor(ms / 60000) % 60, s = Math.floor(ms / 1000) % 60
return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}.${String(ms % 1000).padStart(3, "0")}`
}
return "WEBVTT\n\n" + captionCards(timeline, { maxChars, fps }).map((c, i) => `${i + 1}\n${ts(c.from)} --> ${ts(c.to)}\n${c.text}\n`).join("\n")
}
export type CaptionsBurnedProps = {
format?: VideoFormat
durationInFrames?: number
/** The voice timeline (timeline.json scenes). Captions match the voice word for word. */
timeline?: CaptionScene[]
style?: CaptionStyle
/** Characters per card; default 34 landscape, 26 vertical. */
maxChars?: number
/** Optional still behind the captions (the specimen's sample scene); in a clip the scenes are behind. */
scene?: string
/** Shifts every card by this many frames (a clip places the layer from its first frame). */
offset?: number
/** Keep the last card up to the end (a captions-only piece); off by default so the end card stays clean. */
holdLast?: boolean
}
/** Captions: short cards from the voice timeline in the caption band, in one of three styles. */
export function CaptionsBurned({ format = "landscape", durationInFrames = video.durationInFrames, timeline = [], style = "box", maxChars, scene, offset = 0, holdLast = false }: CaptionsBurnedProps) {
const frame = useCurrentFrame() - offset
const { fps } = useVideoConfig()
const { u, portrait, width } = useStage()
const s = (n: number) => n * u
const max = maxChars ?? (style === "big-word" ? 16 : portrait ? 26 : 34)
const cards = React.useMemo(() => captionCards(timeline, { maxChars: max, fps, style }), [timeline, max, fps, style])
const card = cards.find((c, i) => frame >= c.from && (frame < c.to || (holdLast && i === cards.length - 1)))
const spoken = card ? card.words.reduce((n, w, i) => (frame >= w.at ? i : n), -1) : -1
let body: React.ReactNode = null
if (card && style === "big-word") {
// Big-word: the display face on a solid band chip, so the words hold contrast on any photo or field (light letters
// on the band token; an outline's dark edge would read as the letter to a pixel contrast check).
body = (
<div style={{
fontFamily: "var(--font-display)", fontWeight: "var(--display-weight, 800)" as unknown as number, textTransform: "var(--display-case, none)" as React.CSSProperties["textTransform"],
fontSize: s(portrait ? 92 : 80), lineHeight: 1.04, letterSpacing: "-0.01em", color: T.bandInk, textAlign: "center", maxWidth: width - s(160), textWrap: "balance",
background: T.band, borderRadius: s(18), padding: `${s(8)}px ${s(28)}px ${s(14)}px`, boxShadow: "var(--shadow-md)",
}}>
{card.words.map((w, i) => {
const k = springAt(frame, w.at, fps, SPRINGS.pop)
// The whole group shows (so it sits centred); each word gives one small pop as it is said.
const pop = i === 0 ? 0 : Math.sin(Math.min(1, k) * Math.PI) * 0.08
return <React.Fragment key={i}>{i ? " " : ""}<span style={{ display: "inline-block", transform: `scale(${(i === 0 ? 0.85 + 0.15 * k : 1) + pop})`, transformOrigin: "50% 70%" }}>{w.w}</span></React.Fragment>
})}
</div>
)
} else if (card) {
body = (
<div style={{
background: `color-mix(in oklch, ${T.band} 86%, transparent)`, color: T.bandInk, borderRadius: s(14), padding: `${s(10)}px ${s(26)}px ${s(12)}px`,
fontFamily: "var(--font-body)", fontWeight: 700, fontSize: s(portrait ? 48 : 44), lineHeight: 1.25, textAlign: "center", maxWidth: width - s(160), whiteSpace: "nowrap",
}}>
{style === "karaoke"
? card.words.map((w, i) => <React.Fragment key={i}>{i ? " " : ""}{i === spoken ? <MarkerSwipe p={1}>{w.w}</MarkerSwipe> : w.w}</React.Fragment>)
: card.text}
</div>
)
}
return (
<VideoStage format={format} tone="transparent">
{scene && <StagePhoto src={scene} frame={Math.min(frame, durationInFrames - HOLD)} dur={durationInFrames - HOLD} treatment="natural" side="full" />}
<CaptionBand>{body}</CaptionBand>
</VideoStage>
)
}
export default CaptionsBurned
pieces/video/captions-burned/specimen.tsx 45 lines
import * as React from "react"
import { useCurrentFrame } from "remotion"
import night from "../../fx/backdrops/night"
import { slot } from "../../slots"
import { VideoPreview, type VideoFormat, type Word } from "../../fx/video-kit"
import { CaptionsBurned, video, type CaptionScene, type CaptionsBurnedProps } from "../captions-burned"
export const states = ["landscape", "vertical"]
/** First card readable (box), karaoke (a word lit as it is said), big-word, the end. */
export const keyframes = [20, 280, 400, 459]
/** Sample voice timings at a natural read; longer words and pauses after punctuation take longer. */
function voiced(text: string): Word[] {
let t = 0
return text.split(" ").map((w) => {
const d = 0.13 + 0.04 * w.replace(/[^a-z0-9]/gi, "").length
const word = { w, s: +t.toFixed(3), e: +(t + d).toFixed(3) }
t += d + 0.05 + (/[,.?!]$/.test(w) ? 0.2 : 0)
return word
})
}
// Fictional sample voice for Dana Whitlock (sleep coach), scenes back to back; one scene per caption style.
export const timeline: CaptionScene[] = [
{ words: voiced("Still wide awake at 10 a.m. after a night shift? You are not doing it wrong.") },
{ words: voiced("Your body clock is fighting the morning light. Here is how to win.") },
{ words: voiced("Tap below and the book is yours.") },
]
/** The specimen shows all three styles in turn over one sample still. */
function Showcase(props: CaptionsBurnedProps) {
const f = useCurrentFrame()
return <CaptionsBurned {...props} style={f < 200 ? "box" : f < 360 ? "karaoke" : "big-word"} />
}
// Serialisable sample props: no image URL here, so a render never receives a still URL resolved against another server.
// The designed still is resolved inside the render below via the scene slot.
export const sample: CaptionsBurnedProps = { timeline, holdLast: true }
/** The sample business in its own colours and type (sample-palettes.md: deep-ocean · friendly); Original and every preset stay one click away. */
export const sampleBrand = { name: "Dana Whitlock", theme: "light", background: "#f1f8f8", colors: ["#0e7c7b", "#f2a541"], fonts: ["Archivo", "Inter"] }
export default function CaptionsBurnedSpecimen({ state = "landscape" }: { state?: string }) {
const scene = slot("scene", night)
return <VideoPreview component={Showcase} props={{ ...sample, scene }} format={state as VideoFormat} meta={video} />
}
| Name | Type | Details |
|---|---|---|
captionCards |
CaptionScene[] |
|
toVtt |
CaptionScene[] |
|
format OptionalCaptionsBurned |
VideoFormat |
Default "landscape"
|
durationInFrames OptionalCaptionsBurned |
number |
Default video.durationInFrames
|
timeline OptionalCaptionsBurned |
CaptionScene[] |
Default []
|
style OptionalCaptionsBurned |
CaptionStyle |
Default "box"
|
maxChars OptionalCaptionsBurned |
number |
|
scene OptionalCaptionsBurned |
string |
|
offset OptionalCaptionsBurned |
number |
Default 0
|
holdLast OptionalCaptionsBurned |
boolean |
Default false
|
Theme roles it reads
Set by the theme bar, a preset or your brand. Colours come from the base tokens (--surface, --ink, --cta…) every piece uses.
--display-case--display-weight- Headlines: weight, letter case and tracking.
Image slots
Filled from the brand’s images; the specimen ships its own defaults.
scene- A wide atmosphere photo behind or beside the copy.
-
7ef109748b828d4d.webp
image/webp · 22.2 KB