Libvpx Loop Filtering to Reduce Blocking Artifacts

In video compression, block-based coding often introduces distracting grid-like patterns known as blocking artifacts. This article explains how the libvpx library—the open-source reference implementation for the VP8 and VP9 video codecs—employs an in-loop filtering mechanism to smooth out these block boundaries, balance sharp details with blur reduction, and significantly enhance overall visual quality.

What is In-Loop Filtering?

The loop filter in libvpx is called “in-loop” because it is integrated directly into the encoding and decoding loop. Instead of post-processing the video after it is fully decoded, the filter is applied to reconstructed frames before they are saved to the frame buffer. This ensures that the filtered, higher-quality frames are used as reference frames for future motion estimation, preventing compression errors from compounding over time.

Step 1: Boundary Detection and Selection

The loop filter targets the borders between adjacent blocks (typically 4x4, 8x8, or 16x16 pixels). Because block-based transforms (like the Discrete Cosine Transform) process each block independently, the sharpest mismatches occur at these boundaries. Libvpx analyzes both horizontal and vertical edges to determine where smoothing is required.

Step 2: Thresholding and Edge Preservation

To avoid blurring actual image details (such as the edge of an object or text), libvpx must distinguish between artificial blockiness and real image content. It does this using mathematical thresholds based on two main factors:

Step 3: Simple vs. Normal Filter Modes

Libvpx offers two primary modes of loop filtering to balance computational cost and visual performance:

Step 4: Mathematical Smoothing

Once a boundary is selected for filtering, libvpx applies a low-pass filter to the adjacent pixels. This mathematical operation averages the values of pixels on either side of the edge, gently blending the transition. The strength of this blend is carefully controlled so that the block grid disappears while the underlying textures and gradients of the video remain intact.