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

Sub-pixel interpolation

Prediction · concept · added 2026-11-13

In Brief:
Motion rarely lands on whole pixels. A motion vector can point between pixels if both sides compute the in-between samples from the reference with the same filter, and the closer match can leave a smaller residual.

Objects do not check the pixel grid before they move. A pan of two and a third pixels leaves every whole-pixel motion vector slightly wrong. Sub-pixel interpolation lets a vector point between pixels: the encoder and the decoder compute the in-between samples from the reference frame with the same filter, and the prediction is read from those.

Try a move that misses the grid

Below is one row of pixels from the current frame, after the content has shifted, and the prediction built for it from the reference row. Set the true shift, then choose how finely the vector may point. A positive shift moves the content to the right, and the vector points back to where it was, so its sign is negative. The search keeps the allowed vector with the lowest sum of absolute differences.

← no motion2 pixels →
Current rowPredictionResidual, ×3
Whole pixelHalf pixelQuarter pixel
True shift, pixels
Best vector, pixels
Mean absolute error
Simplified demo: the row is an invented continuous signal with fine detail, sampled exactly at the shifted positions, so the true shift is known. Mean absolute error is the mean absolute difference per pixel between the current row and the prediction, over the 30 pixels drawn, in 8-bit code values. In the upper plot the left scale is the sample value, and the residual bars have their own zero line, marked 0 below the curves. The lower plot shows the error at 65 shifts, 1/32 of a pixel apart, with the chosen filter; the dot is the current setting. The demo is one row, keeps fractions and does not clip; real filters work in two dimensions and round to integers. Quarter positions are the average of the two nearest whole or half samples, as H.264 does along a row.

Two things are separate here: how precisely the vector states the displacement, and how accurately the filter rebuilds samples at that position.

Where the in-between samples come from

No camera recorded them. H.264 and HEVC each define the filters, because the decoder must produce the identical prediction; in these codecs they are not an encoder choice. The luma filters, read from x264 and x265 (High Efficiency Video Coding, HEVC):

H.264 half:       1  -5  20  20  -5   1        / 32
HEVC half:       -1   4 -11  40  40 -11  4 -1  / 64
HEVC quarter:    -1   4 -10  58  17  -5  1  0  / 64

The quarter row is one of the two quarter positions; the other uses the same weights in reverse order.

1−52020−51
Conceptual illustration of the H.264 half-pixel filter: six whole pixels, weighted and summed, then divided by 32, give the sample halfway between the middle two. The negative weights help keep fine detail that a plain average of two neighbors loses.

Sub-pixel search in x264

x264 filters each reference frame once into three extra planes: half a pixel across, half a pixel down, and both. A quarter-pixel prediction is then the average of two samples from those planes and the original, so trying a quarter-pixel vector costs an average, not a six-tap filter. Chroma is interpolated with straight-line weights; for 4:2:0 video that is at eighths of a chroma pixel.

--subme sets how much refinement follows the whole-pixel search, as a number of rounds that can end early. At 0 there is none and vectors stay on whole pixels. At 1 only the partition finally chosen is refined, with one half-pixel and one quarter-pixel round. At 2 and 3 every search gets one half-pixel round, and the quarter-pixel rounds are left for the partition chosen. From 4 every search gets quarter-pixel rounds as well; the medium preset, 7, sets two rounds of each. Higher values also change how candidates are scored, which is on Distortion measures.

Trade-offs

Sources

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