Modern video compression algorithms differ significantly from image compression techniques you're likely familiar with. The added dimensions of motion and time demand specialized mathematical and logical methods to shrink file sizes while preserving quality.
In this guide, we'll focus on H.264, a cornerstone standard that's still widely used today. Though newer codecs like H.265 exist, H.264 offers a clear window into core video compression principles.
Video compression targets spatial and temporal redundancies. By encoding repeated data minimally, file sizes drop dramatically. Picture a one-minute close-up of a face subtly shifting expressions: encoding the static background once and referencing it across frames saves space. This interframe prediction is behind those familiar compression artifacts, like parts of old frames ghosting incorrectly.

I-frames are standalone, compressed like still images using JPEG-like methods in YCbCr color space, separating luminance from chrominance for efficient motion and color handling.
Non-predictive codecs like DV or Motion JPEG stop here, yielding larger but pristine files.
Advanced codecs like H.264 insert I-frames periodically to reset the reference, balancing file size and quality. Closer I-frames mean larger files but stable playback; sparser ones risk drift. Pros tweak this via tools like FFmpeg for optimal bitrate.
Encoders predict frame-to-frame changes for efficiency, birthing P-frames (predicted from prior frames) and B-frames (bidirectional). Algorithms vary, but H.264 exemplifies this.

H.264 divides frames into 16x16 macroblocks. Rather than raw pixels, it finds matching blocks in reference frames, encoding differences via motion vectors. Playback reconstructs motion flawlessly; static blocks need no data.
Framed data undergoes Discrete Cosine Transform (DCT) into frequency coefficients, quantization rounds for compression, and entropy coding packs bits losslessly. The result: a compact, high-quality video ready for streaming or storage.
Image credit: VC Demo, TU Delft