Deep Dive: Parallel Chunked Transcoding

Companion to the main guide's Processing, specifically the "encoding happens in parallel chunks, not serially" paragraph and the seam-avoidance explanation right after it. That material establishes why chunking exists and where to cut. This file goes one level deeper: how a chunk boundary decision actually gets made, how the system tracks the state of many in-flight chunks across many renditions, how a finished chunk gets validated, and how the pieces get stitched back into one file.

Also a companion to the upload-storage deep-dive — that file covers a simpler, strictly-sequential tracking problem (one growing byte offset). This one covers a harder tracking problem (many chunks, processed out of order, in parallel, across many output variants) — worth reading both back to back, because the contrast is itself instructive.

The Shape of the Problem, Before the Mechanics

A single source video doesn't produce one transcoding job — it produces M × R independent jobs, where M is the number of chunks the source is split into, and R is the number of renditions in the ladder (~20, per the main guide's Processing part). A 2-hour video split into, say, 40 scene/keyframe-aligned chunks, targeting 20 renditions, is 800 independent encode jobs, dispatched across a large worker fleet, completing in whatever order the fleet happens to get to them — not in source order, not in rendition order.

Everything below is the machinery needed to turn "800 independent, out-of-order-completing jobs" back into "20 clean, correctly-ordered rendition files."

Normalizing an Arbitrary Upload Into One Canonical Shape

Everything from Step 1 onward assumes the source is a single, well-behaved, seekable file with a consistent frame rate, pixel format, and GOP structure. A user's actual upload has no such guarantee — it could be an iPhone MOV, a decade-old camcorder AVI, a screen recording with a variable frame rate, or a 10-bit HDR file out of a mirrorless camera, in any codec and any container. Step 1's cut-list logic — "scan forward for the nearest valid cut point" — only works if "valid cut point" means the same thing for every upload. Step 0 is what makes that true.

Probe first. A fast metadata pass (the same thing ffprobe does) reads the container and stream headers without decoding the whole file: codec, pixel format, color space and transfer characteristics, frame rate (constant or variable), interlaced vs progressive, rotation metadata, audio codec/channel layout, and container type.

Then normalize into a canonical mezzanine format. The source is fully decoded once and re-encoded into an internal intermediate — typically a high-bitrate, short-GOP or all-I-frame format (e.g., ProRes or intra-only H.264/HEVC) — at a fixed pixel format, fixed color matrix, constant frame rate, deinterlaced, with rotation baked into the actual pixels instead of left as metadata. This mezzanine file, not the original upload, is what Step 1's boundary-decision pass and the 800-way chunk/rendition fan-out actually operate on.

Case that would silently break Step 1What Step 0 does about it
Variable frame rate (VFR) sources — common from phone cameras and screen recordersResampled to constant frame rate (CFR). A chunk boundary expressed as a frame number is meaningless if the frame rate isn't constant.
Telecined (3:2 pulldown) contentInverse-telecined back to true progressive frames before chunking, otherwise duplicate/interlaced-artifact frames get baked into every rendition.

HDR is handled as a branch, not collapsed away: if the source is HDR, the mezzanine preserves it (10-bit, wide gamut), and tone-mapping down to SDR happens per-rendition later, only for the renditions that need SDR output. The output of Step 0 is a single normalized, seekable master with one consistent frame rate, pixel format, and color space — the uniform input Step 1's cut-list algorithm is written to assume.

When this runs

Step 0 is not part of the upload request, and it doesn't start while the user is still uploading. It's triggered by the same event that starts everything else in the Processing part’s fan-out: the moment the upload is durable (201 Created, per the upload-storage deep-dive), a "source ready" event is published once onto the transcode queue. A worker pulls that job and runs Step 0 as its first action — before any chunk-cutting or rendition encoding — precisely once per upload, on the raw original file.

From upload completion to Step 0 running
From upload completion to Step 0 running

