Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Video compression and MPEG

Overview of video compression principles, MPEG family structure, prediction (intra/inter), transform and entropy coding, formulas, worked examples, common exam mistakes, and quick checks.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Video is large: raw frames at typical resolutions need huge storage and high data rates for transmission. Engineers use video compression to reduce bitrate while keeping visual quality — in video streaming, conferencing, broadcasting, CCTV, and storage on devices. Understanding MPEG standards and core techniques (prediction, transform, quantisation, entropy coding) lets you choose or implement codecs and estimate resource needs.

Key ideas

Define terms before use.

  • Video compression — the process of reducing the number of bits required to represent a sequence of video frames while attempting to preserve visual quality.
  • Bitrate — the amount of data transmitted or stored per unit time; units: bits per second (bit/s or bps).
  • Codec — coder-decoder: an algorithm or system that compresses and decompresses video.
  • Intra-frame coding — compression of a frame using only data from the same frame (like image coding). The coded frame is called an I-frame.
  • Inter-frame coding — compression that uses data from other frames (prediction). Predicted frames are P-frames (forward prediction) and B-frames (bi-directional prediction). In MPEG-1/2, B-frames are not used as references; in H.264/AVC and later, B-frames may also serve as references (bi-predictive slices).
  • GOP (Group of Pictures) — a sequence pattern of I, P, B frames forming a repeating structure in MPEG streams. GOPs may be closed or open; in H.264/AVC an IDR picture starts a clean random-access point where no earlier pictures are referenced.
  • Macroblock — a block (typically 16×16 luma samples with corresponding chroma samples) used as the processing unit for motion estimation and transform coding. In 4:2:0, a macroblock contains 16×16 luma plus two 8×8 chroma (Cb, Cr) blocks.
  • Motion estimation — the process of finding a displacement (motion vector) for a macroblock from a reference frame that best predicts the current macroblock. In practice, motion vectors often have fractional-pixel precision (e.g., half-pel in MPEG-1/2, quarter-pel in H.264/AVC) using interpolation filters.
  • Motion compensation — using motion vectors and reference-frame data to predict current frame values.
  • Residual — the difference between actual block pixels and predicted block pixels; residuals are transformed and coded.
  • Discrete Cosine Transform (DCT) — a block transform that converts spatial samples into frequency coefficients. Commonly used on 8×8 blocks.
  • Quantisation — reducing precision of transform coefficients by dividing by quantisation steps and rounding; this is the main source of lossy compression.
  • Entropy coding — lossless coding stage (e.g., Huffman coding, arithmetic coding) applied to the quantised coefficients and motion data to remove statistical redundancy. In block DCT codecs, coefficients are typically zig-zag scanned and run-length coded (with EOB symbols) before variable-length/arithmetic coding.

Core pipeline (stepwise):

  1. Partition each frame into macroblocks (e.g., 16×16 luma). For chroma subsampled formats, chroma blocks are smaller.
  2. For an I-frame: apply block transform (DCT) to each block, quantise coefficients, then entropy-code.
  3. For P/B-frames: predict each block using motion estimation/compensation from reference frames; compute the residual; transform, quantise, entropy-code residual; also code motion vectors.
  4. Pack coded data into bitstream with headers, timing, and optionally error resilience. Include buffering model constraints (e.g., MPEG-2 VBV, H.264 HRD) for rate control and decoder compliance.

MPEG family (overview):

  • MPEG-1 — early standard for CD-quality video (VCD). Uses simple I/P/B structure.
  • MPEG-2 — used in digital TV and DVDs; supports interlaced video and higher bitrates.
  • MPEG-4 Part 2 (Visual) — object-based tools and improvements over MPEG-2, but less efficient than AVC.
  • MPEG-4 Part 10 (AVC, ITU-T H.264) — more advanced tools (variable block sizes, multiple reference frames, in-loop deblocking, CAVLC/CABAC entropy coding).
  • H.265/HEVC (MPEG-H Part 2) — later standard with further compression gains; AV1 is a non-MPEG codec from AOMedia with similar goals.

Precise conceptual statements students must remember:

  • Motion-compensated prediction reduces temporal redundancy by representing a block as a shifted version of a block from another frame plus a residual.
  • Transform coding (DCT) concentrates signal energy into fewer coefficients; quantisation zeros many small coefficients, creating compressibility.
  • Entropy coding compresses resulting symbols to near their entropy if models are accurate.

When drawing a diagram in an answer: draw a timeline (horizontal line) with boxes for sequential frames. Label the first as I, then P and B frames in a typical GOP pattern (for example: I B B P B B P ...). Draw arrows from P/B frames to the reference frame(s) they use: a single arrow backward from a P-frame to its past reference; two arrows (one backward to the past and one forward to the future reference) for B-frames. Note that decoding/coding order differs from display order: B-frames are transmitted after their reference frames, introducing reordering delay. Also draw a block diagram of encoder: Input frame -> block partition -> motion estimation (search) -> motion compensation + residual -> DCT -> quantiser -> entropy coder -> bitstream; include the local reconstruction loop (inverse quantiser + inverse transform + in-loop filter if present) feeding the reference frame buffer so the encoder predicts from exactly what the decoder will reconstruct. Label each block.

