How to Compile FFmpeg with libwebp Support

Compiling FFmpeg with libwebp allows you to encode and decode WebP images directly from the command line, offering high compression efficiency for web-optimized visuals. This guide provides a straightforward, step-by-step walkthrough to install the necessary dependencies, configure the FFmpeg source tree with the --enable-libwebp flag, and build the binaries on a Debian or Ubuntu-based Linux system.

1. Install Build Dependencies and libwebp

Before downloading FFmpeg, install the essential compilation tools and the libwebp development libraries:

sudo apt update
sudo apt install -y \
  build-essential \
  git \
  pkg-config \
  yasm \
  nasm \
  libwebp-dev

2. Download FFmpeg Source Code

Clone the official FFmpeg source repository using Git and navigate into the source directory:

git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg

3. Configure the Build

Run the ./configure script to prepare the build environment. You must include --enable-libwebp to activate WebP support:

./configure \
  --enable-gpl \
  --enable-libwebp \
  --enable-nonfree

Note: If you plan to add other codecs (such as libx264 or libvpx), install their respective development packages and append their flags (e.g., --enable-libx264) to the command above.

4. Compile and Install FFmpeg

Compile the source code using multiple CPU cores to speed up the process, then install the generated binaries to your system path:

make -j$(nproc)
sudo make install

Update the shared library cache:

sudo ldconfig

5. Verify libwebp Support

Ensure that libwebp is properly integrated into your new FFmpeg build by checking the available encoders:

ffmpeg -encoders | grep webp

If the compilation was successful, the output will display libwebp among the available encoders:

 V..... libwebp              libwebp WebP image (codec webp)
 V..... libwebp_anim         libwebp WebP image (codec webp)