Expand description
mediadecode
The backend-agnostic core of the mediadecode
workspace. Defines the unified Packet / Frame types,
VideoAdapter / AudioAdapter / SubtitleAdapter traits, and the
matching push-style *StreamDecoder traits that concrete decoder
backends implement.
This crate ships no decoder code and no FFmpeg dependency.
It’s no_std-clean (with optional alloc / std features) and zero
heavy deps — downstream crates (colconv, scenesdetect, …) program
against this vocabulary regardless of which backend produced the
bytes. Adapter implementations live in sibling crates such as
mediadecode-ffmpeg.
§What’s in the box
- Pixel and sample formats —
PixelFormat(~270 variants covering every FFmpegn8.1AVPixelFormatslug plus cinema-RAW additions; sourced fromvideoframeand re-exported here so consumers keep theirmediadecode::PixelFormatimport).Unknown(u32)preserves the raw wire identifier for lossless round-trip viafrom_u32/to_u32. H.273-aligned color enums (ColorMatrix,ColorPrimaries,ColorTransfer,ColorRange,ChromaLocation) andBayerPatternfor RAW are similarly re-exported fromvideoframe. - Generic packet / frame types —
VideoPacket<A, B>,AudioPacket<A, B>,SubtitlePacket<A, B>,VideoFrame<A, B>,AudioFrame<A, B>,SubtitleFrame<A, B>parameterized over an adapter’s per-item extras typeAand buffer typeB.Plane<B>is the generic plane carrier. - Adapter traits —
VideoAdapter,AudioAdapter,SubtitleAdapter. A backend implements these on a zero-sized type to fixAandBonce for the whole pipeline. - Decoder traits —
VideoStreamDecoder,AudioStreamDecoder,SubtitleStreamDecoder. Push-stylesend_packet/receive_frame/send_eof/flushshape; mirrors FFmpeg’s decoder API while staying backend-agnostic. - Time primitives — re-exported
Timebase/Timestamp/TimeRangefrommediatime, so consumers don’t need a separate dep.
§API style
Mirrors the mediatime idioms
the rest of the findit-studio workspace uses:
- All public fields are private; access is via
field()getters, consumingwith_field(value)builders, and in-placeset_field(value)mutators that return&mut Self. const fneverywhere the field type allows.- Panicking constructors come with
try_*fallible counterparts (empty/try_empty,clone/try_clone, …). - Errors via
thiserrorover the stablecore::error::Error, so failures still implement theErrortrait under--no-default-features.
§Cargo features
| Feature | Default | Effect |
|---|---|---|
std | yes | Enable the standard library and mediatime/default. |
alloc | — | Enable owning collections (Vec, String) without std. |
serde | — | Serialize / Deserialize impls (forwards to mediatime). |
arbitrary | — | Arbitrary impls for fuzzing. |
quickcheck | — | Arbitrary impls for quickcheck. |
no_std builds: disable defaults and pick alloc if you need
Vec-backed payloads:
[dependencies]
mediadecode = { version = "0.2", default-features = false, features = ["alloc"] }§Usage
This crate defines the surface; concrete decoding happens in adapter crates. A backend-agnostic consumer programs against the traits:
use mediadecode::{
decoder::VideoStreamDecoder,
frame::VideoFrame,
packet::VideoPacket,
};
fn decode_one<D: VideoStreamDecoder>(
decoder: &mut D,
packet: &VideoPacket<
<D::Adapter as mediadecode::adapter::VideoAdapter>::PacketExtra,
D::Buffer,
>,
dst: &mut VideoFrame<
<D::Adapter as mediadecode::adapter::VideoAdapter>::PixelFormat,
<D::Adapter as mediadecode::adapter::VideoAdapter>::FrameExtra,
D::Buffer,
>,
) -> Result<(), D::Error> {
decoder.send_packet(packet)?;
decoder.receive_frame(dst)
}For an end-to-end example using the FFmpeg adapter, see
mediadecode-ffmpeg.
§Build requirements
- Rust ≥ 1.95, edition 2024.
- No system dependencies —
mediadecodeis FFmpeg-free and builds anywhere Rust does, includingno_stdtargets with optionalalloc.
§License
mediadecode is under the terms of both the MIT license and the
Apache License (Version 2.0).
See LICENSE-APACHE, LICENSE-MIT for details.
Copyright (c) 2026 FinDIT Studio authors.
Modules§
- adapter
- Adapter traits — the per-kind backend “vocabulary.”
- cfa
- Color-filter-array (Bayer) descriptions: re-exported from
videoframe::frame(videoframe 0.2 dropped thecfamodule and movedBayerPatternunderframe::bayer, re-exported viaframe::*). - channel
- Audio channel layout types.
- color
- Color metadata: re-exported from
videoframe::color. - decoder
- Decoder traits — push-style streams (FFmpeg / WebCodecs / ProRes RAW via VTDecompressionSession) and pull-style frame sources (R3D / BRAW / ARRIRAW / X-OCN / Canon RAW Light).
- frame
- Frame types and supporting building blocks.
- future
future - Async variants of the decoder / frame-source traits — gated
behind the
futurefeature. - packet
- Compressed
Packettypes andPacketFlags. - pixel_
format - Pixel format identifier: re-exported from
videoframe::pixel_format. - subtitle
- Decoded subtitle payload.
Structs§
- Time
Range - A half-open time range
[start, end)in a givenTimebase. - Timebase
- A media timebase represented as a rational number: numerator over non-zero denominator.
- Timestamp
- A presentation timestamp, expressed as a PTS value in units of an associated
Timebase.
Enums§
- Pixel
Format - Pixel format identifier covering FFmpeg + Bayer + cinema-RAW.