Install avifenc on Ubuntu 20.04 and 22.04
AVIF is a next-generation image format for the Web, that’s supported by all major browsers except IE and Edge. It has better compression than WebP, which itself is a great improvement as a replacement for JPG.
As of today, the most efficient way to encode JPG images into AVIF is to use libavif’s avifenc
. There are no prebuilt binaries; if you use Homebrew on Linux all you have to do is brew install libavif
, but if you don’t you’ll probably have to build from source.
The instructions below work as of today for Ubuntu 20.04 and 22.04 LTS. We’ll first install libaom and then libavif.
Prepare dependencies
Let’s start by installing a few dependencies:
sudo apt install ninja-build yasm pandoc cmake libpng-dev libjpeg-dev
ninja-build
is used to build both libaom and libavif; you can remove it after. yasm
is a dependency of libaom. pandoc
is needed to build the avifenc
manpage; remove it if you don’t want it. In any case, you’ll be able to remove it after the build.
Install libaom
These instructions are adapted from Linux from scratch:
# Download the release wget https://storage.googleapis.com/aom-releases/libaom-3.6.1.tar.gz # Uncompress it tar xzf libaom-3.6.1.tar.gz # Create a temporary directory for the build mkdir libaom-3.6.1/aom-build # Move into it pushd libaom-3.6.1/aom-build # Configure the build cmake -DCMAKE_INSTALL_PREFIX=/usr \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_SHARED_LIBS=1 \ -DENABLE_DOCS=no \ -G Ninja .. # Build ninja # Install sudo ninja install # Exit the temporary directory popd # Clean up rm -rf libaom-3.6.1*
Install libavif
Installing libavif follows a similar path to libaom (again, adapted from LFS):
# Download the release (for some reason I get a 403 when I use wget) curl -Lo libavif-0.11.1.tar.gz https://github.com/AOMediaCodec/libavif/archive/refs/tags/v0.11.1.tar.gz # Uncompress it tar xzf libavif-0.11.1.tar.gz # Create a temporary directory for the build mkdir libavif-0.11.1/build # Move into it pushd libavif-0.11.1/build # Configure the build. # If you don't want to install the manpage, remove -DAVIF_BUILD_MAN_PAGES=ON cmake -DCMAKE_INSTALL_PREFIX=/usr \ -DCMAKE_BUILD_TYPE=Release \ -DAVIF_CODEC_AOM=ON \ -DAVIF_BUILD_GDK_PIXBUF=ON \ -DAVIF_BUILD_MAN_PAGES=ON \ -DAVIF_BUILD_APPS=ON \ -G Ninja .. # Build ninja # Install sudo ninja install # Exit the temporary directory popd # Clean up rm -rf libavif-0.11.1*
Finish
You can now remove the build dependencies: sudo apt remove ninja-build pandoc cmake libpng-dev libjpeg-dev
.
Try running avifenc
. If it prints a long help text, then it’s properly installed! You can now encode images in AVIF format with avifenc source.jpg target.avif
. Check the help or the manpage for all the available options.