encoding.info
You are hereSourcePredictionTransformEntropy codingFiltersFramesDecisionsRate controlPerceptionQualityBitstreamSettingsEncoder map
Page 2 of 5 in Prediction

Motion estimation and compensation

Prediction · concept · added 2026-11-13

You'll want firstIntra prediction
In Brief:
Nearby frames often show the same content in a slightly different place. The encoder searches a reference picture for a useful match and sends a motion vector. The decoder builds the prediction from that vector, with no search.

Nearby frames often hold the same content at slightly different positions. Motion estimation is the encoder's search of a reference picture for a useful match for each block; the answer is a motion vector. Motion compensation is the part both encoder and decoder do: build the prediction from the reference picture and the vector, with no search.

Why search at all

A good match can leave much less residual to code than an intra prediction would. The encoder sends how to get the prediction, here a vector into a reference picture the decoder already holds in reconstructed form, and codes the difference that remains. On this page the reference is the frame just before. The decoder never repeats the search; it only follows the vector.

Reference frame Current frame
Conceptual illustration. The block being coded is outlined in the current frame. In the reference frame, the dashed square is the same position and the teal square is the block the encoder chose; the arrow between them is the motion vector.

Be the motion search

A ball has rolled across a lawn between two frames. Find a match for the outlined 16×16 block: move the vector with the sliders, or click a square of the map. The score is the sum of absolute differences (SAD): the absolute difference between each sample of the current block and of the reference block the vector points at, added up. The demo ranks by SAD alone; what the vector costs comes in the next section. The vector is in whole pixels and points from the block's own position to the reference block, so it is the reverse of the ball's travel.

0
← left in the referenceright →
0
← up in the referencedown →
Reference
Current
Residual
SAD map
Vector (x, y)
SAD at this vector
Lowest SAD in the window
Simplified demo: both frames are invented source pictures; an encoder searches a reconstructed reference. The lawn is identical in the two frames apart from a little noise added to the current one, and the ball moved by a whole number of pixels. The map covers every vector within 8 pixels, 289 in all: x runs from −8 at the left to 8 at the right, y from −8 at the top to 8 at the bottom, and (0, 0) is the center. A stronger tint is a lower SAD and the outlined square is the chosen vector. The Residual panel is the selected block, enlarged: current minus prediction, mid-gray where they agree and lighter where the current block is brighter. Differences outside the gray range are clipped in the display; SAD uses the full values. No vector cost is included.

Motion search in x264

x264 does not rank a candidate by distortion alone. The vector is coded as a difference from a predicted vector, which is often the median of the vectors of three neighboring blocks. So during the whole-pixel search a candidate's score is

search score = SAD + lambda × estimated bits(vector − predicted vector)

The estimate comes from a table that grows with the logarithm of the difference; it ranks candidates and is not the block's final coding cost. Lambda is the weight on a bit; see Rate-distortion optimization. A vector that agrees with its neighbors is cheap; a costlier one needs a correspondingly lower SAD. With tesa and --subme 2 or higher, the last candidates are compared by a transformed difference instead of SAD. The settings that shape the whole-pixel search:

SettingMedium presetOther presets
--mehexdia to tesa
--merange1624 in the two slowest

--me picks the search pattern: dia in ultrafast and superfast, umh in slower and veryslow, tesa in placebo; esa is never a preset default. --merange sets the extent of the whole-pixel search, and what that means depends on the pattern. x264 accepts 4 to 1024, and for dia and hex it reduces anything above 16 to 16; smaller values stand. After the whole-pixel search comes refinement between pixels: see Sub-pixel interpolation.

Trade-offs

Sources

Read 2026-11-13, at the commit linked.