Engraved rowing boat and tall ships in a jungle bay, a frame from The Darien Scheme

Dispatch 01 · Films

Building a documentary like software

One command takes a script to a finished film in six languages. A shared timeline, a narrator that grades its own takes, a score written in NumPy, and a flood solved with fluid equations.

· 8 min read · By Aryan Puri

In 1698 Scotland sent five ships to build a colony in the jungle of Panama. The venture was funded by a huge share of the nation's money, and almost all of it was lost. I wanted to tell that story properly, with maps, ledgers, ships, a narrator and a score. I also wanted to tell it in six languages, and to be able to change the script the night before release without rebuilding anything by hand.

So I didn't open a video editor. I wrote the film as a build.

./build.sh              # script in, finished films out
./build.sh --no-render  # everything except the picture
Command per film
1
Narrated languages
6
Subtitle languages
9
Films shipped
4

This post walks through that build: how one picture stays in sync with six narrators, how the narrator grades its own takes, how the sound design follows the edit, and how a flood of molasses gets solved with fluid equations.

Scene 01The pipeline

Every film is a folder. The script is JSON, one entry per narrated line. Everything else is generated from it in order, and every stage only reads what the stage before it wrote, so any step can be rerun on its own.

  1. 01NarrationQwen3-TTS on MLX, per language
  2. 02TimelinePython, one slot per line
  3. 03Shot planTypeScript, cues for every shot
  4. 04Score + foleyNumPy and SciPy synthesis
  5. 05MixDucking per language
  6. 06SubtitlesSentence timings to SRT
  7. 07PictureRemotion, rendered muted
  8. 08Mastersffmpeg, two-pass loudness

The picture is a React app built with Remotion. Each shot is a component with a start, an end and the way it enters: slid onto the table, dropped, or a dive into the map. Shots read their times from the timeline instead of hard-coding them, so a rewritten paragraph moves every shot after it automatically.

Scene 02One picture, six narrators

The hard constraint was dubbing. German runs longer than English, Japanese packs more into fewer characters, and YouTube lets you attach several audio tracks to a single video. That means one picture has to fit every language.

The answer is a master timeline. Each narrated line gets a slot, and the slot is as long as the longest language's recording of that line, plus a breath. Every language starts its line at the start of the slot. Shorter languages just breathe a little longer.

for l in LANGS:
    text = s["text"] if l == "en" else trans[l][sid]
    d = real_dur(l, sid)          # length of the actual recording
    if d is None:
        d = est_dur(l, sid, text) # or an estimate from characters per second
    voice[l] = round(d, 3)
# slot = max(voice.values()) + GAP

Before any audio exists, the estimate uses a measured speaking rate per language, 15 characters a second for English and 7.2 for Japanese. The edit can be blocked out on day one and tightened once the real recordings land.

An engraved-style map of Scotland labelled Scotia
The Darien Scheme · maps drawn from real coastline data with d3-geo

Scene 03A narrator that grades its own takes

The narration is generated locally with Qwen3-TTS, a 1.7-billion-parameter speech model, running on Apple Silicon through MLX. It works in two passes.

The first pass designs the voice. For each language I describe the narrator in a sentence ("a deep, warm, middle-aged documentary narrator, calm and measured") and the VoiceDesign model performs a reference paragraph in that voice. The second pass clones it. The Base model reads the whole script sentence by sentence from that reference, so the voice holds from the first minute to the last.

Generation is random, so every take is checked before it is kept. The check measures the two things a listener notices straight away: speaking too fast or too slow, and dead air in the middle of a sentence.

rate = len(sent) / max(dur, 0.05)     # characters per second
gap = max_gap(a, sr)                  # longest silence inside the take
score = abs(np.log(rate / RATE[lang])) + max(0, gap - 0.7) * 2
if 0.6 * RATE[lang] < rate < 1.6 * RATE[lang] and gap < 0.8:
    break                             # good take, keep it

Up to four seeds are tried per sentence and the best-scoring take wins. Very short sentences are folded into their neighbours first, because a speech model reads "Malaria." far better as part of a longer line. Each sentence's timing is saved next to its audio, which is exactly what the subtitles need later.

Scene 04Sound that follows the edit

