35 · interactive
Visualize / 35

How video compression works.

Most frames in a video look almost identical to the one before. Modern codecs (H.264, HEVC, AV1) exploit that: a few full-quality "keyframes" (I-frames), and many smaller frames that only encode the differences (P and B-frames). Toggle between motion-compensated and all-keyframe to see the ~5× size difference.


24 FRAMES · 1 SECOND @ 24fps If1100KB Bf212KB Bf312KB Pf430KB Bf512KB Bf612KB Pf730KB Bf812KB Bf912KB Pf1030KB Bf1112KB Bf1212KB If13100KB Bf1412KB Bf1512KB Pf1630KB Bf1712KB Bf1812KB Pf1930KB Bf2012KB Bf2112KB Pf2230KB Bf2312KB Bf2412KBSECOND TOTAL572 KBavg 24 KB/frame · 4.6 MbpsRATIO vs ALL-I4.2× smallerGOP IBBPBBPBBPBBI · same contentFRAME TYPESI · Intra · full keyframe · ~100 KBP · Predicted · diff from previous I/P · ~30 KBB · Bi-directional · diff from prev and NEXT · ~12 KBB-frames need future reference → encode out-of-order, reorder at displayGOP · GROUP OF PICTURES · keyframe every 12 frames (~0.5 sec @ 24fps)GOP 1 · frames 1-12GOP 2 · frames 13-24netflix average · ~5 Mbps for 1080p · 629 frames/sec equivalent

Why most frames can be tiny

Adjacent video frames are 95-99% the same pixels. The camera moves, lighting changes, objects shift, but most pixels just don\'t change much frame to frame. A P-frame says "almost like frame N-1, with these specific patches moved by these vectors and these residuals." A B-frame does the same but can also reference the NEXT frame (which is why decoding order ≠ display order). The result: average frame size is a fraction of what each would be standalone.

Scene cuts and the I-frame budget

At a scene cut, the previous frame is useless as a reference — everything\'s different. The encoder detects the scene change and inserts an I-frame. This is why fast-cut videos (action movies, sports highlights) are larger per minute than slow videos (talking heads). It\'s also why scrubbing in a player snaps to I-frames — random seek can\'t start mid-GOP because P/B frames depend on their reference frames.

H.264 vs H.265 vs AV1

H.264 (AVC, 2003) was the watershed — quality + size + compatibility nobody else could match for 15 years. H.265 (HEVC, 2013) compresses ~50% better but has licensing landmines. AV1 (AOMedia, 2018) compresses ~30% better than H.265, is royalty-free, and is what YouTube/Netflix push when your hardware supports it. Encoding AV1 is currently 5-10× slower than H.264; decoding catches up as hardware ships. The general law: each generation roughly halves the bitrate for the same quality, at 5-10× the encode cost.

Go deeper

Codecs and compression →

DCT and entropy coding, motion estimation algorithms, rate control, bitrate ladders, HDR + 10-bit, why hardware decoders matter for battery life.

Open the Codex →
Found this useful?