rff-codec 0.3.1

Remade FFmpeg (Rust): codec abstraction — Decoder/Encoder traits and the codec registry (libavcodec core).
Documentation

rff-codec

Remade With Rust By Mata Network License: Apache-2.0

The codec abstraction layer of remade_ffmpeg_rs — the Decoder and Encoder traits plus the CodecRegistry that every codec crate registers into. FFmpeg's libavcodec core, minus the codecs themselves.

  • Decoder / Encoder traits — push/pull, following the Again/Eof drain protocol from rff-core.
  • CodecRegistry — lookup by CodecId or by FFmpeg-style name ("vp9", "aac"), which is what powers ffmpeg -codecs.
  • Codec — the registration record: id, name, long name, media type, and optional decoder/encoder factories, so a codec can be decode-only or encode-only.
  • CodecParams — the negotiated stream parameters handed to a codec at open time.
  • Adding a codec is one register(&mut registry) call — no engine-core changes.

Usage

use rff_codec::{Codec, CodecRegistry};
use rff_core::{CodecId, Error, MediaType};

fn main() -> Result<(), Error> {
    let mut codecs = CodecRegistry::new();

    // Each rff-codec-* crate contributes one line like this.
    rff_codec_pcm::register(&mut codecs);

    // Lookup by id, or by the name the CLI accepts (`-c:a pcm`).
    let _decoder = codecs.find_decoder(CodecId::Pcm)?;
    let codec: &Codec = codecs.by_name("pcm").expect("just registered");
    assert_eq!(codec.media_type, MediaType::Audio);

    // `ffmpeg -codecs` is a walk over the registry.
    for c in codecs.iter() {
        println!("{:>6}  {}{}  {}", c.name,
            if c.can_decode() { "D" } else { "." },
            if c.can_encode() { "E" } else { "." },
            c.long_name);
    }
    Ok(())
}

Part of Remade With Rust

This crate is one layer of remade_ffmpeg_rs — a ground-up, permissively-licensed Rust rebuild of FFmpeg: a drop-in ffmpeg/ffprobe CLI on pure-Rust codecs, with no copyleft. Most users want the remade-ffmpeg engine facade or the rff-cli binaries rather than this crate directly.

Also check out our sister project FFAI — media for an AI-first world — and the rest of github.com/remade-with-rust, including the standalone codec crates rusty_h264, rusty_vp9, rusty_mp3, rusty_aac, rusty-opus, rusty_vorbis, and the rusty-av1-toolkit forks.

About Mata Network

Mata Network builds sovereign, self-hostable infrastructure. Remade With Rust is our open-source home for the permissively-licensed building blocks that work depends on.

License

Apache-2.0. See the workspace LICENSE.