A lightweight FFmpeg audio decoding wrapper designed for music player applications.
- Simple and intuitive API
- Pure Rust compilation via cc — no C build system required
- Fully statically linked with zero external FFmpeg dependencies
- Bundled with a specific, up-to-date FFmpeg version (currently 8.1.1)
- Optional
tracingfeature for FFmpeg log integration
This crate leverages FFmpeg's decoding capabilities and supports almost all audio formats, including:
- MP3, AAC, FLAC, WAV, OGG, Opus, WMA, ALAC, AIFF, and more
You can find the complete list in generate_config.ts
The resampler output supports the following Rust-native sample types:
| Type | FFmpeg Format |
|---|---|
f32 |
32-bit Float |
i16 |
16-bit Signed |
i32 |
32-bit Signed |
u8 |
8-bit Unsigned |
[dependencies]
ffmpeg_audio = { git = "https://github.com/apoint123/ffmpeg-audio" }
use std::fs::File;
use ffmpeg_audio::{AudioReader, ResampleOptions};
// 1. Initialize the decoding engine
let reader = AudioReader::new(File::open("song.mp3")?)?;
// 2. Configure target audio parameters (e.g., 48kHz, Stereo, 32-bit Float)
let options = ResampleOptions::new()
.sample_rate(48000)
.channels(2)
.format::<f32>();
// 3. Transform into a resampled data pipeline
let mut resampled = reader.into_resampled(options)?;
// 4. Safely pull typed audio frames
while let Some(samples) = resampled.receive_frame_as::<f32>()? {
// `samples` is strictly typed as &[f32]
// process your interleaved samples here
}x86_64-pc-windows-msvci686-pc-windows-msvcaarch64-pc-windows-msvcaarch64-linux-androidarmv7-linux-androideabii686-linux-androidx86_64-linux-androidaarch64-apple-darwinx86_64-apple-darwinx86_64-unknown-linux-gnuaarch64-unknown-linux-gnuaarch64-apple-ios
Other target platforms are not currently supported.
The crates/ffmpeg_audio/examples directory contains runnable examples:
play.rs— A complete audio player usingcpalfor audio outputmetadata.rs— Extracts audio metadata and cover art from files
Run an example with:
cargo run --example play -- path/to/audio.mp3
cargo run --example metadata -- path/to/audio.flacThis is a Cargo workspace containing two crates:
ffmpeg_audio— High-level Rust API for audio decoding and resamplingffmpeg_audio_sys— Low-level FFI bindings to FFmpeg's C libraries
This crate focuses solely on audio decoding. The following features are not included:
- Video processing
- Encoders, muxers, and filters
- Swscale (video scaling/conversion)
- Hardware acceleration
- Device and network protocol support