Symphonia

repository·main·Indexed 25 days ago

https://github.com/pdeljanov/symphonia

A pure Rust media container and audio decoding library supporting a wide range of popular audio codecs and container formats. It focuses on safety, performance, and gapless playback, providing a modular architecture via feature flags for formats, codecs, and metadata. The project includes developer tools such as symphonia-play for probing and playing media streams, and symphonia-check for validating decoded output against reference decoders like ffmpeg, flac, and mpg123.

Tokens
27.4K
Snippets
32
Records
194
Agent score
85%

What's inside Symphonia

  1. Overview of Symphonia Common Utilities

    main

    The symphonia-common crate provides shared utilities used by various codecs and formats within Project Symphonia.

    WARNING

    This crate is intended for internal use only. It is an implementation detail of Symphonia and is not designed for public consumption. It should only be used by first-party Symphonia demuxers or decoders.

  2. Understand Symphonia's demuxing and decoding architecture

    main

    Symphonia separates the process of reading container formats from the process of decoding codec bitstreams. This is achieved through two distinct layers:

    1. Demuxing (Format Reading): The process of reading a multimedia container to obtain packets for specific tracks. In Symphonia, this is handled by format readers, which implement the symphonia::core::formats::FormatReader trait.

    2. Decoding: The process of decompressing codec bitstream packets into playable data (like PCM audio samples). This is handled by decoders. For audio, decoders implement the symphonia::core::codecs::audio::AudioDecoder trait.

    To process a track, you must obtain packets from a FormatReader and then pass them to a decoder.

  3. Explore Symphonia examples

    main

    Symphonia provides example implementations to demonstrate core functionality. Two primary examples are available:

    • basic-interleaved.rs: Demonstrates how to decode an audio file and interleave the decoded samples, which is a common requirement for preparing audio for playback.
    • getting-started.rs: A foundational example designed for newcomers, covering the basic workflow of using the library.
  4. Implement a basic audio decode loop

    main

    A standard decoding loop follows these four steps repeatedly until format.next_packet() returns None:

    1. Acquire Packet: Get the next packet from the format reader using format.next_packet().
    2. Consume Metadata: Check if new metadata is available using format.metadata().is_latest() and pop old metadata if necessary.
    3. Filter Packet: Ensure the packet belongs to your selected track by checking packet.track_id == track_id.
    4. Decode Packet: Pass the packet to the decoder using decoder.decode(&packet) to obtain audio samples.

    Error Handling:

    • symphonia::core::errors::Error::ResetRequired: Indicates the track list has changed (e.g., chained OGG streams). You may need to re-examine tracks and recreate decoders.
    • symphonia::core::errors::Error::IoError or DecodeError: These are often non-fatal for the stream; you can skip the packet and continue.
  5. Use the symphonia crate instead of symphonia-core for general use

    main
    The symphonia-core crate is intended strictly for developers who are building new decoders or demuxers for Project Symphonia. If you are an end-user looking to decode audio files or use Symphonia's features in an application, you should use the high-level symphonia crate instead.
  6. Build ffbench for FFmpeg benchmarking

    main

    To perform a fair comparison with FFmpeg, use the ffbench tool from the pdeljanov/FFmpeg repository. This tool is preferred over the standard ffmpeg utility because it uses statically linked libraries and avoids the overhead of audio conversion to PCM S16LE.

    Follow these steps to build ffbench:

    1. Clone the FFmpeg repository.
    2. Checkout the symphonia-ffbench branch.
    3. Configure and build the examples.
    git clone https://github.com/pdeljanov/FFmpeg.git
    cd FFmpeg
    git checkout symphonia-ffbench
    ./configure
    make -j16
    make -j16 examples

    Run the benchmark using:

    ./doc/examples/ffbench /path/to/file/to/decode