Key features you need to know

  • Waaaay better compression than JPEG and WEBP (Google’s 10+ years old codec)
  • Royalty-free -> anyone can use, implement, redistribute without paying any fee -> more adoption
  • High browser adoption (~74% according to caniuse)
  • Support for alpha channel and animation (Chrome 91+ only at the time of writing), replacing +35 years old GIF format and WEBP

Installations

Getting the binaries

My favorite and also the recommended method is to get the pre-build binaries directly from the source-code repository (or the official website):

There are also some other options, so you can choose the one that suits you best:

  • Build everything using media-autobuild_suite.
  • Download pre-built binaries of media-autobuild_suite from jeremylee.sh.
  • Build ffmpeg and (libavif)[https://github.com/AOMediaCodec/libavif] from source.

Adding to PATH

  • Windows Search
    -> Search for env
    -> Edit the system environment variables
    -> Environment Variables...
    -> Path (in User variables for <your_username>)
    -> Edit
    -> New
    -> Paste the path to the folder containing the binaries
    -> OK x 3

Encoding parameters

  • Everything can be done using ffmpeg, but libavif has some more optimized default values that I don’t want to bother with.
  • ffmpeg supports all kinds of input formats, libavif only support jpeg, png and y4m. If you want to encode a video with libavif, use ffmpeg to “decompress” to y4m first.
  • The terminal commands are written in PowerShell. For Command Prompt, replace the backtick (`) with the caret (^).
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
avifenc `
    -y <CHROMA_SUBSAMPLING> `
    -d <BIT_DEPTH> `
    -c aom `
    --min 0 `
    --max 63 `
    --minalpha 0 `
    --maxalpha 63 `
    -a aq-mode=1 `
    -a cq-level=<CQ_LEVEL> `
    -a enable-chroma-deltaq=1 `
    -a tune=ssim `
    <input> <output>.avif
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
ffmpeg -i <input> `
    -c:v libaom-av1 `
    -b:v 0 `
    -qmin 0 `
    -qmax 63 `
    -crf <CQ_LEVEL> `
    -cpu-used 6 `
    -aq-mode 1 `
    -pix_fmt yuv<CHROMA_SUBSAMPLING>p<BIT_DEPTH>le `
    -aom-params enable-chroma-deltaq=1 `
    <output>.avif
  • CHROMA_SUBSAMPLING: 444 for high-resolution images, else 420.
  • BIT_DEPTH: 8, 10 or 12. Recommended using 10 even for 8-bit images. 12-bit is overkill for 99.99% of general use cases.
  • CQ_LEVEL: lower the value, higher the quality. Recommended range: 18-26. I typically use 18.

References