Best Pre-Processing Filters for AVIF Image Encoding
Optimizing images for AVIF encoding requires targeted pre-processing to eliminate non-essential high-frequency data, reduce compression artifacts from legacy formats, and prepare color channels for the AV1 codec. Applying filters such as spatial denoising, deblocking, edge-preserving blurs, and film grain extraction allows the encoder to allocate its bitrate efficiently, yielding significantly smaller file sizes without sacrificing perceived visual fidelity.
Denoising Filters (NL-Means and Bilateral Filtering)
Digital sensor noise and high-frequency grain consume a disproportionate amount of bandwidth in transform-based codecs like AV1. Applying an edge-preserving denoising filter prior to encoding smooths flat and textured areas while keeping vital edges sharp.
- Non-Local Means (NL-Means): Excellent for photographic inputs, as it searches the entire image for similar pixel neighborhoods to remove noise without blurring distinct textures.
- Bilateral or Guided Filters: Faster alternatives that smooth uniform regions while using local edge gradients to prevent blurring object boundaries.
Film Grain Stripping for Synthetic Grain Modeling
AVIF natively supports Film Grain Synthesis (FGS), a feature
inherited from the AV1 video standard. Instead of forcing the encoder to
compress random film grain directly—which requires high bitrates and
often results in smearing—you should apply a heavy denoising filter to
strip the grain completely before encoding. You can then extract the
grain characteristics and pass them as synthetic grain parameters to the
AV1 encoder (--film-grain in tools like rav1e
or libaom), which regenerates the grain realistically on
the client side at virtually zero bitrate cost.
Deblocking and Deringing Filters
When converting older formats such as JPEG or WebP to AVIF, the source file often contains existing 8x8 block artifacts and ringing noise around high-contrast edges. The AVIF encoder will treat these artifacts as genuine image details, wasting bits to preserve distortion.
- Deblocking Filters: Soften artificial boundary lines caused by 8x8 DCT grid misalignment.
- Deringing (Mosquito Noise Removal): Cleans the high-frequency halos around text and hard edges before AVIF's directional intra-prediction tries to encode them.
Chroma Pre-Filtering and Subsampling Preparation
Most AVIF web assets are encoded in YUV 4:2:0 to minimize payload, which halves the horizontal and vertical resolution of color channels.
- Chroma Low-Pass Filtering: Applying a mild Gaussian blur or low-pass filter strictly to the U and V (Cb and Cr) channels before downsampling prevents color fringing, chromatic aberration, and aliasing along saturated, high-contrast borders.
- Chroma Re-centering: Aligning chroma sample positions ensures that the AV1 encoder’s chroma grid matches the subsampling phase, preventing color-bleed artifacts.
High-Fidelity Resampling Filters
If scaling is required before encoding, avoid simple bilinear or nearest-neighbor scaling, which introduce blur or harsh pixel steps. Use windowed sinc filters with negative lobes:
- Lanczos3 or Mitchell-Netravali: Delivers sharp downscaling with controlled aliasing, providing clean pixel grids that match AV1’s variable block size partitioning (from 4x4 up to 128x128).
- Catmull-Rom: Provides a neutral balance between sharpness and ringing, ideal for images containing sharp geometric UI elements mixed with continuous-tone photography.