Skip to main content

Symphonia

A pure Rust multimedia format demuxing, tag reading, and audio decoding library supporting AAC, FLAC, MP3, Vorbis, and more

Features

Symphonia is designed to be a comprehensive audio decoding solution for Rust applications, offering powerful features with zero unsafe code.

Pure Rust

100% safe Rust with no unsafe code, providing memory safety and security guarantees

15+ Codecs

Support for AAC, FLAC, MP3, Vorbis, ALAC, PCM, ADPCM, and more

Multiple Formats

Demux MP4, MKV, OGG, WAV, AIFF, and CAF container formats

Metadata Reading

Read ID3v1/v2, Vorbis Comment, and other metadata formats

Gapless Playback

Full support for gapless playback across supported codecs

Auto Detection

Automatic format and codec detection from media sources

Modular Design

Feature flags for fine-grained control over dependencies

High Performance

Optional SIMD optimizations for maximum performance

Quick Example

Here’s a minimal example of decoding an audio file with Symphonia:
use symphonia::core::codecs::DecoderOptions;
use symphonia::core::formats::FormatOptions;
use symphonia::core::io::MediaSourceStream;
use symphonia::core::meta::MetadataOptions;
use symphonia::core::probe::Hint;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Open the media source
    let file = std::fs::File::open("audio.mp3")?;
    let mss = MediaSourceStream::new(Box::new(file), Default::default());

    // Create a hint to help the format registry
    let mut hint = Hint::new();
    hint.with_extension("mp3");

    // Probe the media source
    let probed = symphonia::default::get_probe()
        .format(&hint, mss, &FormatOptions::default(), &MetadataOptions::default())?;

    // Get the format reader
    let mut format = probed.format;

    // Find the first audio track
    let track = format
        .tracks()
        .iter()
        .find(|t| t.codec_params.codec != symphonia::core::codecs::CODEC_TYPE_NULL)
        .ok_or("no audio track found")?;

    // Create a decoder
    let mut decoder = symphonia::default::get_codecs()
        .make(&track.codec_params, &DecoderOptions::default())?;

    // Decode loop
    loop {
        let packet = match format.next_packet() {
            Ok(packet) => packet,
            Err(_) => break,
        };

        if packet.track_id() != track.id {
            continue;
        }

        let decoded = decoder.decode(&packet)?;
        // Process decoded audio samples...
    }

    Ok(())
}

Get Started

Installation

Add Symphonia to your Cargo.toml and enable the features you need

Quickstart

Learn the basics and decode your first audio file in minutes

Core Concepts

Understand Symphonia’s architecture and design principles

API Reference

Explore the complete API documentation

Supported Formats and Codecs

  • AAC-LC - Advanced Audio Coding (requires aac feature)
  • FLAC - Free Lossless Audio Codec (default)
  • MP3 - MPEG-1/2 Audio Layer III (requires mp3 feature)
  • Vorbis - Ogg Vorbis (default)
  • ALAC - Apple Lossless (requires alac feature)
  • PCM - Pulse Code Modulation (default)
  • ADPCM - Adaptive Differential PCM (default)
  • Opus - Opus codec (requires opus feature)
  • WavPack - WavPack lossless (requires wavpack feature)

Why Symphonia?

Written in 100% safe Rust with no unsafe code blocks, Symphonia provides strong memory safety guarantees and helps prevent common audio codec vulnerabilities like buffer overflows.
Symphonia aims to match or exceed the performance of popular C-based implementations like FFmpeg. With optional SIMD optimizations, performance is typically within ±15% of FFmpeg for most codecs.
Use feature flags to include only the codecs and formats you need, keeping binary sizes small and dependencies minimal. This modular design makes it easy to extend with custom codecs.
Works seamlessly across Linux, macOS, Windows, and other platforms supported by Rust. No platform-specific dependencies or system libraries required.

Community and Support

GitHub Repository

Star the repo, report issues, and contribute to the project

Examples

Explore working examples and sample projects

Benchmarks

Compare performance against other audio libraries

FAQ

Find answers to common questions

Build docs developers (and LLMs) love