Scheduling Dubs: The ReelDub Pipeline
I wanted to hear Instagram Reels in English without losing who was talking. Commercial dubbing is a studio product. I built ReelDub on hardware I already own: share a link from my phone, wait in a queue, get an mp4 where the voices match the speakers as closely as my models allow.
This post is about the boring center of that fantasy: how jobs get scheduled, how a worker proves it is still alive, and how the pipeline turns a URL into a dubbed file without pretending a cron job is a product.
From the iPhone share sheet
The iOS share extension is the fastest path in. I copy a Reel URL, tap Share, pick ReelDub, choose a target language and a quality preset, and the app POSTs to my server. The browser UI does the same for links I paste at a desk.
None of that work happens on the phone. The phone only enqueues. All heavy lifting runs on a Python worker next to an NVIDIA GPU, usually in Docker on a machine at home or on a small fleet node I rent for bursts.
The server stores the job in Mongo (or Postgres if I flip a flag), returns a job id, and the UI polls or streams progress while the worker mutates stage names humans can read: Downloading, Transcribing, Voicing, Encoding.
A queue, not a cron
I did not wire this as "run every night at 3am." That would hide failures and make latency arbitrary. Every dub is an explicit queued job with ordering controls: move to front, move to back, cancel. The queue is the product surface for capacity.
When I am the only user, one GPU and one worker process is enough. When friends hammer it, the same queue backs multiple workers. New work waits fairly; recovery work can jump ahead of fresh jobs so a half-finished dub does not starve behind a pile of new links.
Progress is not a spinner lie. The worker maps subprocess log lines into a small dictionary of stage labels so the API can show where time went.
LEASE = timedelta(seconds=90)
HEARTBEAT_SECONDS = 15
LEASE_MARGIN_SECONDS = 5
MAX_ATTEMPTS = 3
STAGES = {
"Waiting for GPU capacity": "Waiting for GPU",
"GPU stage: ": "Processing",
"Downloading video": "Downloading",
"Separating original": "Separating audio",
"Cleaning residual": "Cleaning background voices",
"Listening with": "Transcribing",
"Identifying speakers": "Identifying voices",
"Translating the source": "Translating",
"Synthesizing ": "Voicing",
"Reading on-screen": "Reading on-screen text",
"Translating on-screen": "Translating on-screen text",
"Mixing soundtrack": "Mixing",
"Encoding video": "Encoding",
}
Claim, lease, heartbeat
The scary failure mode is a worker killed mid-render: GPU OOM, power blip, ssh session dropped. If the job stayed "running" forever, I would babysit the database by hand.
So claim is a state machine. A worker atomically moves one eligible queued (or retryable expired) job to running and stamps a lease id plus lease_end ninety seconds in the future.
While the subprocess runs, a side thread renews the lease every fifteen seconds if progress is quiet, and sooner when stage fields change. If renewal fails because another worker won the lease or the database hiccupped, the current process backs off and exits cleanly.
If heartbeats stop, lease_end passes. The job becomes eligible again with attempt incremented, up to three tries, then failed with a plain error string. Slots tied to GPU admission release so another render can start.
That is the whole scheduler story: no Kubernetes sermon, just leases you can explain to future-you at 1am.
Pipeline stages (what actually runs)
After claim, the worker owns one render directory for the lease lifetime. The high-level flow is:
- Download with yt-dlp (respecting public visibility; restricted Reels fail with a readable error).
- Separate and clean audio so background music does not drown speech.
- Transcribe with Whisper-class models, then diarize so lines belong to speakers.
- Translate through my Index stack into the target language.
- Voice: clone or match timbre (Qwen3-TTS "Best", Kitten "Fast" when the lighter service is up).
- OCR on burned-in text when the job requests screen text; translate and mix those captions.
- Mix new speech with retained soundtrack, encode to the delivery format, upload bytes to the media store.
Each step emits log prefixes the worker maps through STAGES so the UI does not parse raw stderr.
Think of it as a conveyor: the queue feeds jobs one at a time per GPU slot; inside the slot, stages are mostly sequential because VRAM and model load costs dominate. I measured before chasing parallelism on a 16 GB card; two concurrent clips saved wall time but stretched the slowest clip and spiked memory. For my fleet notes I document those numbers honestly instead of assuming linear scale.
Fleet fencing and recovery
Single-host Compose is the default install. When I add a second GPU machine, a small fleet coordinator sits beside the API. Nodes authenticate, heartbeat, and request work only when they have a free slot.
A fleet job carries fleet_slot metadata. The coordinator accepts uploads only while the lease that claimed the job is still current. That is fencing: a zombie node cannot publish a stale render after a healthy node picked up recovery.
When a node misses heartbeats, its running job returns to the queue with recovery rank bumped so it is not stuck behind brand-new shares. Attempt counters still apply; I do not infinite-retry poisoned sources.
GPU-FLEET.md in the repo is the runbook: certificates, node identity, and the rule to run a real dub after provisioning before trusting capacity ads.
Mongo by default, Postgres optional
Job documents are wide and change shape as I add voice modes, screen-text versions, and fleet fields. Mongo fits that iteration: one jobs collection, GridFS for large media, atomic find-and-modify for claim on the default path.
Postgres is behind uses_postgres() for installs that want relational libraries and SQL reporting. Claim then delegates to a stored routine with the same candidate, exhausted, failure, and release field lists. I keep one Python claim() function so workers do not fork logic per database.
I am not religious about either store. I am religious about one claim implementation and tests that prove expired leases actually rerelease GPU tickets.
Fast vs Best voice modes
Users feel latency in Voicing. "Fast" prefers the Kitten stack when the service is healthy: lower quality bar, quicker turnaround. "Best" goes through Qwen3-TTS with upload-voice matching when the studio profile and GPU memory allow.
If someone queued Fast but Kitten is down, the worker can demote with an explicit quality_fallback message rather than silently shipping the wrong engine. Match mode (speaker timbre from the source clip) stays off lightweight workers that cannot load the matching models.
That matrix is enforced at claim time via candidate filters, not by failing halfway through a download.
Closing
ReelDub is personal infrastructure: share sheet convenience on top of a scheduler I would trust for unpaid friends. The interesting engineering is not any single model checkpoint. It is leases, heartbeats, fenced fleet handoffs, and a stage map that keeps one shared link from turning into three mystery processes on a GPU.
If you run your own copy, start with one worker, watch lease renewals in the logs, and only then add a second node. The queue will tell you when you actually need it.