Best CRF Values for Lossy AVIF Image Encoding
This guide provides a comprehensive overview of choosing the optimal Constant Rate Factor (CRF) values when encoding lossy AVIF images. AVIF offers superior compression efficiency compared to older formats like JPEG and WebP, but achieving the ideal balance between visual quality and file size relies heavily on properly configuring the CRF parameter. Below, you will find direct recommendations for target use cases, encoder-specific considerations, and actionable best practices to optimize your image pipeline.
Understanding the AVIF CRF Scale
In most AVIF encoders—such as libavif using the AOMedia
codec (libaom)—the CRF scale ranges from 0 to
63:
- 0 represents mathematically lossless compression (largest file size).
- 63 represents the lowest visual quality and highest compression (smallest file size).
Because the scale is logarithmic, small numeric adjustments produce noticeable changes in quality and byte size.
Recommended CRF Ranges for Common Scenarios
- Ultra-High Quality (CRF 15–22):
Best for professional photography portfolios, detailed artwork, and hero assets where compression artifacts cannot be tolerated. At this level, images are visually indistinguishable from uncompressed sources on high-DPI displays. - Standard Web Delivery (CRF 25–32):
The recommended sweet spot for general web usage, e-commerce product pages, and blog posts. A CRF of 28 to 30 typically yields the best trade-off, offering major byte savings over WebP and JPEG without visible degradation at normal viewing distances. - Aggressive Compression (CRF 35–45):
Ideal for mobile-first websites, small thumbnails, background decorative textures, or low-bandwidth environments. While mild blurring or loss of fine high-frequency detail may occur, the image remains coherent without severe blockiness. - Extreme Compression (CRF 46–63):
Generally not recommended for user-facing production assets, as noticeable structural loss and color washing occur.
Factors Influencing Optimal CRF Selection
1. Image Resolution and Pixel Density
Higher-resolution images (such as 4K or high-DPI assets) can sustain higher CRF values (e.g., CRF 32–36) because the human eye cannot easily detect small compression flaws across a dense pixel grid. Conversely, lower-resolution images (such as 400x400 thumbnails) require lower CRF values (e.g., CRF 22–26) to prevent visible edge blur and loss of crucial structural details.
2. Image Content and High-Frequency Detail
- Complex textures: Images containing grass, foliage, sand, or complex patterns mask compression noise effectively, allowing for slightly higher CRF values.
- Smooth gradients: Large areas of solid color or smooth sky gradients are prone to color banding. For images with delicate gradients, lower the CRF value or ensure you are encoding in 10-bit color depth to maintain smooth transitions.
3. Color Depth (8-bit vs. 10-bit)
Whenever possible, encode lossy AVIF images using 10-bit
color depth (--depth 10 in avifenc),
even for standard 8-bit source images. The 10-bit encoding space
drastically reduces banding and visual artifacts, effectively allowing
you to increase the CRF value by 2 to 4 points to achieve lower file
sizes with better visual fidelity.
4. Chroma Subsampling
While CRF controls quantization, chroma subsampling dictates color resolution:
- Use YUV 4:4:4 (
--yuv 444) alongside moderate CRF values for UI screenshots, graphics with fine text, and synthetic line art to prevent color fringing. - Use YUV 4:2:0 (
--yuv 420) with standard photographic content to maximize compression efficiency.
Best Practices for Implementation
- Standardize on a Baseline: Begin automated batch testing with a default CRF of 28 using 10-bit color depth and the default AOM encoder.
- Tune with CPU Effort: Pair your chosen CRF with an
appropriate encoder speed preset. In
avifenc, a speed setting of--speed 4or--speed 6provides a solid balance between encoding duration and compression efficiency without altering your target CRF. - Automate Quality Audits: When building automated image pipelines, evaluate output quality against source images using perceptual metrics such as SSIMULACRA2 or Butteraugli rather than relying solely on fixed CRF targets across drastically different content types.