Step 0 runs asynchronously and exactly once per video — not once per chunk, not once per rendition — which is why it has to happen before the M × R fan-out rather than inside it: 800 independent workers each re-normalizing their own slice of an oddball source would be redundant and, worse, could disagree with each other about frame boundaries near chunk edges.

Deciding Where to Cut (the Boundary-Decision Pass)

Before any real (expensive) encoding starts, a cheap analysis pass runs over the source file once, to produce a cut list — a sequence of frame numbers (or timestamps) where it's safe to cut. Two signals feed this, combined:

Scene-cut detection. Consecutive frames are compared — typically via a color-histogram difference or per-pixel difference — and a difference far above the surrounding baseline is flagged as a hard scene cut. This is exactly the same class of analysis ffmpeg's scene-detection filter or x264/x265's scenecut option perform — well-established, standard technique, not YouTube-specific.

Forced periodic keyframes, as a backstop. Real footage doesn't reliably produce scene cuts — a long uncut interview or a static presentation slide might go 10 minutes with no detected cut at all. So independently of scene detection, the source is treated as having a forced keyframe interval (commonly every 2–4 seconds) — meaning even in a shot with zero natural breaks, there's never a stretch longer than a few seconds without a legitimate, dependency-free cut point available.

Reconciling the two against a target chunk size. The chunk splitter wants chunks that are both (a) cheap-to-cut (on a scene boundary or forced keyframe) and (b) roughly even-sized, so no single worker in the fleet gets a disproportionately large chunk that becomes the long pole for the whole job. The algorithm, at a simple level: pick a target chunk duration (say, ~2 minutes); starting from the end of the last chunk, scan forward for the nearest valid cut point closest to that target; cut there; repeat.

The output of this step is a cut list: an ordered sequence of (chunk_index, start_frame, end_frame) tuples, computed once per source video, and reused for every rendition — the same cut points apply whether you're producing the 240p H.264 chunk or the 4K AV1 chunk of that same time range, because the cut points are a property of the source's content, not of any particular output format.

What Gets Dispatched, and How It's Identified

Each unit of work dispatched to the transcoding fleet is identified by a compound key: (video_id, chunk_index, rendition_spec) — e.g., (abc123, chunk_07, 1080p_vp9). This triple is what makes it possible to track "which of the 800 jobs for this video are done" without ambiguity — every job has a unique, stable identifier that doesn't depend on when it ran or which worker ran it.

video abc123, cut list: [chunk_00, chunk_01, chunk_02, ... chunk_39]   (40 chunks, from Step 1)
rendition ladder:       [144p_h264, 240p_h264, ... 1080p_vp9, 4k_av1]  (20 renditions, from §2)

dispatched jobs = cut list × rendition ladder = 40 × 20 = 800 jobs

job key example: (abc123, chunk_07, 1080p_vp9)
  → "encode frames [start_frame, end_frame) of chunk_07,
     from video abc123's durable source (Colossus, §3),
     targeting the 1080p VP9 rendition spec"

Each job is self-contained: it names the exact byte/frame range to read from the durable source, and the exact target codec/resolution/bitrate to produce. A worker doesn't need any information about other chunks or other renditions to do its job — which is precisely what makes 800 of these dispatchable to 800 different machines with zero coordination between them.

Tracking Which of the 800 Jobs Are Done

This is the part that answers "how does it keep track of which chunk is what, which is complete, which is left." Contrast this directly with the upload-tracking problem: uploads are strictly sequential, so tracking reduces to one number (a byte offset). Transcoding jobs are not sequential — they complete in whatever order the fleet gets to them — so tracking here needs an actual index, not a counter: a small, fast-to-query record per (chunk_index, rendition_spec) key, holding a status.

chunk_indexrenditionstatusoutput location
chunk_001080p_vp9donecolossus://.../c00.vp9
chunk_011080p_vp9donecolossus://.../c01.vp9
chunk_021080p_vp9in_progress—
chunk_031080p_vp9pending—
chunk_00240p_h264donecolossus://.../c00.264
chunk_01240p_h264failed (2 retries)—
…………

