avio
A safe, high-level Rust API over FFmpeg for building media applications: decode, encode, filter, compose, and stream.
avio is the editing engine of the ff-* crate family. It owns the editing model (Timeline / Clip, the model-to-frame derivation, and edit history) and re-exports the model-agnostic ff-* primitives behind feature flags, so you can depend on a single crate and opt into the capabilities you need. If your app needs a different editing model, depend on the ff-* primitives directly instead; each is usable on its own. See the main repository for full context.
Installation
[]
# Default: probe + decode + encode + hwaccel
= "0.16"
# Add filtering
= { = "0.16", = ["filter"] }
# Full streaming stack (implies pipeline, which implies filter)
= { = "0.16", = ["stream"] }
# Async decode/encode (requires tokio runtime)
= { = "0.16", = ["tokio"] }
The crates in this family version independently (each on its own cadence, like tokio or http); see crates.io for the current version of each.
Feature Flags
| Feature | Enables | Default | Implies |
|---|---|---|---|
probe |
ff-probe, read-only media metadata |
yes | |
decode |
ff-decode, video and audio decoding |
yes | |
encode |
ff-encode, video and audio encoding |
yes | |
hwaccel |
hardware-accelerated encoders | yes | |
filter |
ff-filter, filter graph operations |
no | |
pipeline |
ff-pipeline, decode/filter/encode |
no | filter |
stream |
ff-stream, HLS / DASH / live streaming |
no | pipeline |
preview |
ff-preview, real-time playback and seek |
no | |
preview-proxy |
proxy generation | no | preview |
render |
ff-render, GPU compositing pipeline |
no | preview |
render-gpu |
wgpu backend | no | render |
tokio |
async wrappers for decode, encode, and preview | no | decode + encode |
gpl |
GPL-licensed encoders | no | |
srt |
SRT input/output | no | |
serde |
serde derives for filter types |
no |
Quick Start
Probe
use open;
let info = open?;
if let Some = info.primary_video
Decode
use ;
// Video: request RGB24 output (FFmpeg converts internally)
let mut vdec = open
.output_format
.build?;
while let Some = vdec.decode_one?
// Audio: resample to f32 at 44.1 kHz
let mut adec = open
.output_format
.output_sample_rate
.build?;
while let Some = adec.decode_one?
Image Sequences
A %-pattern path (e.g. frame%04d.png) automatically selects the image2
demuxer for decode and muxer for encode:
use ;
// Decode numbered PNGs → video
let mut decoder = open
.hardware_accel
.frame_rate
.build?;
// Encode video → numbered PNGs
let mut encoder = create
.video
.video_codec
.build?;
Encode
use ;
let mut encoder = create
.video
.video_codec
.bitrate_mode
.audio
.audio_codec
.build?;
for frame in &video_frames
encoder.finish?;
Per-Codec Options
VideoCodecOptions and AudioCodecOptions provide typed, per-codec
configuration applied before the codec is opened:
use ;
let opts = H264;
let mut encoder = create
.video
.video_codec
.bitrate_mode
.codec_options
.build?;
Available option structs: H264Options, H265Options, Av1Options,
SvtAv1Options, Vp9Options, ProResOptions, DnxhdOptions,
OpusOptions, AacOptions, Mp3Options, FlacOptions.
Professional Formats
use ;
let mut encoder = create
.video
.video_codec
.pixel_format
.codec_options
.build?;
HDR Metadata
use ;
// HDR10: PQ transfer + MaxCLL/MaxFALL side data
let mut encoder = create
.video
.video_codec
.bitrate_mode
.pixel_format
.codec_options
.hdr10_metadata
.build?;
// HLG: broadcast HDR without MaxCLL/MaxFALL
use ;
let mut encoder = create
.video
.video_codec
.pixel_format
.color_transfer
.color_space
.color_primaries
.build?;
Async (tokio feature)
use ;
use StreamExt;
let mut encoder = from_builder?;
let stream = open.await?.into_stream;
pin!;
while let Some = stream.next.await
encoder.finish.await?;
Pipeline (pipeline feature)
use ;
builder
.input
.output
.build?
.run?;
Crate Family
| Crate | Purpose |
|---|---|
ff-sys |
Raw bindgen FFI (internal use only) |
ff-common |
Shared buffer-pooling abstractions |
ff-format |
Pure-Rust type definitions (no FFmpeg linkage) |
ff-probe |
Read-only media metadata extraction |
ff-decode |
Video and audio decoding |
ff-encode |
Video and audio encoding |
ff-filter |
Filter graph operations |
ff-pipeline |
Decode, filter, encode pipeline |
ff-stream |
HLS / DASH adaptive streaming output |
ff-preview |
Real-time preview and proxy workflow |
ff-render |
GPU compositing pipeline (wgpu) |
avio |
Editing engine + facade (this crate) |
MSRV
Rust 1.93.0 (edition 2024).
License
MIT OR Apache-2.0