How to encode a single PNG/JPEG file as AVIF
You can encode myimg.png to myimg.avif using
example.sh
avifenc -q 30 -s 4 myimg.png myimg.avifQuality 30 is a rather low quality, optimized for filesize but that still looks good as AVIF:
-s 4: How much CPU time to spend on optimizing (same quality).
-s 0would be slow but result in a smaller file at the same quality, whereas-s 10would be very fast but result in a larger file at the same quality.
You can install avifenc on Debian/Ubuntu using
example.sh
sudo apt install libavif-binHow to encode for maximum
If you don’t care about encoding time, you can use
example.sh
avifenc -q 30 -s 0 myimg.png myimg.avifto get the smallest possible AVIF file at this quality level.
Often, the file is only marginally smaller than with -s 4, but it depends on the image content, and if you need the absolute smallest file size, this is the way to go.
Check out similar posts by category:
Audio/Video
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow