Edge-Pixel Padding in AV1 Motion Compensation

Edge-pixel padding in the AV1 video codec ensures that motion compensation operates smoothly when motion vectors point beyond the boundaries of a reference frame. Because sub-pixel interpolation filters require surrounding context to calculate fractional positions, fetching pixels near or past frame borders risks reading undefined memory or introducing boundary artifacts. AV1 solves this by mathematically clamping out-of-bounds coordinates to the nearest valid edge pixels, creating an extended border of duplicated edge data that allows motion compensation loops to maintain reconstruction accuracy across the entire frame.

The Boundary Reference Problem

In motion compensation, a macroblock or coding block in the current frame predicts its content by referencing a previously decoded frame. Motion vectors often displace references across the outer edge of a picture, especially when an object enters or leaves the scene.

AV1 utilizes separable directional interpolation filters, typically 8-tap or 4-tap filters, to achieve half-pixel and quarter-pixel accuracy. An 8-tap filter requires up to four pixels of context to either side of the target coordinate. When the prediction block sits close to a border, the filter window naturally overshoots the frame boundary. Without a padding mechanism, these filters would either produce severe edge distortion or crash decoder implementations through invalid memory access.

Edge Clamping Logic

AV1 handles boundary extensions at the algorithmic level using sample coordinate clamping. When computing the source coordinates \((x, y)\) in the reference frame, the codec clamps the index values to the outer boundaries of the picture area:

Under this rule, any horizontal read past the left edge repeats the pixel at index \(0\), while reads past the right edge repeat the pixel at \(\text{Width} - 1\). The vertical borders replicate the top and bottom rows respectively. When a coordinate exceeds both axes simultaneously, it clamps to the nearest corner pixel, resulting in an outward orthogonal and diagonal replication of the boundary.

Sub-Pixel Interpolation Integration

During motion compensation, the interpolation filters apply their weights directly to these clamped pixel arrays. Because the padding simply stretches the edge values, the filter applies its coefficients across a plateau of identical numbers when deeply out of bounds. This eliminates ringing artifacts and prevents artificial edges—such as zero-value black borders—from polluting the motion-compensated prediction block.

Practical Buffer Implementation

While the AV1 specification defines edge padding mathematically via coordinate clamping, actual decoder implementations (such as libaom and dav1d) optimize this process for performance. Evaluating clipping logic per-pixel inside tightly optimized SIMD assembly routines degrades decoding speed.

To overcome this, implementations allocate reference frame buffers with an extra physical margin—often between 64 and 128 pixels wide—surrounding the actual reconstructed picture. Once a frame finishes decoding:

  1. The top and bottom rows are copied outward into the vertical margins.
  2. The left and right boundary columns are copied outward into the horizontal margins.
  3. The four corner pixels are propagated into the diagonal corner margins.

This pre-padding allows the motion compensation loop to load contiguous blocks of memory directly, using normal pointer offsets without conditional boundary checks, while strictly adhering to the AV1 specification.

Loop Drift Prevention

Because edge padding is fully standardized, both the AV1 encoder and decoder generate bit-identical prediction signals for out-of-bounds blocks. This strict determinism prevents reconstruction drift inside the inter-frame prediction loops, allowing encoders to freely search outside frame boundaries to compress panning shots and moving edges efficiently.