How to Use librav1e with FFmpeg

This article provides a quick guide on how to encode AV1 video using the librav1e encoder wrapper in the FFmpeg command-line tool. You will learn the basic command syntax, essential configuration parameters such as speed and quality controls, and practical examples for executing successful encodes.

Prerequisites

To use librav1e within FFmpeg, your FFmpeg binary must be compiled withrav1e support. You can verify this by running ffmpeg -encoders and checking if librav1e is listed in the output, or by checking your build configuration for the --enable-librav1e flag.

Basic Syntax

The most basic command to transcode a video using librav1e is as follows:

ffmpeg -i input.mp4 -c:v librav1e output.mkv

Essential Parameters

To control the quality, file size, and encoding speed, you should utilize the specific private options exposed by the librav1e wrapper.

1. Constant Quality (Quantizer)

Instead of specifying a target bitrate, AV1 encoding is typically done using a Constant Quantizer (QP) mode. This ensures consistent quality throughout the video. * Parameter: -qp or -crf (Note: librav1e maps both to its internal quantizer). * Range: 0 (lossless) to 255 (worst quality). * Recommended Range: 50 to 100 (where lower values yield higher quality and larger files).

2. Speed / CPU Usage

rav1e offers multiple speed presets to balance encoding time and compression efficiency. * Parameter: -speed * Range: 0 to 10 (where 0 is the slowest/most efficient and 10 is the fastest/least efficient). * Recommended Range: 4 to 6 for a good balance of speed and compression.

3. Bitrate Control

If you require a specific file size, you can specify a target bitrate. * Parameter: -b:v (e.g., -b:v 2M for 2 Megabits per second).

4. Tiling (Multi-threading)

To improve encoding speeds on multi-core processors, you can split the video frame into tiles. * Parameters: -tile-rows and -tile-cols (expressed as log2 values; e.g., 1 means 2 tiles, 2 means 4 tiles).


Practical Command Examples

This command encodes a video using a high-quality quantizer of 80 and a balanced speed preset of 5, while copying the audio stream without re-encoding.

ffmpeg -i input.mp4 -c:v librav1e -qp 80 -speed 5 -c:a copy output.mkv

Target Bitrate Encode with Opus Audio

This command targets a video bitrate of 1.5 Mbps, uses a faster speed preset of 7, and transcodes the audio to the Opus format.

ffmpeg -i input.mp4 -c:v librav1e -b:v 1500k -speed 7 -c:a libopus -b:a 128k output.mkv