This table (conceptually — the real implementation is presumably some low-latency metadata store, not literally a SQL table) is what a completion-checker queries to answer "is rendition 1080p_vp9 for video abc123 fully done yet?" — that's just "are all 40 rows for (abc123, *, 1080p_vp9) marked done?" Once they are, Step 5 (stitching) triggers for that rendition specifically. Each rendition reaches "fully done" independently and at its own pace — a slow chunk in the 4K AV1 lane doesn't hold up the 240p H.264 lane.

Handling a worker crash or a preempted machine. A job stuck in in_progress past some timeout, or one that reports failed, is simply re-dispatched — because each job's key and exact input range are already fully specified, retrying doesn't require re-deriving anything. This is only cheap because chunks are small (minutes, not hours) — a crash only costs re-doing a couple of minutes of encode, not re-encoding the entire 2-hour video from scratch.

Validating a Finished Chunk

A worker reporting "done" isn't, by itself, enough — a process can exit successfully while still having produced a truncated or corrupted output. Before a chunk's status flips to done, cheap, mechanical checks confirm the output actually matches what was expected:

  • Duration / frame-count check: the output chunk's frame count should exactly match end_frame − start_frame from Step 1's cut list. A short frame count means the encode was truncated somewhere.
  • Decodability check: the output is decoded once, end to end, immediately after encoding, specifically to catch corruption that a codec-level validity check alone might miss.
  • Boundary-frame check: since chunks are only ever cut on I-frames (Step 1), the first frame of the output chunk is checked to confirm it really is a keyframe — if it isn't, re-cutting/re-encoding that chunk is cheaper than shipping a chunk that'll produce a visible seam at stitch time.

"Complete" means all of the above checks pass, not merely "a worker process exited"; there generally isn't a quality ranking between successful chunks for the same key — a chunk that passes validation is accepted, a chunk that fails is retried, it's a binary accept/reject (unless the pipeline additionally spot-checks visual quality metrics like SSIM/VMAF against the source, a real, standard technique in large-scale transcoding pipelines, though the specifics of whether/how YouTube applies this per-chunk aren't publicly confirmed).

Stitching Validated Chunks Back Into One Rendition File

Once every chunk for a given (video_id, rendition_spec) is marked done and validated, the chunks are assembled, in original chunk order (sorted by chunk_index, not by completion order, which was essentially random), into the final rendition file. Two things make this a cheap concatenation rather than a re-encode:

  1. Consistent encoder settings across all chunks of the same rendition. Every chunk targeting 1080p_vp9 for a given video was encoded with the same resolution, codec, profile, and bitrate target — only the content differs chunk to chunk, not the format. Concatenating same-format bitstreams is cheap; concatenating different formats would require a re-encode, which chunking is specifically trying to avoid paying for.
  2. Every chunk boundary is already a clean I-frame cut (Step 1, validated in Step 4). Because no chunk depends on frames from its neighbor, there's nothing to reconcile at the join.

One real piece of re-work is required at stitch time, though: timestamp renumbering. Each chunk was encoded independently, and most encoders start their internal presentation/decode timestamps (PTS/DTS) at (or near) zero for whatever range they were handed — chunk 7 doesn't know it's supposed to start at "minute 14" of the final video. So the stitching step rewrites each chunk's timestamps to be continuous with the chunk before it before writing them into the final container. This is a metadata-level rewrite, not a re-encode — the actual compressed frame data is untouched, only the timing information wrapping it is corrected.

Timestamp renumbering at stitch time
Timestamp renumbering at stitch time

Progressive Availability, One Rendition at a Time

Because Steps 3–5 happen independently per rendition, a rendition becomes available for playback the moment its own stitching finishes — it doesn't wait for the other 19 renditions to also finish. This is the mechanism underneath the main guide's Upload part diagram ("t=+minutes: first rendition live... t=+hours: remaining renditions land progressively") — "progressively" isn't a vague description, it's literally each rendition's independent completion event firing separately as its own chunk set finishes validating and stitching. A viewer's ABR player (see Adaptive playback) simply sees a growing set of Representation entries appear in the manifest over time as each one crosses this finish line.

Dispatch, Monitoring, and Write-Back — How the Three Actually Connect

Steps 2, 3, 5, and 6 each describe one piece of this in isolation. This part walks through them as a single connected flow, because the "who does the dispatching, who's watching, where does the result land" question doesn't have one answer — it's three different mechanisms, each handing off to the next.

1. Dispatch: a queue, not a scheduler making 800 individual decisions

Once Step 1's cut list exists, a dispatcher enumerates the full cross product — 40 chunks × 20 renditions — and pushes each (video_id, chunk_index, rendition_spec) job as one message onto the transcode queue (the same queue named in the main guide's Processing part fan-out diagram).