Formulas

Bitrate = frames_per_second × bits_per_frame — frames_per_second (Hz), bits_per_frame (bits). Applies to constant-framerate streams.

Compression_ratio = raw_size / compressed_size — both in bytes or bits; dimensionless.

MSE = (1/(N×M)) × Σ_{i=0..N-1} Σ_{j=0..M-1} (I(i,j) - K(i,j))^2 — Mean Squared Error between original I and reconstructed K; I,K in intensity (0..255 for 8-bit), units: intensity^2.

PSNR = 10 × log10(MAX_I^2 / MSE) — Peak Signal-to-Noise Ratio in decibels (dB); MAX_I is maximum possible pixel value (255 for 8-bit). Applies when MSE > 0.

2-D DCT (for an N×N block): C(u,v) = α(u) α(v) × Σ_{x=0..N-1} Σ_{y=0..N-1} f(x,y) × cos(((2x+1)uπ)/(2N)) × cos(((2y+1)vπ)/(2N)) — transform coefficient C(u,v). α(0) = sqrt(1/N), α(k) = sqrt(2/N) for k>0 — normalisation factors. f(x,y) intensity values.

Decoded_coefficient = Quantised_coefficient × Qstep — ideal scalar dequantiser mapping for reconstruction; Qstep is quantiser step size.

SAD (Sum of Absolute Differences) used in simple motion estimation: SAD = Σ_{i} Σ_{j} |current(i,j) - reference(i+dx,j+dy)| — sum over block; dx,dy are candidate motion vector components in pixels.

Symbols: Hz = s^-1; bit = dimensionless unit for information but use 'bit' or 'bps'. Verify DCT normalisation if your exam expects different convention.

Worked examples

Example 1 — Bitrate from resolution, frame rate and bits per pixel Problem: A video is 1280×720 (HD), 25 fps. After compression average bits per pixel per frame = 0.1 bits per pixel. Compute bitrate in Mbps. Steps:

  1. Pixels per frame = 1280 × 720 = 921600 px.
  2. Bits per frame = 921600 × 0.1 = 92160 bits.
  3. Bitrate = 25 fps × 92160 bits = 2,304,000 bits/s = 2.304 Mbps. Answer: 2.304 Mbps.

Example 2 — PSNR from MSE Problem: For a reconstructed 8-bit video frame, MSE = 100. Compute PSNR. Steps:

  1. MAX_I = 255.
  2. PSNR = 10 × log10(255^2 / 100) = 10 × log10(65025 / 100) = 10 × log10(650.25).
  3. log10(650.25) ≈ 2.8133; so PSNR ≈ 28.133 dB. Answer: ≈ 28.13 dB.

Example 3 — Motion estimation trace (small 4×4 blocks) Problem: Current 4×4 block C and reference candidates R0..R2 are given; compute SAD and pick best vector. Data (values): C = [52 55 61 66; 70 61 64 73; 63 59 55 90; 67 72 78 85] (rows semicolon separated). R0 = C (exact match), R1 = every element +2, R2 = every element -1. Compute SADs: SAD(R0) = 0 (identical). SAD(R1) = Σ |C - (C+2)| = 16 elements × 2 = 32. SAD(R2) = 16 elements × 1 = 16. Best is R0 -> motion vector 0 (no motion). State prediction residual = zero block. Answer: Best candidate R0 with SAD 0.

Common mistakes

  • Confusing chroma subsampling notation: 4:2:0 means chroma has half horizontal and half vertical resolution relative to luma; each chroma plane has one quarter the number of luma samples (together the two chroma planes total one half of the luma sample count). Explain briefly if you use this notation.
  • Using PSNR without stating MAX_I (bit depth); PSNR depends on bit depth.
  • Writing DCT without normalisation factors α(u), α(v) — examiners deduct marks.
  • Treating quantisation as reversible; it's lossy unless special inverse mapping is exact.

For your exam

Question types you will see: definitions (define frame types, macroblock), short notes (pipeline, MPEG features), derivations (derive bitrate formula, show DCT equations), numericals (compute bitrate, PSNR, SAD), trace of motion estimation, and diagrams (encoder block diagram, GOP timeline). What a full-marks answer includes:

  • For definitions: clear bold term, short precise statement, units if applicable.
  • For derivations: state assumptions, show each algebraic step and final formula, mention when each formula applies.
  • For numericals: list given data with units, show formulas, substitute numbers with units, show intermediate results, final answer with correct units and reasonable rounding.
  • For diagrams: draw labelled timeline for GOP, and encoder block diagram with arrows and labels for residual, motion vectors, quantiser, entropy coder.

Quick check

  1. What is the main source of loss in most video codecs? 2) Name three frame types used in MPEG. 3) Write the PSNR formula (state MAX_I meaning). Answers: Lossy quantisation of transform coefficients; I-frame, P-frame, B-frame; PSNR = 10·log10(MAX_I^2 / MSE), where MAX_I is maximum possible pixel value (e.g., 255 for 8-bit).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?