I make vertical explainer reels for Instagram. Nobody is on camera: a voice explains how something works, and a redrawn screen, object or number moves on the word that names it. In my reels every scene starts on a spoken word, not on a frame number I typed. The touchscreen one has 13,494,983 views (Instagram API, Nov 8, 2026).
This is part 1 of 5 on making video with Claude Code and Remotion. It covers the piece everything else rests on: turning a voiceover into word timestamps, then starting scenes on words.
Why frame numbers break
<Sequence from={312}> is a guess about when the voice says something. Change one sentence, record again, and every scene after the change is early or late.
With an AI agent writing the scenes it gets worse. The agent can't hear the audio. It reads the script and guesses frames from the text, and the guesses drift further with every sentence.
Word timestamps fix both problems. You get a list of every spoken word with its start and end in milliseconds. A scene asks for a word ("start when the voice says pen") and the frame is computed from the list.
What you need
- A Remotion project (
npx create-video@latest). The code here was type-checked against Remotion 4.0.548. - A voiceover at
public/voice.mp3. - For the local route: ffmpeg, and room for a Whisper model (medium.en is about 1.5 GB).
- For the cloud route: an AssemblyAI API key. It's billed by audio length.
Step 1: get word timestamps
Option A: whisper.cpp on your own machine
Remotion ships a package that installs whisper.cpp, downloads a model and converts the result into its own caption format.
npm i @remotion/install-whisper-cpp @remotion/captions // scripts/transcribe-whisper.ts import fs from 'node:fs'; import path from 'node:path'; import {execFileSync} from 'node:child_process'; import { downloadWhisperModel, installWhisperCpp, toCaptions, transcribe, } from '@remotion/install-whisper-cpp'; const whisperPath = path.join(process.cwd(), 'whisper.cpp'); const version = '1.5.5'; await installWhisperCpp({to: whisperPath, version}); await downloadWhisperModel({model: 'medium.en', folder: whisperPath}); // whisper.cpp reads 16-bit, 16 kHz WAV only. execFileSync('ffmpeg', [ '-y', '-i', 'public/voice.mp3', '-ar', '16000', '-ac', '1', '-c:a', 'pcm_s16le', 'voice-16k.wav', ]); const whisperCppOutput = await transcribe({ inputPath: 'voice-16k.wav', whisperPath, whisperCppVersion: version, model: 'medium.en', tokenLevelTimestamps: true, }); const {captions} = toCaptions({whisperCppOutput}); fs.writeFileSync('public/captions.json', JSON.stringify(captions, null, 2)); console.log(`${captions.length} words written`); Run it with npx tsx scripts/transcribe-whisper.ts, or plain node scripts/transcribe-whisper.ts on Node 24, which strips the types itself.
Two lines matter more than they look. Remotion's docs say the input "has to be a 16-bit, 16KHz, WAVE file", which is what the ffmpeg call makes. And tokenLevelTimestamps: true passes whisper.cpp's --dtw flag, which the docs call "Recommended to get actually accurate timings".
Option B: AssemblyAI in the cloud
No install, three HTTP calls: upload, submit, poll.
// scripts/transcribe-assemblyai.ts import fs from 'node:fs'; import type {Caption} from '@remotion/captions'; const base = 'https://api.assemblyai.com'; const key = process.env.ASSEMBLYAI_API_KEY; if (!key) throw new Error('Set ASSEMBLYAI_API_KEY first'); const headers = {authorization: key}; // 1. Upload the local file, get a private URL back. const upload = await fetch(`${base}/v2/upload`, { method: 'POST', headers, body: fs.readFileSync('public/voice.mp3'), }); const {upload_url} = (await upload.json()) as {upload_url: string}; // 2. Ask for a transcript of that URL. const submit = await fetch(`${base}/v2/transcript`, { method: 'POST', headers: {...headers, 'content-type': 'application/json'}, body: JSON.stringify({audio_url: upload_url}), }); const {id} = (await submit.json()) as {id: string}; // 3. Poll until it is done. type Word = {text: string; start: number; end: number; confidence: number}; type Transcript = { status: 'queued' | 'processing' | 'completed' | 'error'; error?: string; words?: Word[]; }; let transcript: Transcript; while (true) { const res = await fetch(`${base}/v2/transcript/${id}`, {headers}); transcript = (await res.json()) as Transcript; if (transcript.status === 'completed') break; if (transcript.status === 'error') throw new Error(transcript.error); await new Promise((r) => setTimeout(r, 3000)); } // 4. Same shape as Remotion's Caption. The leading space marks a new word, // which createTikTokStyleCaptions() relies on later. const captions: Caption[] = (transcript.words ?? []).map((w, i) => ({ text: i === 0 ? w.text : ` ${w.text}`, startMs: w.start, endMs: w.end, timestampMs: null, confidence: w.confidence, })); fs.writeFileSync('public/captions.json', JSON.stringify(captions, null, 2)); console.log(`${captions.length} words written`); AssemblyAI gives start and end for every word in milliseconds. Its own FAQ says these "are accurate to within about 400 milliseconds", so play the first result against the audio before you build on it.
The file you end up with
Both scripts write the same shape to public/captions.json (values below are an example):
[ {"text": "Your", "startMs": 120, "endMs": 300, "timestampMs": null, "confidence": 0.98}, {"text": " phone", "startMs": 300, "endMs": 560, "timestampMs": null, "confidence": 0.99}, {"text": " screen", "startMs": 560, "endMs": 910, "timestampMs": null, "confidence": 0.97} ] The leading space on " phone" is on purpose. Whisper uses it to mark where a new word starts, and Remotion's caption helpers read it (part 2 depends on it). That's why the AssemblyAI script adds one to every word but the first.
Step 2: load the timings before the render starts
calculateMetadata runs before Remotion renders anything. It's the right place to fetch the file and set the video's length from the last word, so the composition is always exactly as long as the voice.
// src/Explainer.tsx (top of the file) import React from 'react'; import { AbsoluteFill, interpolate, Sequence, spring, staticFile, useCurrentFrame, useVideoConfig, type CalculateMetadataFunction, } from 'remotion'; import {Audio} from '@remotion/media'; import type {Caption} from '@remotion/captions'; import {makeCue} from './timing'; export type ExplainerProps = { captions: Caption[]; }; // Runs before render: loads the word timings and sets the length from the last word. export const calculateExplainerMetadata: CalculateMetadataFunction< ExplainerProps > = async ({props}) => { const res = await fetch(staticFile('captions.json')); const captions = (await res.json()) as Caption[]; const fps = 60; const lastMs = captions.at(-1)?.endMs ?? 0; return { fps, durationInFrames: Math.ceil(((lastMs + 800) / 1000) * fps), props: {...props, captions}, }; }; Register it with empty default props; the real captions arrive through calculateMetadata:
// src/Root.tsx <Composition id="Explainer" component={Explainer} width={1080} height={1920} fps={60} durationInFrames={60} defaultProps={{captions: []}} calculateMetadata={calculateExplainerMetadata} /> Record a longer take and the video grows with it. Nobody edits durationInFrames again.
Step 3: a helper that turns a word into a frame
// src/timing.ts import type {Caption} from '@remotion/captions'; // "Finger," and "finger" should match, so compare letters and digits only. const clean = (s: string) => s.toLowerCase().replace(/[^\p{L}\p{N}']/gu, ''); // Returns a function that gives the frame where a word is spoken. // nth = 2 means the second time the word is said. export const makeCue = (captions: Caption[], fps: number) => { return (word: string, nth = 1): number => { const target = clean(word); let seen = 0; for (const c of captions) { if (clean(c.text) === target && ++seen === nth) { return Math.round((c.startMs / 1000) * fps); } } // Fail loudly: a silent fallback is how scenes drift off the voice. throw new Error(`"${word}" (#${nth}) is not in the transcript`); }; }; Three choices in those 20 lines:
-
clean()strips punctuation and case, so"Finger,"in the transcript matchesfingerin your code. -
nthhandles words the voice says twice.at('screen', 2)is the second "screen". - It throws. If a word is missing, the render stops with
"pen" (#1) is not in the transcript. The alternative, quietly returning frame 0, gives you a video where one scene starts at the very beginning and you only notice on the phone.
Step 4: scenes that start on words
The sentence in this example is the opening line of my touchscreen reel: "Your phone screen reacts to the lightest brush of your finger and ignores a pen pressed as hard as you can."
// src/Explainer.tsx (the composition) export const Explainer: React.FC<ExplainerProps> = ({captions}) => { const {fps, durationInFrames} = useVideoConfig(); const at = makeCue(captions, fps); // "Your phone screen reacts to the lightest brush of your finger // and ignores a pen pressed as hard as you can." const screen = at('screen'); const brush = at('brush'); const pen = at('pen'); return ( <AbsoluteFill style={{backgroundColor: '#0b0b0f'}}> <Audio src={staticFile('voice.mp3')} /> <Sequence from={screen} durationInFrames={pen - screen}> {/* The ripple is a beat inside the scene, timed from the scene's start. */} <ScreenScene rippleAt={brush - screen} /> </Sequence> <Sequence from={pen} durationInFrames={durationInFrames - pen}> <PenScene /> </Sequence> </AbsoluteFill> ); }; Inside a <Sequence>, useCurrentFrame() starts at 0. So a scene never knows where it sits in the video, only how long ago its word was said. A beat inside the scene (the ripple on brush) is passed in as a distance from the scene's own start:
// src/Explainer.tsx (the scenes) const ScreenScene: React.FC<{rippleAt: number}> = ({rippleAt}) => { const frame = useCurrentFrame(); // 0 at the word "screen" const {fps} = useVideoConfig(); const enter = spring({frame, fps, config: {damping: 200}}); const ripple = spring({frame, fps, delay: rippleAt, config: {damping: 30}}); return ( <AbsoluteFill style={{justifyContent: 'center', alignItems: 'center'}}> <div style={{ width: 640, height: 1180, borderRadius: 80, background: '#1c1f2a', transform: `translateY(${interpolate(enter, [0, 1], [120, 0])}px)`, opacity: enter, position: 'relative', overflow: 'hidden', }} > <div style={{ position: 'absolute', left: 320 - 200, top: 700 - 200, width: 400, height: 400, borderRadius: 200, border: '6px solid #7cc4ff', transform: `scale(${ripple})`, opacity: 1 - ripple, }} /> </div> </AbsoluteFill> ); }; const PenScene: React.FC = () => { const frame = useCurrentFrame(); // 0 at the word "pen" const {fps} = useVideoConfig(); const press = spring({frame, fps, config: {damping: 12}}); return ( <AbsoluteFill style={{justifyContent: 'center', alignItems: 'center'}}> <div style={{ width: 40, height: 520, borderRadius: 20, background: '#d9d9d9', transform: `translateY(${interpolate(press, [0, 1], [-300, 0])}px)`, }} /> </AbsoluteFill> ); }; Move the sentence to the end of the script, record again, run the transcription, render. The phone, the ripple and the pen follow the words. No number in the code changed.
When the script changes
- A cue word is cut: the render stops on the missing word. Pick a new one.
- Two cues end up in the wrong order (you moved a sentence but not its scene):
pen - screengoes negative and Remotion refuses withdurationInFrames must be positive. Annoying, and better than a render that quietly drops a scene. - Numbers: the voice says "thirteen point five million" and the transcript may write
13.5,13.5 millionor the words. Cue on a plain word next to the number. - Mishears: open
captions.jsononce per voice. A lowconfidencevalue is the quickest way to find the word Whisper got wrong. - A scene feels late: start it a few frames before its word,
at('pen') - 3, and judge it with the sound on.
Where Claude Code comes in
I don't write most scenes by hand anymore. Claude Code writes them, and this helper changes what it writes. Without it, the agent reads the script and invents frame numbers. With at() in the project, I describe the beat ("the phone comes in on screen, the ripple on brush, the pen on pen") and it writes at('screen'), at('brush'), at('pen'). The timing is no longer its guess, it's the voice.
A line in your project's CLAUDE.md is enough for it to stick: "Scenes start on spoken words. Use at(word) from src/timing.ts, never a raw frame number."
Next
Part 2 uses the same captions.json to draw a word-by-word caption with one boxed key word. If you're setting up Remotion inside Claude Code for the first time, I wrote down the install and a timed first test in Remotion with Claude Code: setup, cost and a timed test.
How do you time scenes today: frames, seconds, or words?
This post was written with AI assistance. The code type-checks against Remotion 4.0.548, and the numbers come from my own reels and logs.