dispatcher, once cut list is ready:
  for chunk in [chunk_00 .. chunk_39]:
    for rendition in [144p_h264 .. 4k_av1]:
      enqueue(transcode_queue, job = {video_id, chunk_index, rendition_spec, start_frame, end_frame})

→ 800 messages land on one queue

Nothing about this is a central scheduler deciding "worker #42 gets chunk_07." It's pull-based: any free machine in the transcode fleet pulls the next available message, processes it, and acknowledges completion. This is what makes the fleet self-load-balancing — a fast machine naturally pulls more jobs than a slow one — and it's also why Step 3's crash-recovery is free: an unacknowledged message simply becomes visible again after a timeout and gets pulled by whichever machine is next available.

2. Monitoring: nobody polls — completions publish, and aggregation is incremental

There is no process periodically asking "is video abc123 done yet?" by scanning all 800 rows. Instead, completion is push-driven, in two layers:

  • Per-job: when a worker finishes (chunk_07, 1080p_vp9) and it passes Step 4's validation, the worker itself writes the status row into Step 3's index. That write is the signal — there's no separate discovery step.
  • Per-rendition aggregation: each (video_id, rendition_spec) pair has an implicit counter — "how many of this rendition's 40 chunks are validated-done." Every qualifying status write increments it. The moment it reaches 40/40, that crossing fires its own event: "1080p_vp9 for abc123 is fully chunked, ready to stitch."
Per-rendition completion counter crossing its threshold
Per-rendition completion counter crossing its threshold

3. Write-back: stitch, write once to Colossus, flip one pointer

The "stitch-ready" event triggers Step 5: the 40 validated chunks are read back (by chunk_index order), PTS/DTS-renumbered, and concatenated — no re-encode. The result is written to Colossus as a single new object at a canonical path, e.g. colossus://.../abc123/1080p_vp9.mp4.

That write is followed by a metadata update — plausibly a Bigtable row transition, consistent with the pointer pattern the upload-storage deep-dive describes — from "40 individual chunk rows" to a single "rendition: done, location: colossus://.../1080p_vp9.mp4" pointer. Flipping that pointer visible is what Step 6 calls "publish": the serving/manifest layer picks it up and adds a new Representation entry, independently of whatever the other 19 renditions are doing.

The full loop, end to end

One (chunk, rendition) job, from dispatch to publish
One (chunk, rendition) job, from dispatch to publish

Every arrow in this diagram is an event, not a poll — dispatch is a queue push, job completion is a status write, rendition completion is a counter crossing a threshold, and publish is a pointer flip. Nothing in this loop waits on a clock; it waits on the previous event.

Does Dispatch Need a Transaction Between the Queue Push and the Status Write?

The natural next question: the dispatcher is touching two different systems (a queue, and a status store) — how is that kept consistent? There's no such thing as a real cross-system transaction between a queue and a separate database; no two-phase commit spans them. The honest answer has two parts: for dispatch specifically, this problem doesn't actually need solving, and for the general case where it does, here's the standard pattern.

Why dispatch itself avoids the problem: "pending" doesn't need a row

