Ch. 3 · Anatomy of a Hybrid Codec

한국어日本語
8 min

Inter Prediction and Motion Compensation: How Video Compresses Time

More than half of video compression efficiency comes from here: one motion vector says 'shift this part of the previous frame and it's nearly right'.

Inter prediction predicts the current block by taking pixels from another frame (a reference frame). It is where the 'temporal redundancy removal' from Chapter 1 is implemented. In typical video, this is the technique that saves most of the bits.

Motion vectors

The core idea is simple. If a ball moved 5 pixels to the right on screen, instead of 'redrawing the whole ball', you only need to send a single vector that says 'move this block of the reference frame by (5, 0)'.

Reference frame (t-1) Ball Current frame (t) ? MV = (+340, +20) → take the reference block as-is and use it as the prediction
How motion compensation works — the block shifted by the vector in the reference frame is used as the prediction

Of course it doesn't match perfectly. If the lighting changes or an object rotates, an error remains, and that error is the residual. Only this residual goes through transform, quantization, and entropy coding to be transmitted.

Motion estimation — the hardest job for the encoder

The process of finding 'which vector is best' is motion estimation (ME). In theory you would search the entire reference frame (full search), but that is enormously expensive. So practical encoders use heuristics such as diamond search and hierarchical (coarse-to-fine) search. A large share of encoding time is spent here.

Sub-pel motion

Real object motion doesn't land on whole-pixel boundaries. So codecs use interpolation filters to create virtual positions in the reference frame at 1/4-pixel, even 1/8-pixel, resolution.

CodecMotion vector precision
H.2641/4 pixel (luma), 1/8 pixel (chroma)
HEVC1/4 pixel (7-tap/8-tap interpolation filters)
AV11/8 pixel
VVC1/16 pixel (affine mode only), 1/4 pixel by default

Multiple reference frames and bi-directional prediction

  • Uni-directional (P) prediction — References just one past frame.
  • Bi-directional (B) prediction — References past and future frames at the same time and combines them, for example by averaging. Especially strong at predicting regions that are uncovered after being occluded (disocclusion).
  • Multiple references — Since H.264, several reference frames (up to 16) can be registered and the best one chosen. AV1 keeps frames in 8 reference buffer slots, and each frame picks up to 7 references among them, such as LAST/GOLDEN/ALTREF.
In practice — the B-frame dilemma

B-frames are very efficient to compress, but because they reference future frames, encoding order and playback order differ. This means ① the encoder needs a look-ahead buffer, which increases latency, and ② in latency-sensitive applications like live broadcast and video conferencing, B-frames are limited or turned off entirely. Whether latency or compression efficiency matters more is a design decision codec engineers have to make again for every application. How this choice shows up in real live-encoding settings is covered in Chapter 15.

Motion vector (MV)Motion vector

A coordinate offset that points to where in the reference frame to fetch the prediction block.

Motion estimationMotion estimation

The search process by which the encoder finds the optimal MV. Takes up a large share of encoding time.

Sub-pel interpolationSub-pel interpolation

A technique that uses filters to create values at virtual positions between whole pixels.

P-frame / B-frameP-frame / B-frame

Prediction frames that reference one direction / both directions (past + future).

DisocclusionDisocclusion

A region that was hidden behind another object and is newly revealed. Hard to predict from past frames alone, so bi-directional (B) prediction helps.

Check yourself

Why are B-frames, despite their good compression efficiency, avoided in live broadcast?

Check yourself

Why is sub-pel motion compensation needed?