I run csip12.in, a small free study site for CBSE Class 11 and 12 Computer Science students in India. Students asked for short videos, so this month I started making 60-second explainers for topics like circuit switching and packet switching.
I do not own a video editor and I did not want to learn one. Instead, each video is a web page that knows how to draw any moment of itself, and a script that takes 30 photos of it per second. Here is how it works and what went wrong along the way.
1. The video is a pure function of time
The whole video is one HTML file at 1080×1920. It has a fixed layout (title, a speech-bubble caption, an SVG area for the animation, progress dots) and one important function:
function render(t) { let k = 0; for (let i = 0; i < DUR.length; i++) if (t >= START[i]) k = i; // which scene const lt = t - START[k]; // time inside it art.innerHTML = SCENES[k](lt, DUR[k]); // SVG string cap.innerHTML = CAPTIONS[k]; } Each scene is a function (localTime, duration) => svgString. There is no requestAnimationFrame, no CSS transitions, no state carried from one frame to the next. Every frame is computed from t alone.
That one rule is what makes the rest easy. I can jump to second 37.4 and see exactly what that frame will look like. I can render frames out of order, or render one still per scene to check the layout before spending ten minutes on a full capture.
The animations are just small helpers on top of that:
const clamp = (x, a = 0, b = 1) => Math.min(b, Math.max(a, x)); const ease = x => x < .5 ? 2*x*x : 1 - (-2*x + 2)**2 / 2; // pop(lt, at): 0 before `at`, then a quick overshoot up to 1 A packet moving from router R1 to R2 is lerp(x1, x2, ease(clamp((lt - 1.2) / 0.8))). A label appearing at 2.5 s is scale = pop(lt, 2.5). Once you have five or six of these, building a scene goes surprisingly fast.
2. Taking the photos
A Python script starts Chrome headless with --remote-debugging-port, opens the page over the DevTools protocol, and then loops:
for i in range(int(TOTAL * FPS)): await call('Runtime.evaluate', expression=f'render({i / FPS})') shot = await call('Page.captureScreenshot', format='jpeg', quality=92) save(f'frames/f{i:05d}.jpg', shot['data']) Two details mattered:
- Fonts. Before the first frame, I wait on
document.fonts.readyand print which font families actually loaded. A fallback font in frame 1 and the real font in frame 40 looks like a glitch. - Window size.
Emulation.setDeviceMetricsOverridewith 1080×1920 anddeviceScaleFactor: 1, so the screenshot is exactly one video frame with no scaling.
A 60-second video is 1,800 screenshots. On my laptop that takes a few minutes, which is fine.
3. Timing comes from the voice, not the other way round
I write the narration first, one line per scene, and generate each line with a text-to-speech model running locally. Then the build script:
- trims the silence at both ends of every line with ffmpeg's
silenceremove(run forwards, reversed, and forwards again so it trims the end too), - measures each trimmed clip with
ffprobe, - sets each scene's duration to the line's length plus 0.85 s of breathing room,
- writes those durations into a copy of the HTML file before capturing.
So if I rewrite a sentence and it gets longer, the scene simply gets longer. Nothing needs to be re-timed by hand.
The audio is one ffmpeg -filter_complex: each voice line is delayed to its scene start with adelay, everything is mixed with amix, a quiet background track is added at 8% volume, and loudnorm=I=-14 brings the result to the loudness that YouTube and Facebook expect. The background music is also generated, a four-chord loop of sine waves written with NumPy, so there is nothing to license.
4. Things that bit me
Stale frames. I once shortened a video and the output came out longer than before. The capture had written frames 0–1,850 into a folder that still held frames up to 1,950 from the previous, longer render, and ffmpeg's f%05d.jpg input happily used all of them. The build now deletes the frames folder before every capture.
Checking audio quality without listening to all of it. Local TTS on a 4 GB GPU sometimes returns a take that is just a hum or hiss. Instead of listening to every take, I render a tiny spectrogram for each line (showspectrumpic, 0–4 kHz). Real speech shows clear stacked harmonic stripes, and a bad take shows flat horizontal bars or uniform noise. I glance at ten small images and re-generate only the bad lines.
ffmpeg crashing on contact sheets. I wanted a grid of one still per scene to review layouts at a glance. hstack/xstack with a dozen inputs crashed ffmpeg on Windows with a heap error, so I tile the stills with Pillow instead. It is five lines of code and has never failed.
Text overflow. SVG text does not wrap and does not complain. A table cell like "Store & forward" at font size 38 quietly ran over its box. The only reliable check was the contact sheet: render the stills and look.
Why not just use a video editor?
For one video, an editor is faster. For a series, this approach wins: every video shares the same layout and helpers, so a new topic means writing about ten scene functions and ten sentences. Changing the brand colour or the caption font across all videos is a single line of CSS. And because the video lives in plain text files, I can keep old versions and see exactly what changed between them.
The first one, on circuit switching, is here: Circuit Switching in 60 seconds. The notes it is based on are on csip12.in, and I would be glad to hear from anyone who has built something similar, especially about speeding up the capture loop.