Sound effects are not placed by hand. Each shot in the plan carries its own cues, like a paper slide when a sheet lands on the table or a coin when a figure appears in the ledger. One command flattens the whole plan into a list of timed events:

const ev = shots.flatMap((s) =>
  s.sfx.map((e) => ({ ...e, t: +(s.start + e.t).toFixed(3), shot: s.id })),
);

When the edit changes, the sound moves with it.

The score for The Darien Scheme is synthesised in NumPy and SciPy: a harp, a drone, a fiddle and a bodhrán, for a story that begins in Scotland. In chapter five, when disease reaches the colony, a semitone starts rubbing against the drone.

The mix ducks the music under the narrator automatically. A smoothed voice-activity envelope pulls the music down 9 dB while someone is speaking and lets it back up in the pauses:

act = lp(np.abs(v), 3) > 0.01             # is the narrator speaking?
duck = lp(act.astype(np.float32), 1.5)    # smooth it, 0..1
music_gain = 10 ** ((-9 * duck) / 20)     # -9 dB under the voice

Every language gets its own mix, because every narrator pauses in different places.

Scene 05Solving a flood

In January 1919 a tank in Boston burst and sent a wave of molasses through the North End at about 35 miles an hour. I didn't want to animate that wave by hand, so I simulated it.

The wave comes from the shallow-water equations, solved with a Lax-Friedrichs scheme in NumPy. Molasses is not water, though. It thickens as it cools in the January air, and that is what made the real flood so deadly. So the friction term grows over time, and the wave slows and sets the way the real one did.

hn  = 0.5 * (hp[2:] + hp[:-2])  - dt / (2 * dx) * (F1p[2:] - F1p[:-2])
hun = 0.5 * (hup[2:] + hup[:-2]) - dt / (2 * dx) * (F2p[2:] - F2p[:-2])
# friction: visc rises as the syrup cools
un *= 1.0 / (1.0 + dt * (0.015 * np.abs(un) / np.maximum(hn, 0.05)
                         + visc / np.maximum(hn, 0.3) ** 2))

There are two simulations: a side view for the street, and a 2D version over a map of the neighbourhood, where the harbour water damps the flow at its edge.

Silhouetted Boston buildings with a wave of amber molasses flooding the street
The Great Molasses Flood · the wave is a simulation and the only colour in the film

Scene 06Every film its own look

The engine is shared. The art direction never is. Each story gets the visual language of its own time and place, tested on a short cold open before the full film is built.

Engraved boat and ships in a bay
Darien · engravings
A painted forge room framed with folk-art flowers
Banco · folk art
A gold-leaf folding screen with pine trees and waves
Gold Drain · gold leaf
Silhouetted Boston street under an elevated railway
Molasses · shadow theatre

The Darien Scheme is a rostrum camera moving over a table of engravings, ledgers and maps. Stockholms Banco, about Europe's first paper money, is painted like Scandinavian folk art. The Gold Drain, about Japan in 1859, mixes four Japanese art forms, one for each kind of scene, held together by a single rule:

Only the gold shines.

The Great Molasses Flood is shadow theatre: paper-cut silhouettes tinted by depth with fog between the layers, jointed puppets lit from behind, and nothing in colour except the molasses.

Scene 07Masters

The last stage turns the parts into files YouTube can take. The picture renders muted, and film grain is added afterwards in ffmpeg. Each language's mix is normalised to -14 LUFS with a two-pass loudness filter: the first pass measures, the second applies the exact correction, so every track plays at the same loudness. Then each language gets its own file, tagged with its language code.

ffmpeg -i mix_$l.wav -af "loudnorm=I=-14:TP=-1.5:LRA=11:measured_I=$I:measured_TP=$TP:\
measured_LRA=$LRA:measured_thresh=$TH:offset=$OFF:linear=true" -c:a aac -b:a 256k audio_$l.m4a

Subtitles come from the sentence timings saved during narration, in nine languages.

What I like most about building films this way is what it makes cheap. Moving a chapter, re-recording a line, adding a language or tightening a cue each take one command. The films are on the Ducat channel. Next I'll go deeper on the voice: designing a narrator, keeping it stable across six languages, and what makes a take sound human.