Prompt
How do I keep image quality acceptable when converting to AVIF?
Latest observation
To keep image quality acceptable when converting to AVIF, focus on source quality, encoder settings, and testing. AVIF can look excellent at much smaller sizes than JPEG/PNG, but it’s also easy to over-compress if you push settings too hard.
Practical tips
1. Start with the best source you have
- Convert from the original high-quality image if possible.
- Avoid recompressing from an already heavily compressed JPEG.
- For graphics/screenshots, use a lossless source or PNG as input.
2. Use sensible quality settings
AVIF quality controls vary by encoder, but generally:
- Quality 40–60 often gives a good balance for photos.
- Quality 60–80 is safer if you want fewer visible artifacts.
- For very small file sizes, quality below 35 may start looking rough depending on the image.
If your encoder supports it, test a few values:
- Photo: 45, 55, 65
- Detailed imagery / text-heavy images: 60–80 or use lossless if needed
3. Use a good encoder
Different AVIF encoders can produce different results:
- libavif + libaom: common, high quality, slower
- rav1e or svt-av1 based paths may be faster, with different quality/performance tradeoffs
If quality matters more than speed, choose the encoder known for best results in your pipeline.
4. Watch chroma subsampling
For images with sharp color edges, text, UI, or logos:
- Prefer 4:4:4 if supported
- 4:2:0 is smaller but can blur color detail around edges
For natural photos, 4:2:0 is usually fine.
5. Avoid aggressive downscaling
If you resize the image:
- Use a high-quality resampling filter
- Don’t shrink more than necessary
- Resize once, not multiple times
6. Keep bit depth when needed
If the source has:
- gradients
- HDR
- scientific/medical detail
- heavy post-processing
Then consider 10-bit or 12-bit AVIF if your tools and target devices support it. This reduces banding.
7. Don’t strip metadata blindly if you need it
Quality is visual, but you may want to preserve:
- color profiles (ICC)
- orientation
- transparency
- EXIF/XMP if needed
Incorrect color management can make a “good” AVIF look wrong.
8. Test against the original
Compare with:
- side-by-side viewing
- zoomed-in inspection
- SSIM/PSNR or perceptual metrics if you automate
Look for:
- banding
- blockiness
- ringing
- color bleeding
- loss of fine texture
9. Use lossless AVIF when appropriate
For:
- screenshots
- UI assets
- line art
- text-heavy images
- images with transparency and crisp edges
Lossless AVIF can be a good choice, though file size may still be larger than lossy.
Rule of thumb
- Photos: start around quality 50–65
- Screenshots/UI: use higher quality or lossless
- If you see artifacts: increase quality before changing other settings
Example with FFmpeg
If you’re using FFmpeg, a simple example is:
ffmpeg -i input.jpg -c:v libaom-av1 -still-picture 1 -crf 35 output.avif
Lower crf usually means higher quality and larger files, though exact behavior depends on the encoder.
If you want, I can give you:
- recommended AVIF settings for photos vs screenshots, or
- commands for a specific tool like
ffmpeg,imagemagick, orcavif.