How to Compile libaom from Source Using CMake?

Compiling libaom (the reference encoder/decoder for the AV1 video format) from source allows you to leverage the latest performance optimizations and features. This guide provides a straightforward, step-by-step walkthrough for cloning the official repository, setting up your build environment with CMake, configuring the build options, and installing the compiled binaries on your system.

Prerequisites and Dependencies

Before you begin the compilation process, you need to ensure your system has the necessary tools installed. You will need a C/C++ compiler (like GCC, Clang, or MSVC), Git, and CMake.

Additionally, libaom heavily relies on assembly optimizations for performance. To enable these, you must install an assembler:

Step 1: Clone the Source Code

First, open your terminal or command prompt and clone the official AOMedia Git repository to your local machine.

git clone https://aomedia.googlesource.com/aom
cd aom

Step 2: Create a Build Directory

CMake requires a separate directory to store build files, object files, and binaries. Creating an isolated build directory keeps the original source code clean.

mkdir build_aom
cd build_aom

Step 3: Configure the Build with CMake

Now, run CMake to generate the build files. The standard command will look for your system’s default compiler and build configurations.

cmake ..

If you need to customize your build, you can pass specific flags to CMake using the -D prefix. Here are a few common configuration examples:

Step 4: Compile the Source Code

Once CMake has successfully generated the build files, you can begin the compilation process. Use the universal CMake build command, which works across Linux, macOS, and Windows.

cmake --build .

To speed up compilation on multi-core processors, you can append the parallel jobs flag (for example, using 4 threads):

cmake --build . --parallel 4

Step 5: Install libaom

After the build process completes successfully, you can install the compiled libraries and command-line tools (aomenc and aomdec) to your system.

On Linux or macOS, you will likely need administrative privileges:

sudo cmake --install .

On Windows systems, running your command prompt as an Administrator or installing to a user-writable directory via the CMAKE_INSTALL_PREFIX flag will achieve the same result. Your system is now ready to use the newly compiled libaom encoder and decoder.