How to Integrate librav1e into FFmpeg
This guide provides a comprehensive overview of integrating and using
the rav1e AV1 encoder (via the librav1e library) within
FFmpeg for efficient video processing. You will learn how to obtain or
compile an FFmpeg binary with librav1e support, write the
correct command-line syntax for encoding, and adjust key parameters such
as speed presets and constant quality to optimize your AV1 video
compression workflow.
Step 1: Enable librav1e in FFmpeg
To process videos using librav1e, your FFmpeg
installation must be compiled with support for it. Because
librav1e is licensed under the BSD 2-Clause license, it can
be built into both GPL and non-GPL builds of FFmpeg.
If you are compiling FFmpeg from source, you must first install Rust,
cargo, and the rav1e library on your system.
Once those dependencies are met, configure your FFmpeg build by
appending the --enable-librav1e flag:
./configure --enable-gpl --enable-librav1e
make -j$(nproc)
sudo make installFor users who prefer not to compile from source, pre-built static
binaries containing librav1e are available through
third-party package managers like Homebrew (macOS) or specialized
community builds for Windows and Linux.
Step 2: Basic Encoding Syntax
Once you have an FFmpeg build with librav1e enabled, you
can specify it as your video encoder using the
-c:v librav1e parameter.
The most basic command to transcode a video to AV1 using
librav1e is:
ffmpeg -i input.mp4 -c:v librav1e -c:a copy output.mkvThis command takes an input video, encodes the video stream using
librav1e, copies the audio stream without re-encoding, and
packages the result into a Matroska (.mkv) container.
Step 3: Configuring Quality and Speed
To achieve the best balance between file size, visual quality, and encoding time, you should configure the encoder’s speed presets and quality parameters.
- Speed Presets (
-preset): rav1e offers speed levels ranging from0(slowest, highest compression efficiency) to10(fastest, lowest compression efficiency). A preset of5or6is generally recommended for a good balance of speed and quality. - Quantizer / Quality (
-qp): Instead of standard CRF,librav1euses Quantizer Parameter (QP) values to control quality. The range is0to255. Lower values yield higher quality and larger file sizes. A QP value between50and100is typically ideal for standard-definition and high-definition video.
An optimized command utilizing these settings looks like this:
ffmpeg -i input.mp4 -c:v librav1e -qp 80 -preset 5 output.mp4Step 4: Advanced Fine-Tuning
For advanced control, you can pass custom parameters directly to the
rav1e library using the -rav1e-params flag. Multiple
parameters can be separated by colons.
For example, to set a keyframe interval (gop size) and force low-latency tuning, use the following command:
ffmpeg -i input.mp4 -c:v librav1e -qp 80 -rav1e-params speed=5:low_latency=true -g 240 output.mp4By leveraging these configuration options, you can successfully
integrate librav1e into your FFmpeg pipeline to generate
highly optimized AV1 video files.