Choosing the right AVIF encoding settings means balancing file size, visual quality, and encoding time. The key parameters are the quantizer, encoder speed, chroma subsampling, and bit depth. Each setting changes the output. Match them to your image type.
Quantizer Quality vs File Size
The quantizer is the primary quality control in AVIF. It runs from 0 to 63. Lower values give higher quality and larger files. Higher values reduce file size but introduce visible compression artifacts.
For photos, set the quantizer to a moderate range for visually lossless or near-lossless results. For graphics and text, drop it to a lower range to preserve sharp edges and fine details. At the extremes, 0 is near-lossless but not truly lossless, and 63 produces very small, low-quality files.
The AVIF quantizer is not a percentage. It is a logarithmic scale. Moving from a lower value to a higher value reduces file size more than moving from that higher value to an even higher value.
Encoder Speed Avifenc Speed Settings
The libavif encoder avifenc offers a speed setting from 0 to 10. Speed 0 is the slowest and most efficient. It spends more time looking for compression efficiencies, giving smaller files at the same quantizer. Speed 10 encodes quickly but produces larger files for the same visual quality.
How to choose avifenc speed
- Speed 0 to 3: Use for final exports or batch processing where encoding time is not critical. Best file size for a given quality.
- Speed 4 to 6: Good balance for everyday use. Encoding is still slower than JPEG, but reasonable for single images.
- Speed 7 to 10: Only when speed is more important than file size, for example generating thumbnails or previews on demand.
AVIF encoding is much slower than JPEG encoding. That matters when converting on demand. If you are converting many images, a higher speed setting avoids long waits.
Chroma Subsampling 4 -4 -4 vs 4 -2 -0
AVIF supports chroma subsampling of 4:4:4, 4:2:2, 4:2:0, and 4:0:0 for monochrome. Chroma subsampling reduces file size by storing less colour detail. The choice between 4:4:4 and 4:2:0 depends on the image type.
4:4:4 for graphics and text
4:4:4 keeps full colour resolution for every pixel. Use it for graphics, screenshots, text, and line art where colour edges must be sharp. Using 4:2:0 on such images causes colour bleeding around text and fine lines.
4:2:0 for photos
4:2:0 stores colour at half the horizontal and vertical resolution. The human eye is less sensitive to colour detail than to brightness, so the difference is often invisible in photographs. 4:2:0 saves bytes on photos compared to 4:4:4 with negligible visual loss.
4:2:2 is a middle ground rarely needed. 4:0:0 discards all colour and is only useful for grayscale images.
Bit Depth 8, 10, or 12 Bits
AVIF supports 8, 10, and 12 bits per channel. Higher bit depth allows more colour levels and reduces banding in gradients. For most web use, 8 bits is sufficient. 10 bits is useful for HDR images or when editing, because it gives more headroom before banding appears. 12 bits is rarely needed outside professional workflows.
Higher bit depth increases file size but not dramatically. The quantizer and speed settings have a much larger effect on file size than the bit depth.
Lossless Mode and When to Use it
AVIF has a lossless mode, but lossless AVIF is often not smaller than lossless WebP or optimised PNG. The lossless mode sets the quantizer to a special mode that preserves every pixel exactly. Use it for archival or medical images where no quality loss is acceptable.
For most practical purposes, a low quantizer with 4:4:4 chroma is visually identical to lossless while producing a much smaller file. Only use true lossless mode when you need bit-perfect reproduction and cannot accept any compression artifacts.
Sensible Choices Photos vs Graphics
Start with these settings for common use cases:
- Photos for web: quantizer a moderate value, speed 6, chroma 4:2:0, 8 bit. Good quality, reasonable file size, tolerable encoding time.
- Photos for archive: quantizer a lower value, speed 3, chroma 4:2:0, 10 bit. Higher quality with more efficient encoding.
- Graphics and text: quantizer a low value, speed 4, chroma 4:4:4, 8 bit. Preserves sharp edges and colour accuracy.
- Maximum compression: quantizer a high value, speed 10, chroma 4:2:0, 8 bit. Use only for thumbnails or previews where quality does not matter.
These are starting points. The best AVIF quality setting for your specific images may vary depending on content and your tolerance for artifacts.
Practical Workflow for Developers
When integrating AVIF encoding into your application, follow these steps:
- Determine the image type: photo or graphic. This decides chroma subsampling and quantizer range.
- Choose a speed setting. For batch conversion, start with speed 6. For on-demand conversion, use speed 8 or 9 to keep response times low.
- Set the quantizer based on your quality target. Test a few values on representative images.
- Select bit depth. 8 bits for standard web content, 10 bits for HDR or high-quality archives.
- Run encoding and verify output. Adjust quantizer or speed if file sizes are too large or encoding is too slow.
Test settings on individual images at avif.tools before implementing them in your own encoder.