XUtils

libavif

Library for encoding and decoding .avif files. [BSD-2-Clause]


Windows

vcpkg install libavif

You can also download the official windows binaries on the release page.

macOS

Homebrew:

brew install libavif

MacPorts:

sudo port install libavif

Linux

Debian-based distributions:

sudo apt install libavif-dev

Red Hat-based distributions:

sudo yum -y install libavif

MinGW

For the “default” MSYS2 UCRT64 environment:

pacman -S mingw-w64-ucrt-x86_64-libavif

Build Notes

Building libavif requires CMake.

No AV1 codecs are enabled by default. Enable them by setting any of the following CMake options to LOCAL or SYSTEM whether you want to use a locally built or a system installed version (e.g. -DAVIF_CODEC_AOM=LOCAL):

  • AVIF_CODEC_AOM for libaom (encoder and decoder)
  • AVIF_CODEC_DAV1D for dav1d (decoder)
  • AVIF_CODEC_LIBGAV1 for libgav1 (decoder)
  • AVIF_CODEC_RAV1E for rav1e (encoder)
  • AVIF_CODEC_SVT for SVT-AV1 (encoder)

When set to SYSTEM, these libraries (in their C API form) must be externally available (discoverable via CMake’s FIND_LIBRARY) to use them, or if libavif is a child CMake project, the appropriate CMake target must already exist by the time libavif’s CMake scripts are executed.

Local / Static Builds

The ext/ subdirectory contains a handful of basic scripts which each pull down a known-good copy of an AV1 codec and make a local static library build. Most scripts require CMake, Ninja and NASM. dav1d uses Meson instead of CMake, and rav1e uses cargo (Rust). Check each library’s documentation for an exact list of requirements.

If you want to statically link any codec into your local (static) build of libavif, building using one of these scripts and then setting the associated AVIF_CODEC_* to LOCAL is a convenient method, but you must make sure to disable BUILD_SHARED_LIBS in CMake to instruct it to make a static libavif library.

If you want to build/install shared libraries for AV1 codecs, you can still peek inside of each script to see where the current known-good SHA is for each codec.

Tests

A few tests written in C can be built by enabling the AVIF_BUILD_TESTS CMake option.

The remaining tests can be built by enabling the AVIF_BUILD_TESTS and AVIF_ENABLE_GTEST CMake options. They require GoogleTest to be built locally with ext/googletest.cmd or installed on the system.

Command Lines

The following instructions can be used to build the libavif library and the avifenc and avifdec tools.

Build using installed dependencies

To link against the already installed aom, libjpeg and libpng dependency libraries (recommended):

git clone -b v1.0.3 https://github.com/AOMediaCodec/libavif.git
cd libavif
cmake -S . -B build -DAVIF_CODEC_AOM=SYSTEM -DAVIF_BUILD_APPS=ON
cmake --build build --parallel

Build everything from scratch

For development and debugging purposes, or to generate fully static binaries:

git clone -b v1.0.3 https://github.com/AOMediaCodec/libavif.git
cd libavif/ext
./aom.cmd
./libyuv.cmd
./libsharpyuv.cmd
./libjpeg.cmd
./zlibpng.cmd
cd ..
cmake -S . -B build -DBUILD_SHARED_LIBS=OFF -DAVIF_CODEC_AOM=LOCAL -DAVIF_LIBYUV=LOCAL -DAVIF_LIBSHARPYUV=LOCAL -DAVIF_JPEG=LOCAL -DAVIF_ZLIBPNG=LOCAL -DAVIF_BUILD_APPS=ON
cmake --build build --parallel

Prebuilt Library (Windows)

If you’re building on Windows with Visual Studio 2022 and want to try out libavif without going through the build process, static library builds for both Debug and Release are available on AppVeyor.

Development Notes

Please check the wiki for extra resources on libavif, such as the Release Checklist.

The libavif library is written in C99. Most of the tests are written in C++14.

Formatting

Use clang-format to format the C sources from the top-level folder (clang-format-16 preferred):

clang-format -style=file -i \
  apps/*.c apps/*/*.c apps/*/*.cc apps/*/*.h examples/*.c \
  include/avif/*.h src/*.c src/*.cc \
  tests/*.c tests/*/*.cc tests/*/*.h

Use cmake-format to format the CMakeLists.txt files from the top-level folder:

cmake-format -i \
  CMakeLists.txt \
  tests/CMakeLists.txt \
  cmake/Modules/Find*.cmake \
  contrib/CMakeLists.txt \
  contrib/gdk-pixbuf/CMakeLists.txt \
  android_jni/avifandroidjni/src/main/jni/CMakeLists.txt


Articles

  • coming soon...