| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A lightweight FFmpeg audio decoding wrapper designed for music player applications.
This crate leverages FFmpeg's decoding capabilities and supports almost all audio formats, including:
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
}This crate covers all Rust Tier 1 targets and most mainstream Tier 2 targets. Highlights include:
For the full list of supported target triples, see get_config_dir_name().
Warning
Building for a target triple not listed in get_config_dir_name() might fail at compile time, or cause a runtime UB.
The crates/ffmpeg_audio/examples directory contains runnable examples:
Run an example with:
cargo run --example play -- path/to/audio.mp3
cargo run --example metadata -- path/to/audio.flacTo build for wasm32-unknown-emscripten, install the following prerequisites:
Emscripten SDK (emsdk) — Follow the official installation guide. After installation, make sure emcc is in your PATH.
Rust target:
rustup target add wasm32-unknown-emscriptenlibclang — Required by bindgen to generate C bindings. Most systems already have it; Emscripten SDK also ships one.
Then build as usual:
cargo build --target wasm32-unknown-emscripten --releaseThe output (a .js + .wasm pair) can be run with Node.js:
node target/wasm32-unknown-emscripten/release/your_app.jsThis crate focuses solely on audio decoding. The following features are not included:
| Back | FazBrowse Home | New Git URL |