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.avif

Quality 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).

You can install avifenc on Debian/Ubuntu using

example.sh
sudo apt install libavif-bin

How 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.avif

to 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