How librav1e Interfaces with VLC and mpv
This article explores how librav1e, the Rust-based AV1
video encoder, interfaces with popular video playback and rendering
applications like VLC and mpv. While these media players are primarily
known for decoding and playing back media files, they also feature
robust transcoding, recording, and stream-saving capabilities. By
leveraging intermediary multimedia frameworks—most notably FFmpeg—VLC
and mpv can utilize librav1e to compress and encode video
streams into the modern AV1 format.
The Role of librav1e in Playback Ecosystems
To understand how librav1e interfaces with playback
libraries, it is important to distinguish between encoding and decoding.
While libraries like dav1d or libgav1 are used
by VLC and mpv to decode (play) AV1 video,
librav1e is an encoder used to create AV1
video.
Media players interface with librav1e when performing
tasks such as: * Transcoding: Converting an existing
video file into the AV1 format. * Stream
Saving/Screencasting: Recording live streams, gameplay, or
desktop feeds directly to an AV1-encoded file. * Video
Editing/Filtering: Exporting filtered or altered video
segments.
The Middleware Layer: FFmpeg and libavcodec
Neither VLC nor mpv typically communicates with librav1e
directly. Instead, they rely on FFmpeg (specifically
the libavcodec library) as a universal translation
layer.
[ VLC / mpv ] ---> [ FFmpeg (libavcodec) ] ---> [ librav1e C-API Wrapper ] ---> [ librav1e (Rust Core) ]
1. C-Compatible Bindings (c_api)
Because librav1e is written in Rust, it cannot be
natively linked by C-based multimedia libraries without a translation
bridge. The developers of rav1e provide a C-compatible API
(c_api). This allows C/C++ libraries to call Rust functions
as if they were native C functions.
2. FFmpeg Integration
FFmpeg includes a dedicated wrapper module for librav1e
within libavcodec. When FFmpeg is compiled with the
--enable-librav1e flag, it registers librav1e
as an available AV1 encoder.
How mpv Interfaces with librav1e
The mpv media player is designed to be highly integrated with FFmpeg.
To encode video using librav1e in mpv, the player utilizes
its output and encoding options.
- The Command Pipeline: When a user executes an
encoding command in mpv (e.g.,
mpv input.mp4 --o=output.mkv --ovc=librav1e), mpv initializes its internal rendering pipeline. - Frame Passing: mpv decodes the source video frame-by-frame, applies any requested video filters, and sends the raw YUV pixel data to FFmpeg’s encoding interface.
- Configuration: mpv passes encoder-specific options
(such as speed presets, constant quality values, or tile configurations)
down to
librav1evia FFmpeg’s private options system.
How VLC Interfaces with librav1e
VLC operates on a modular architecture consisting of access modules, demuxers, decoders, encoders, and outputs.
- The VLC Transcode Module: When a user utilizes
VLC’s “Convert/Save” feature, VLC invokes its transcoding module
(
stream_out_transcode). - Codec Negotiation: VLC queries its loaded plugins
for an AV1 encoder. If VLC’s FFmpeg module
(
libavcodec_plugin) was compiled withlibrav1esupport, VLC selects it. - Data Flow: VLC passes raw, uncompressed video
frames to the
libavcodec_plugin, which manages the configuration of thelibrav1estate machine, feeds it raw frames, and retrieves the compressed AV1 packets to be muxed into a container like MKV or WebM.