The full set of 800 job keys is deterministic — it's just cut_list × rendition_ladder, both already durable by the time dispatch runs. Nothing about "pending" needs to be written anywhere: (chunk_07, 1080p_vp9) is implicitly pending simply because no row exists for it yet. The status index only gets written to later, by workers, when they pick up a job (in_progress) or finish one (done/failed) — and each of those is a single write by a single actor, not two systems that need to agree with each other.

BEFORE dispatch:  status index has zero rows for abc123 — that's fine, "no row" == pending
dispatch:         800 messages pushed to transcode queue  (the only write)
AFTER a worker
picks up a job:   worker itself writes (chunk_07, 1080p_vp9) → in_progress
AFTER it finishes:worker itself writes (chunk_07, 1080p_vp9) → done, location=...

So dispatch has exactly one write: push to the queue. There's nothing on the database side that needs to happen atomically with it, because there's nothing on the database side that needs to exist yet.

If you do need upfront rows (the general dual-write problem)

Sometimes you genuinely want a row to exist before anything else happens — e.g., for observability, or because the job set isn't deterministic the way this one is. In that case you are doing two writes to two systems, and there are exactly two standard ways to keep them honest:

  1. Write first, then enqueue, and reconcile with a sweep. Write the row (pending) before pushing to the queue. If the process crashes between the two, you get an orphaned pending row with no message behind it — but that's a detectable, repairable state, not a silent loss: a periodic sweeper finds pending rows older than some threshold with no corresponding in-flight message, and re-enqueues them. This isn't atomicity, it's eventual consistency with a self-healing repair pass.
  2. Transactional outbox. Write the status row and an "outbox" row in one local transaction against a single transactional store, then have a separate relay process read unsent outbox rows and publish them to the queue, marking them sent once delivered. This guarantees "message published" is strictly downstream of "DB transaction committed" — at-least-once on the publish side, so consumers still need to be idempotent. This requires the status store itself to support transactions across the two rows, which plain Redis does not.

Since this pipeline's actual job set is deterministic, pattern 1 (or better, no upfront write at all) is the right fit here — pattern 2 becomes relevant for less deterministic fan-outs elsewhere in the pipeline (e.g., a Content ID fingerprint match writing a row and needing to notify a review queue).

"Pull and Forget" — What Actually Catches a Failure Mid-Processing

The instinct that "some background job must be watching the status store, spot a stuck in_progress row, and re-push it" is reasonable, but it's not the primary mechanism — and building it that way would duplicate something the queue already does for you.

The primary mechanism is built into the queue itself: a visibility timeout (SQS's term) / ack deadline (Pub/Sub's term) / consumer-group PEL + XCLAIM (if literally using Redis Streams). When a worker pulls a job, the message becomes invisible to every other consumer for a fixed window — long enough to cover a normal encode. If the worker finishes and acknowledges within that window, the message is deleted for good. If it doesn't — the worker crashed, got preempted, hung — nothing needs to notice anything: the message simply becomes visible again automatically once the window expires, and the next free worker pulls it.

Visibility-timeout retry, no scanner involved
Visibility-timeout retry, no scanner involved

Where a background sweep genuinely does earn its keep: poison messages. If a job keeps getting redelivered and keeps failing — not a one-off crash, but a job that's fundamentally broken — most queue systems cap retries at some count and then move the message to a dead-letter queue (DLQ) instead of redelivering forever. Step 3's failed(2) status is tracking exactly this: a delivery-attempt counter. A separate process — alerting, or a human-facing dashboard — watches the DLQ for jobs the automatic retry already gave up on.

So there are two distinct layers, not one: the visibility-timeout retry (automatic, built into the queue, handles ordinary crashes/preemption) and the DLQ/staleness sweep (a genuine background watcher, but scoped narrowly to jobs the automatic retry already gave up on).

Putting the Whole Pipeline Together

Steps 1 through 6, end to end
Steps 1 through 6, end to end