Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
ff-encode
Encode video and audio to any format with a builder chain. The encoder validates your codec, resolution, and bitrate settings before allocating any FFmpeg context — invalid configurations are caught as Err, not discovered at the first push_video call.
Installation
[]
= "0.3"
= "0.3"
# Enable GPL-licensed encoders (libx264, libx265).
# Requires GPL compliance or MPEG LA licensing in your project.
# ff-encode = { version = "0.3", features = ["gpl"] }
By default, only LGPL-compatible encoders are enabled.
Quick Start
use ;
let mut encoder = create
.video // width, height, fps
.video_codec
.bitrate_mode
.preset
.audio // sample_rate, channels
.audio_codec
.audio_bitrate
.build?;
for frame in &video_frames
for frame in &audio_frames
encoder.finish?;
Quality Modes
// Constant bitrate — predictable file size and bandwidth.
.bitrate_mode // 4 Mbps
// Constant rate factor — quality-driven; file size varies.
.bitrate_mode // 0–51, lower = better
// Variable bitrate — target average with hard ceiling.
.bitrate_mode
Hardware Encoding
use ;
let mut encoder = create
.video
.video_codec
.hardware_encoder
.build?;
HardwareEncoder::Auto selects NVENC, QuickSync, AMF, or VideoToolbox based on what is available at runtime. If no hardware encoder is found, the builder falls back to a software encoder automatically.
Progress Tracking
let mut encoder = create
.video
.video_codec
.bitrate_mode
.on_progress
.build?;
LGPL Compliance
By default, ff-encode only links encoders that are compatible with the LGPL license — hardware encoders (NVENC, QSV, AMF, VideoToolbox) or software encoders for VP9 and AV1.
Enable the gpl feature to add libx264 and libx265. This changes the license terms of your binary; ensure you comply with the GPL or hold an appropriate MPEG LA commercial license before distributing.
Error Handling
| Variant | When it occurs |
|---|---|
EncodeError::InvalidConfig |
Codec, resolution, or bitrate settings are invalid |
EncodeError::UnsupportedCodec |
Requested codec not available in this FFmpeg build |
EncodeError::HardwareUnavailable |
Hardware encoder requested but no device found |
EncodeError::Io |
Write error on the output file |
EncodeError::Encode |
FFmpeg returned an error during frame encoding |
Feature Flags
| Flag | Description | Default |
|---|---|---|
hwaccel |
Enables hardware encoder detection (NVENC, QSV, AMF, VideoToolbox, VA-API). | enabled |
gpl |
Enables GPL-licensed encoders (libx264, libx265). Requires GPL compliance or MPEG LA licensing. | disabled |
tokio |
Enables AsyncVideoEncoder and AsyncAudioEncoder. Each encoder runs a worker thread and exposes an async push / finish interface backed by a bounded tokio::sync::mpsc channel (capacity 8). Requires a tokio 1.x runtime. |
disabled |
[]
= { = "0.5", = ["tokio"] }
When the tokio feature is disabled, only the synchronous VideoEncoder, AudioEncoder, and ImageEncoder APIs are compiled. No tokio dependency is pulled in.
MSRV
Rust 1.93.0 (edition 2024).
License
MIT OR Apache-2.0