FFmpeg AV1 Encoding with rav1e and Custom Speeds

This article explains how to transcode video to the AV1 format using the librav1e encoder in FFmpeg. You will learn the correct command-line syntax, how the speed presets work, and how to configure custom speeds to balance encoding time and file size.

Understanding rav1e Speed Settings

The rav1e encoder is a Rust-based AV1 encoder known for its safety and clean code base. In FFmpeg, it is accessed via the librav1e codec library.

The primary setting for controlling encoding performance is the -speed parameter (sometimes configured via -rav1e-params speed=X). * The speed scale ranges from 0 to 10. * 0 is the slowest speed, offering the highest compression efficiency and best quality per megabyte. * 10 is the fastest speed, ideal for quick test encodes or real-time streaming, but at the cost of larger file sizes and lower quality. * The default speed preset is typically 6.

Basic Command Syntax

To transcode a video using librav1e, you must specify the video codec as librav1e and set your desired speed and quality. Quality is controlled using the quantizer parameter (-qp), which ranges from 0 (lossless) to 255 (lowest quality). A QP value between 80 and 120 is generally recommended for standard use.

Here is the template command:

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

Custom Speed Examples

Depending on your hardware capability and patience, you can adjust the speed to fit your specific needs.

1. High-Efficiency Encoding (Slow / Archive Quality)

If you want the smallest possible file size and do not mind long encoding times, use a lower speed setting (between 0 and 3).

ffmpeg -i input.mp4 -c:v librav1e -speed 2 -qp 90 -c:a flac output.mkv

2. Balanced Encoding (Standard Use)

For a good compromise between CPU usage and compression efficiency, use a speed setting in the middle of the range (between 4 and 6).

ffmpeg -i input.mp4 -c:v librav1e -speed 5 -qp 105 -c:a aac -b:a 128k output.mkv

3. Fast Encoding (Testing or Low CPU Overhead)

If you need to quickly preview an encode or have limited computing power, use a high speed setting (between 7 and 10).

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

Alternative Syntax using rav1e-params

You can also pass speed and other custom parameters directly to the encoder using the -rav1e-params flag. Use a colon (:) to separate multiple parameters:

ffmpeg -i input.mp4 -c:v librav1e -rav1e-params speed=4:qp=100 -c:a copy output.mkv