Skip to main content

YouTube: Upload & Processing Deep Dives

Editorial

How does a 10 GB upload survive a broken connection?

One Request Cannot Resume

The simplest upload is one PUT of the whole file. If the connection breaks, nothing is kept: in our test against MinIO (an S3-compatible store), 4 MiB of an 8 MiB PUT arrived before the connection dropped, and afterwards no object existed. The next attempt starts again from byte 0 — for a 10 GB file broken at 80%, eight gigabytes again.

Two Ways to Resume

Object stores solve this in two ways, and both work with uploads that go straight from the client to storage:

Google Cloud Storage (and YouTube's Data API)Amazon S3
Shapeone session; the file is sent in chunks, in ordera multipart upload; each part is its own PUT
Sizeschunks in multiples of 256 KiBparts of at least 5 MiB (except the last), at most 10,000
After a breakan empty PUT with Content-Range: bytes */SIZE; the answer, 308, says which bytes arrivedlist the parts already stored; send the rest
Finishingthe last chunk completes the objecta request listing every part completes it
Lifetimea session "remains active for up to a week"until completed or aborted; Amazon recommends a lifecycle rule with AbortIncompleteMultipartUpload to delete the abandoned ones
Resuming an upload: ask what arrived, send the rest. In Google's protocol an empty PUT returns the bytes the server holds. A 64 MiB file is sent in 8 chunks of 8 MiB; chunks 1 to 5 arrive, and the connection drops during chunk 6. The client sends an empty PUT with Content-Range: bytes */67108864; storage answers 308 with Range: bytes=0-41943039, the five chunks it holds. The client resends chunk 6 as bytes 41943040-50331647, answered 308 with Range: bytes=0-50331647, then the rest; the last chunk is answered 201 Created. Chunk sizes are multiples of 256 KiB; a session lives up to a week; S3's multipart upload instead lists the parts it holds, and the client sends the rest.

We ran the multipart version: a 26 MiB file in six parts, five of 5 MiB and a last one of 1 MiB. The client sent three, then "crashed". The resumed client asked the store, which listed parts 1, 2 and 3 — 15 MiB that did not have to travel again — and sent the other three. The completed object's SHA-256 equalled the file's. Two details matter for a real system:

  • The ETag is not a checksum of the file. The finished object's ETag ended in -6, the number of parts: a multipart ETag is built from the parts. So the client declares the file's SHA-256 when it starts, and the server checks it before anything is processed.
  • Too-small parts fail late. A 1 MiB first part was accepted when sent and refused only at completion, with EntityTooSmall. The client must size its parts from the start.

Where a session starts matters too: "Resumable uploads are pinned in the region where you initiate them" — a session opened in the US for a client in Asia carries every byte across the Pacific. The upload service therefore opens each session in the region nearest the uploader.

What a Signed URL Grants

Uploads bypass the API servers: the API hands the client a URL that object storage accepts without the user's credentials. We tested what such a URL allows, with S3 signature version 4 (AWS4-HMAC-SHA256) against MinIO:

AttemptResult
PUT with the URL200, stored
GET with the same URL403, SignatureDoesNotMatch — the method is part of the signature
PUT by a second client with no credentials, holding only the URL200 — the object now held that client's bytes
PUT with the object key changed in the URL403, SignatureDoesNotMatch
PUT one second after the URL expired403, AccessDenied
PUT of 8 MiB, nothing about size in the signature200
The same with the length signed (content-length;host), sending 2 MiB403
A form upload (POST policy) limited to 1 MiB, sending 2 MiB400, EntityTooLarge
A signed URL is a bearer credential: eight attempts with one presigned PUT URL against an S3-compatible store. The signature covers the method (PUT), the object key, the expiry (10 minutes) and the signed headers (host); change any of them and the store answers 403. It does not cover who sends the request, nor how many bytes, unless the length is signed. Results: the intended PUT, 200, stored; a GET with the same URL, 403; a stranger's PUT with no login, 200, and it overwrote the object; the object key changed, 403; one second after expiry, 403; 8 MiB with no size in the signature, 200, stored; the length signed but 2 MiB sent, 403; a form upload whose policy allows 1 MiB, sent 2 MiB, 400, too large.

The third row is the one to remember. A signed URL is a bearer credential: Google's documentation says "anyone who possesses it can use the signed URL to perform specified actions, such as reading an object, within a specified period of time." Both stores cap a version-4 URL at 7 days. So the design limits what a leaked URL can do:

  • One fresh object key per session. A leaked URL can overwrite only its own unfinished upload, never a published video or someone else's.
  • Short lifetimes, a bounded size. Sign the exact length, or use a form upload with content-length-range; a plain signed PUT takes any size.
  • Check before use. Processing starts only after the stored object's SHA-256 matches the one the creator's authenticated client declared.

How the URL is signed depends on the store. S3's version 4 derives an HMAC key from the secret access key. Google Cloud Storage signs with RSA-SHA256 using a service account's private key, or with an HMAC key. Either way the store recomputes the signature over the method, the path, the expiry and the signed headers, which is why changing any of them fails.

Faster Uploads

Uploading in parallel helps only while one connection cannot fill the link — high latency, losses, a per-connection cap. When the link itself is full, splitting the file changes nothing: 10 GB over 50 Mb/s takes 1,600 seconds, about 27 minutes, however it is cut. What does help is starting the session near the uploader, keeping chunks large enough that per-request overhead stays small, and resuming instead of restarting.

Re-encoding on the phone to shrink the upload does not help either. A fast preset needs more bits for the same quality: on our busy scene x264's veryfast preset reached VMAF 94.8 at 6.1 Mb/s, where its default preset reaches the same VMAF at about 4.5 Mb/s — 37% more. A smaller file means lower quality instead, and processing re-encodes the upload anyway; YouTube recommends uploading at bit rates such as 8 Mb/s for 1080p and 35–45 Mb/s for 2160p.

Which codecs, and what do they cost?

Three Codecs, Measured

A codec trades bits against computing: the newer ones need fewer bits for the same picture and more work to find them. We measured the trade on two 10-second scenes of Tears of Steel (1920×800, 24 frames a second) — the calmest and the busiest 10 seconds of the film by bit rate at a fixed quality — scoring every encode with VMAF, the perceptual quality metric Netflix built and open-sourced. Each codec ran as its makers recommend for on-demand video: H.264 with x264's default preset, VP9 in two passes with Google's VOD settings, AV1 with SVT-AV1 preset 6.

Three codecs, measured: the saving depends on the scene. Quality (VMAF) against bit rate on a log scale, for the calmest and the busiest 10 seconds of Tears of Steel at 1920 by 800, encoded with H.264 (x264), VP9 (two passes, Google's settings) and AV1 (SVT-AV1). For VMAF 93 the calm scene needs 0.52 Mb/s with H.264, 0.25 with VP9 and 0.18 with AV1; the busy scene needs 3.48, 3.27 and 2.44. VP9 saves much more on the calm scene than on the busy one; AV1 saves about 30% over VP9 on both, and the busy scene needs 7 to 14 times the bits of the calm one.
Bit rate for VMAF 93Calm sceneBusy scene
H.2640.52 Mb/s3.48 Mb/s
VP90.25 Mb/s3.27 Mb/s
AV10.18 Mb/s2.44 Mb/s

Averaged over the streaming range (VMAF 80–96):

  • VP9 against H.264 saved 49% on the calm scene and only 10% on the busy one.
  • AV1 against VP9 saved 30% and 31% — the one saving that held on both.
  • AV1 against H.264 saved 65% and 37%.

There is no single "VP9 is 30% better" number: the saving depends on the content. The busy scene also needed 7 to 14 times the bits of the calm one for the same quality — the reason a fixed ladder wastes bits on simple videos (next section).

What the Saving Costs

We timed each encoder on the busy scene, reading it as raw frames so that decoding the source costs nothing — decoding our lossless copy of the scene alone took 0.53 CPU-seconds per second of video, enough to distort a comparison:

Encoder (busy scene)CPU-seconds per second of videoBit rateVMAF
x264, default preset (CRF 23)1.316.5 Mb/s97.1
x264, veryfast (CRF 23)0.476.1 Mb/s94.8
VP9, two passes, Google's VOD settings (CRF 36)9.335.7 Mb/s96.2
SVT-AV1, preset 6 (CRF 36)2.385.2 Mb/s95.8
SVT-AV1, preset 10 (CRF 36)0.616.2 Mb/s93.3

VP9 took 7.1 times the computing of H.264 — YouTube's own account says "data-efficient video codecs like VP9 use more computer resources to encode than H.264." AV1 is not uniformly slower: SVT-AV1, an encoder built for this scale, took 1.8 times H.264 at preset 6, and at preset 10 less than half — for a lower VMAF.

What the saving costs: CPU-seconds to encode one second of the busy scene of Tears of Steel, with the bit rate and VMAF reached. x264 at its default preset 1.31 (6.5 Mb/s, VMAF 97.1), x264 veryfast 0.47 (6.1 Mb/s, 94.8), VP9 in two passes with Google's settings 9.33 (5.7 Mb/s, 96.2) — 7.1 times H.264 — SVT-AV1 preset 6 2.38 (5.2 Mb/s, 95.8) and preset 10 0.61 (6.2 Mb/s, 93.3). Apple's real-time hardware H.264 encoder took 0.8 seconds for the 10-second scene against 1.5 for x264, but at the same bit rate scored VMAF 89.7 against 96.4 at 5.7 Mb/s and 73.1 against 86.8 at 1.8 Mb/s. YouTube's own transcoding chip, described in 2021: up to 20 to 33 times the compute efficiency of its software, and VP9 on it needs 30% fewer bits than software H.264.

YouTube's Answer: Its Own Chip

YouTube began designing a transcoding chip in 2015 and described it in 2021: the Video Coding Unit. "We've seen up to 20-33x improvements in compute efficiency compared to our previous optimized system, which was running software on traditional servers." Hardware gives up a little quality — "VCU H.264 encodings are on average 11.5% higher BD-rate than libx264, and VCU VP9 is 18% greater BD-rate than libvpx" — and still wins overall: "VCU leverages the improved coding efficiency of VP9 relative to H.264 to achieve 30% BD-rate improvement relative to libx264. The high compute cost of VP9 makes it computationally infeasible at scale in software."

A general-purpose hardware encoder is not a substitute. Apple's VideoToolbox, the real-time H.264 encoder in Macs and iPhones, ran the busy scene in 0.8 seconds against x264's 1.5 — and at x264's bit rates scored VMAF 89.7 against 96.4 at 5.7 Mb/s, and 73.1 against 86.8 at 1.8 Mb/s. Real-time encoders are built for speed; a chip for an archive is built for quality per bit.

Which Codecs to Keep

CodecPlays onRole
H.264everythingthe fallback; Apple's streaming guide says "For backward compatibility, some video content SHOULD be encoded with H.264"
VP9Chrome, Firefox, Edge, Android; Safarithe main format where it decodes in hardware
AV1Chrome, Firefox, Edge; Safari "only on devices with hardware decoder, e.g. iPhone 15 Pro, M3 MacBook Pro"the most efficient, where the device can play it

The newest codec is worth its encoding cost where the bits it saves are delivered many times: a video watched a million times pays for its AV1 encode in bandwidth; one watched 35 times — the median — may not. So the scheduler can encode the compatible codecs first for every video and the most efficient codec for videos whose views justify it.

What does a ladder weigh, and who chooses it?

What a Ladder Weighs

A ladder is the set of renditions a video is offered in: resolutions, each with a bit rate, for each codec. We encoded the 20 seconds of Big Buck Bunny (4K, 30 frames a second) whose source bit rate is the film's median, three ways: VP9 exactly as Google's VOD table prescribes for each frame size, H.264 at the bit rates of Apple's HLS table, and AV1 with SVT-AV1 at one quality setting.

All three ladders weigh about one upload: measured on 4K Big Buck Bunny, in Mb/s, against YouTube's upload advice of 35 to 45 Mb/s for 2160p30. VP9 with Google's settings, 7 rungs from 240p to 2160p: 19.5 Mb/s, of which 2160p is 11.06 and 1440p 4.84. H.264 with Apple's ladder, 6 rungs from 234p to 1080p: 12.1 Mb/s, 1080p being 5.90. AV1, 7 rungs: 10.9 Mb/s. All three together: 42.5 Mb/s. The upload itself, an H.264 file, was 7.6 Mb/s. On a 1080p screen the VP9 rungs scored VMAF 95.3 at 1080p (1.70 Mb/s), 90.2 at 720p (0.90), 83.9 at 480p (0.65), 69.5 at 360p (0.26) and 49.1 at 240p (0.15).
RungVP9 (Google's table)H.264 (Apple's table)AV1 (SVT-AV1)
2160p11.06 Mb/s—4.65 Mb/s
1440p4.84—2.60
1080p1.70, VMAF 95.35.90, VMAF 97.41.71, VMAF 95.7
720p0.90, VMAF 90.22.94, VMAF 93.40.93, VMAF 90.9
480p (H.264: 432p)0.65, VMAF 83.90.73, VMAF 81.20.51, VMAF 83.0
360p0.26, VMAF 69.50.37, VMAF 70.80.34, VMAF 73.8
240p (H.264: 234p)0.15, VMAF 49.10.15, VMAF 44.60.20, VMAF 54.6
Whole ladder19.5 Mb/s12.1 Mb/s (plus a 540p rung)10.9 Mb/s

VMAF here is measured on a 1080p screen, so the small rungs score low; on a phone they look far better. Two conclusions follow:

  • The renditions are not a multiple of the upload. All three ladders together come to 42.5 Mb/s, about what YouTube advises a 4K upload to be (35–45 Mb/s). For a 1080p upload at the advised 8 Mb/s, the VP9 and H.264 ladders up to 1080p come to 15.7 Mb/s, about twice the upload. Storage grows by one to a few times the uploads, not by an order of magnitude.
  • A fixed table wastes bits on easy content. VP9's settings cap the bit rate but let the encoder spend less when the picture is simple; at 1080p it used 1.7 Mb/s of its 1.8 Mb/s target. The H.264 table fixes the rate, so the same rung spent 5.9 Mb/s on the same simple film.

Per-Title Encoding

The codec measurements showed the busy scene needing 7 to 14 times the bits of the calm one for the same VMAF. A ladder chosen per video spends bits where the picture needs them. Netflix introduced it in 2015: "We've spent years developing an approach, called per-title encoding, where we run analysis on an individual title to determine the optimal encoding recipe based on its complexity." For one title they report: "At the high end, the new per-title encoding assigns 4640 kbps for the highest quality 1080p encode. This is 20% in bitrate savings compared to 5800 kbps for the fixed ladder scheme."

Per-title encoding costs extra encodes to find the ladder, so it pays where views are many: a popular video's ladder is worth refining; one watched 35 times is not.

How does the processing graph run, and in what order?

The Graph in a Table

Each upload's processing is a set of tasks with dependencies — probe the file; check it; for every rung an encode and then a package step; publish when the low path and the check are done. The graph lives in the tasks table of the data model, one row per task, with the tasks it needs and a priority. Workers take tasks with one statement:

-- take one task whose needs are all done, and lease it for five minutes
UPDATE tasks t
   SET state = 'running', attempts = attempts + 1, lease_until = now() + interval '5 minutes'
 WHERE (t.video_id, t.task) = (
         SELECT c.video_id, c.task
           FROM tasks c
          WHERE (c.state = 'waiting' OR (c.state = 'running' AND c.lease_until < now()))
            AND NOT EXISTS (SELECT 1 FROM tasks d
                             WHERE d.video_id = c.video_id AND d.task = ANY (c.needs) AND d.state <> 'done')
          ORDER BY c.priority, c.video_id, c.task
          LIMIT 1
          FOR UPDATE SKIP LOCKED)
RETURNING t.video_id, t.task, t.attempts;
  • Ready only. A task is taken only if every task it needs is done.
  • No double work. FOR UPDATE SKIP LOCKED makes concurrent workers pass over a row another worker is taking, instead of waiting for it or taking it too.
  • A lease, not a lock. The worker gets five minutes; a task whose lease ran out is taken again, so a crashed worker delays its task by the lease, nothing more.
  • Fencing. The worker reports success with UPDATE … WHERE state = 'running' AND attempts = <its attempt>. A worker that was presumed dead and finishes late names an old attempt and changes nothing.

We tested these on PostgreSQL 17. The schema refuses a state it does not know (published fails the CHECK). A task claimed by one worker could not be claimed by another while its lease ran; once the lease ran out it was taken again as attempt 2, and the first worker's late report changed 0 rows. Four workers ran the 29 tasks of one upload's graph with no task starting before its needs ended and none taken twice.

The Order Decides When It Plays

The same graph of one 20-second 4K upload, the same four workers, three orders — each task taking its measured time (the encodes as timed reading the H.264 upload, over a worker's four cores):

The order of the tasks: playable at 7 seconds, not 53. One 4K upload's processing graph on 4 workers, with measured task times: 13 encodes (H.264 to 1080p, VP9 to 2160p) and the check, drawn in worker lanes over time. First created, first taken: the H.264 encodes go first, the 360p one in the second round, and publishing waits its turn, so the video is playable at 53 seconds; all renditions are done at 172 seconds. The 360p path first, then the longest encodes first: the 360p H.264 encode starts at once and the video is playable at 7 seconds; the 2160p and 1440p VP9 encodes start at once too, and everything is done at 162 seconds — the 2160p VP9 encode alone takes 161.
OrderPlayableAll renditions done
First created, first taken53 s172 s
Low path first, then by height7 s187 s
Low path first, then the longest encode first7 s162 s

The low path first makes the video watchable at once. What follows decides when the last rendition is ready: the 2160p VP9 encode alone took 161 seconds, so the graph cannot finish sooner, and starting it early reaches that bound. Started last, it pushes everything out by 25 seconds. The scheduler therefore orders by two rules: the path to the first playable version, then the longest work.

Checks Before Publishing

The check runs beside the low path and gates publish. It covers the platform's rules and copyright: "Using a database of audio and visual files submitted by copyright owners, Content ID identifies matches of copyright-protected content. When a video is uploaded to YouTube, it's automatically scanned by Content ID." Matching compares the video's sound and pictures with the reference files, so it must read every frame; we time it as one full decode of the upload. A match can block the video, which is why blocked is a state of its own.

How is one video encoded on many machines?

One Video, Many Workers

A worker encodes one rendition, but one rendition of a long 4K video is hours of computing. Cutting the video into chunks lets many workers encode one rendition at once. We cut 120 seconds of Tears of Steel into chunks at keyframes and encoded them in parallel with the same settings:

Chunked encoding: 2.6 times faster, the same video. 120 seconds of Tears of Steel are cut at keyframes into 5 chunks of 24 seconds, each encoded by its own worker, and joined by concatenation without re-encoding. Wall clock on a 10-core laptop: one worker 48.4 seconds (113 CPU-seconds, VMAF 95.33); 5 chunks on 5 workers 18.5 seconds (175 CPU-seconds, VMAF 95.32, the file 0.4% bigger); 10 chunks on 10 workers 19.0 seconds (170 CPU-seconds, VMAF 95.30, 0.7% bigger). All 2,880 frames in each, no decode errors; the speed-up stops where the laptop's cores run out.
RunWall clockCPU-secondsSizeVMAF
One worker, whole video48.4 s113—95.33
5 chunks of 24 s, 5 workers18.5 s (2.6×)175+0.4%95.32
10 chunks of 12 s, 10 workers19.0 s (2.5×)170+0.7%95.30

The joined files had all 2,880 frames and decoded without an error; they were 0.4–0.7% bigger, the small price of starting each chunk afresh. The speed-up stopped at 2.6× because all workers shared one laptop of ten cores, six of them slower efficiency cores, and the same work took half as many CPU-seconds again. Across machines, the wall clock approaches the time of the slowest chunk.

Chunking needs cuts at keyframes the encoder will keep, so each chunk decodes on its own and the joined file is seamless. The same requirement appears again for the player, below.

How do segments let the player switch quality?

Segments a Player Can Switch Between

The player changes quality between segments. That works only if every rendition's segments start at the same instants, each with a keyframe (an IDR frame) that decodes without earlier frames. Apple's HLS rules say it outright: "Video segments MUST start with an IDR frame", "Key frames (IDRs) SHOULD be present every two seconds", "Target durations SHOULD be 6 seconds", and "Media Segments MUST NOT exceed the target duration by more than 0.5 seconds."

Encoders do not do this on their own. We measured where they put keyframes:

A player switches only at shared keyframes: where encoders put keyframes, and the segments a packager could cut. x264 with its defaults put keyframes at scene cuts in 60 seconds of Tears of Steel, so a DASH packager asked for 4-second segments could only cut 8 segments of 10.4, 4.5, 5.0, 5.9, 7.1, 5.7, 10.4 and 11.0 seconds. With a keyframe forced every 2 seconds it cut 15 segments of exactly 4 seconds, the same in every rendition. VP9 with Google's VOD settings, which let the encoder place keyframes: across the seven rungs of 20 seconds of Big Buck Bunny, six rungs had keyframes at 0, 4.93, 5.57, 8.23, 10.70, 14.37 and 16.90 seconds; the 240p rung had none at 10.70, so a player cannot switch there.
  • x264 with its defaults put keyframes at scene cuts — at 10.4, 14.9, 19.9 s and so on. Asked for 4-second segments, ffmpeg's DASH packager could cut only 8 segments, of 4.5 to 11.0 seconds. Here the two renditions happened to get the same keyframes; nothing guarantees it.
  • VP9 with Google's VOD settings — keyframes "up to 240 frames" apart, which "allows the encoder to choose the best placement of keyframes" — gave six rungs keyframes at the same seven instants, but the 240p rung lacked the one at 10.70 s. A player could not switch to or from 240p there.
  • A keyframe forced every 2 seconds in every rendition gave 15 segments of exactly 4 seconds in both renditions.

So the encode tasks of a ladder all force keyframes at the same fixed interval, and scene-cut keyframes are switched off or kept only in addition. The cost is a few extra keyframes; the gain is that every segment boundary is a switch point in every rung.

Packaging

Packaging cuts the encoded file into segments and writes the manifests, without encoding again. The same aligned encode can serve both formats: DASH (an MPD listing each representation's segments) and HLS (a playlist per rendition — published as RFC 8216, an Informational RFC). Packed as HLS with fMP4 segments of 6 seconds, our aligned 1280×534 rendition became 10 segments, a target duration of 6 and one initialization segment (EXT-X-MAP). Both formats can carry the same fragmented-MP4 segments, so one copy of the bytes can serve every player.

Starting Before the Upload Ends

Processing could start before the last byte arrives, if the partial file can be read. An MP4 has an index, the moov box, that says where every frame is; ffmpeg writes it at the end by default. We cut three 30-second files at their halfway byte:

Half an MP4 is readable only if the index comes first: 30 seconds of video in three layouts, each cut at its halfway byte, as if the upload had stopped there. With ffmpeg's default layout the index (moov) comes after the media data, so the first half has no index: it does not open and no frames decode. With the index first (+faststart) the first half opens and 389 of the 720 frames decode. A fragmented file, with a small index before each fragment, also opens and decodes 389 of the 720 frames. Processing can begin before the upload ends only with the index first.
LayoutFirst half
Index at the end (ffmpeg's default)does not open: "moov atom not found"
Index first (+faststart)opens; 389 of 720 frames decode
Fragmented (an index per fragment)opens; 389 of 720 frames decode

Uploads come in whatever layout the camera or editing software wrote, and ffmpeg's own default puts the index last. So the design waits for the complete, hash-checked upload before processing; early processing is an optimisation only for files that put the index first.