Expand description
Audio and video codec implementations for OxiMedia.
This crate provides encoding and decoding for royalty-free codecs:
§Video Codecs
- AV1 — Alliance for Open Media codec (primary, feature
av1) - VP9 — Google’s royalty-free codec (feature
vp9) - VP8 — Google’s earlier royalty-free codec (feature
vp8) - Theora — Xiph.Org Foundation codec, VP3-based (feature
theora) - MJPEG — Motion JPEG, one JPEG baseline frame per video frame (feature
mjpeg) - APV — Advanced Professional Video, ISO/IEC 23009-13 (feature
apv) - FFV1 — Lossless video codec, RFC 9043 (feature
ffv1)
§Audio Codecs
- Opus — Modern low-latency audio codec (feature
opus) - Vorbis — Xiph.Org audio codec (always available)
- FLAC — Lossless audio (always available)
- PCM — Uncompressed audio (always available)
§Image Codecs
- JPEG-XL — ISO/IEC 18181, royalty-free (feature
jpegxl) - WebP — Google royalty-free (always available)
- GIF — Patents expired 2004 (always available)
- PNG / APNG — W3C royalty-free (always available)
- AVIF — AV1-based still image format (always available)
§Codec Feature Matrix
Full encode/decode support, bit-depth, and chroma subsampling per codec:
| Codec | Encode | Decode | Bit Depths | Chroma |
|---|---|---|---|---|
| AV1 | ✓ | ✓ | 8, 10, 12 | 4:2:0, 4:4:4 |
| VP9 | ✓ | ✓ | 8, 10 | 4:2:0 |
| VP8 | ✓ | ✓ | 8 | 4:2:0 |
| Theora | ✓ | ✓ | 8 | 4:2:0 |
| MJPEG | ✓ | ✓ | 8 | 4:2:0, 4:2:2, 4:4:4 |
| APV | ✓ | ✓ | 8, 10, 12 | 4:2:0, 4:2:2, 4:4:4 |
| FFV1 | ✓ | ✓ | 8 | 4:2:0, 4:2:2, 4:4:4 |
| H.263 | ✓ | ✓ | 8 | 4:2:0 |
| JPEG-XL | ✓ | ✓ | 8, 10, 12 | 4:2:0, 4:2:2, 4:4:4 |
| AVIF/AV1 | ✓ | ✓ | 8, 10, 12 | 4:2:0, 4:4:4 |
| APNG/PNG | ✓ | ✓ | 8, 16 | RGBA, Grayscale |
| GIF | ✓ | ✓ | 8 | Paletted |
| WebP | ✓ | ✓ | 8 | 4:2:0 (lossy), lossless |
| Opus | ✓ | ✓ | — | Mono/Stereo/Surround |
| Vorbis | ✓ | ✓ | — | Mono/Stereo/Surround |
| FLAC | ✓ | ✓ | 16, 24 | Mono/Stereo/Multi |
| PCM | ✓ | ✓ | 8, 16, 24, 32, f32 | Any |
Enable optional codecs via Cargo features:
[dependencies]
oximedia-codec = { version = "0.1.4", features = ["av1", "vp9", "opus", "jpegxl"] }Available features: av1 (default), vp9, vp8, theora, h263, opus,
ffv1 (default), jpegxl (default), mjpeg, apv, image-io (default).
§Architecture
All codecs implement unified traits:
VideoDecoder— Decode compressed packets to framesVideoEncoder— Encode frames to compressed packets
§JPEG-XL: ISOBMFF Container and Streaming Decode
The jpegxl module provides two output paths for animated JXL sequences:
§AnimatedJxlEncoder::finish_isobmff()
Wraps the bare JXL codestream in an ISOBMFF container (ISO Base Media File Format):
ftypbox — major brandjxl, compatible brandsjxl+isomjxllbox — JXL level 5jxlpbox — the bare codestream with theis_lastbit set
use oximedia_codec::jpegxl::{AnimatedJxlEncoder, JxlAnimation};
let anim = JxlAnimation { ticks_per_second: 30, ..Default::default() };
let mut encoder = AnimatedJxlEncoder::new(640, 480, 3, 8, 7, anim);
encoder.add_frame(&frame_rgb, 1)?;
// Produces ftyp + jxll + jxlp bytes, decodable by JxlStreamingDecoder
let isobmff_bytes: Vec<u8> = encoder.finish_isobmff()?;§JxlStreamingDecoder<R: Read> — Streaming Frame Iterator
JxlStreamingDecoder is a lazy frame iterator that auto-detects whether its
source is an ISOBMFF container or a bare native codestream:
| Format | Detection | Producer |
|---|---|---|
| ISOBMFF | bytes[4..8] == b"ftyp" and bytes[8..12] == b"jxl " | finish_isobmff() |
| Native | bytes[0..2] == [0xFF, 0x0A] | finish() |
use oximedia_codec::jpegxl::{AnimatedJxlEncoder, JxlAnimation, JxlStreamingDecoder};
use std::io::Cursor;
// Encode
let anim = JxlAnimation { ticks_per_second: 30, ..Default::default() };
let mut encoder = AnimatedJxlEncoder::new(640, 480, 3, 8, 7, anim);
encoder.add_frame(&frame_rgb, 1)?;
let bytes = encoder.finish_isobmff()?;
// Stream-decode frame by frame
for frame_result in JxlStreamingDecoder::new(Cursor::new(bytes))? {
let frame = frame_result?;
println!("frame {}x{}", frame.width, frame.height);
}§MJPEG: Baseline JPEG Compliance
The mjpeg module wraps oximedia-image’s pure-Rust JPEG baseline encoder and decoder.
The JPEG encoder emits DQT segments with quantization tables in the correct zigzag scan
order and achieves ≥28 dB PSNR at quality 85 for typical natural images.
§Example
use oximedia_codec::{VideoDecoder, Av1Decoder};
let mut decoder = Av1Decoder::new(&codec_params)?;
decoder.send_packet(&packet)?;
while let Some(frame) = decoder.receive_frame()? {
// Process decoded frame
}§Audio Example
use oximedia_codec::opus::OpusDecoder;
let mut decoder = OpusDecoder::new(48000, 2)?;
let audio_frame = decoder.decode_packet(&packet_data)?;Re-exports§
pub use vorbis::SimpleVorbisEncoder;pub use vorbis::VorbisConfig;pub use vorbis::VorbisEncConfig;pub use vorbis::VorbisEncoder;pub use vorbis::VorbisPacket;pub use vorbis::VorbisQuality;pub use audio::AudioFrame;pub use audio::ChannelLayout;pub use audio::SampleFormat;pub use error::CodecError;pub use error::CodecResult;pub use frame::ColorInfo;pub use frame::ColorPrimaries;pub use frame::FrameType;pub use frame::MatrixCoefficients;pub use frame::Plane;pub use frame::TransferCharacteristics;pub use frame::VideoFrame;pub use multipass::allocation::AllocationStrategy;pub use multipass::Allocator;pub use multipass::Analyzer;pub use multipass::Buffer;pub use multipass::BufferConfig;pub use multipass::ComplexityStats;pub use multipass::EncoderConfig as MultiPassConfig;pub use multipass::EncoderError;pub use multipass::EncodingResult;pub use multipass::FrameAllocation;pub use multipass::FrameComplexity;pub use multipass::LookaheadAnalysis;pub use multipass::LookaheadFrame;pub use multipass::MultiPassEncoder;pub use multipass::PassStats;pub use multipass::PassType;pub use multipass::SceneChangeDetector;pub use multipass::Stats;pub use multipass::VbvStatistics;pub use rate_control::AdaptiveAllocation;pub use rate_control::AdaptiveQuantization;pub use rate_control::AllocationResult;pub use rate_control::AnalysisResult;pub use rate_control::AqMode;pub use rate_control::BitrateAllocator;pub use rate_control::BlockQpMap;pub use rate_control::BufferModel;pub use rate_control::CbrController;pub use rate_control::ComplexityEstimator;pub use rate_control::ContentAdaptiveAllocator;pub use rate_control::ContentAnalyzer;pub use rate_control::ContentMetrics;pub use rate_control::ContentType;pub use rate_control::CqpController;pub use rate_control::CrfController;pub use rate_control::FrameStats;pub use rate_control::GopAllocationStatus;pub use rate_control::GopStats;pub use rate_control::Lookahead;pub use rate_control::QpResult;pub use rate_control::QpSelector;pub use rate_control::QpStrategy;pub use rate_control::RateControlMode;pub use rate_control::RateController;pub use rate_control::RcConfig;pub use rate_control::RcOutput;pub use rate_control::SceneChangeDetector as RcSceneChangeDetector;pub use rate_control::SceneChangeThreshold;pub use rate_control::SceneContentType;pub use rate_control::TextureMetrics;pub use rate_control::VbrController;pub use reconstruct::BufferPool;pub use reconstruct::CdefApplicator;pub use reconstruct::CdefBlockConfig;pub use reconstruct::CdefFilterResult;pub use reconstruct::ChromaSubsampling;pub use reconstruct::DeblockFilter;pub use reconstruct::DeblockParams;pub use reconstruct::DecoderPipeline;pub use reconstruct::EdgeFilter;pub use reconstruct::FilmGrainParams;pub use reconstruct::FilmGrainSynthesizer;pub use reconstruct::FilterDirection;pub use reconstruct::FilterStrength;pub use reconstruct::FrameBuffer;pub use reconstruct::GrainBlock;pub use reconstruct::LoopFilterPipeline;pub use reconstruct::OutputConfig;pub use reconstruct::OutputFormat;pub use reconstruct::OutputFormatter;pub use reconstruct::PipelineConfig;pub use reconstruct::PipelineStage;pub use reconstruct::PlaneBuffer;pub use reconstruct::PlaneType;pub use reconstruct::ReconstructResult;pub use reconstruct::ReconstructionError;pub use reconstruct::ResidualBuffer;pub use reconstruct::ResidualPlane;pub use reconstruct::StageResult;pub use reconstruct::SuperResConfig;pub use reconstruct::SuperResUpscaler;pub use reconstruct::UpscaleMethod;pub use tile::assemble_tiles;pub use tile::decode_tile_stream;pub use tile::decode_tiles_parallel;pub use tile::HeaderedTileEncodeOp;pub use tile::RawLumaEncodeOp;pub use tile::TileConfig;pub use tile::TileCoord;pub use tile::TileDecodeOp;pub use tile::TileDecodeResult;pub use tile::TileEncodeOp;pub use tile::TileEncodeStats;pub use tile::TileEncoder;pub use tile::TileResult;pub use pcm::ByteOrder;pub use pcm::PcmConfig;pub use pcm::PcmDecoder;pub use pcm::PcmEncoder;pub use pcm::PcmFormat;pub use traits::BitrateMode;pub use traits::DecoderConfig;pub use traits::EncodedPacket;pub use traits::EncoderConfig;pub use traits::EncoderPreset;pub use traits::VideoDecoder;pub use traits::VideoEncoder;pub use av1::Av1Decoder;pub use av1::Av1Encoder;pub use ffv1::Ffv1Decoder;pub use ffv1::Ffv1Encoder;pub use image::convert_rgb_to_yuv420p;pub use image::convert_yuv420p_to_rgb;pub use image::rgb_to_yuv;pub use image::yuv_to_rgb;pub use image::EncoderConfig as ImageEncoderConfig;pub use image::ImageDecoder;pub use image::ImageEncoder;pub use image::ImageFormat;pub use png::batch_encode as batch_encode_png;pub use png::best_encoder;pub use png::decode as decode_png;pub use png::encode_grayscale as encode_png_grayscale;pub use png::encode_rgb as encode_png_rgb;pub use png::encode_rgba as encode_png_rgba;pub use png::encoder_from_profile;pub use png::fast_encoder;pub use png::get_info as png_info;pub use png::is_png;pub use png::optimize as optimize_png;pub use png::transcode as transcode_png;pub use png::validate as validate_png;pub use png::Chromaticity;pub use png::ColorType as PngColorType;pub use png::CompressionLevel as PngCompressionLevel;pub use png::DecodedImage as PngImage;pub use png::EncoderBuilder as PngEncoderBuilder;pub use png::EncoderConfig as PngEncoderConfig;pub use png::EncodingProfile;pub use png::EncodingStats;pub use png::FilterStrategy;pub use png::FilterType;pub use png::ImageHeader as PngHeader;pub use png::PaletteEntry;pub use png::PaletteOptimizer;pub use png::ParallelPngEncoder;pub use png::PhysicalDimensions;pub use png::PngDecoder;pub use png::PngDecoderExtended;pub use png::PngEncoder;pub use png::PngEncoderExtended;pub use png::PngInfo;pub use png::PngMetadata;pub use png::SignificantBits;pub use png::TextChunk;pub use gif::is_gif;pub use gif::DisposalMethod;pub use gif::DitheringMethod;pub use gif::GifDecoder;pub use gif::GifEncoder;pub use gif::GifEncoderConfig;pub use gif::GifFrame;pub use gif::GifFrameConfig;pub use gif::GraphicsControlExtension;pub use gif::ImageDescriptor;pub use gif::LogicalScreenDescriptor;pub use gif::QuantizationMethod;pub use jpegxl::AnsDecoder;pub use jpegxl::AnsDistribution;pub use jpegxl::AnsEncoder;pub use jpegxl::BitReader as JxlBitReader;pub use jpegxl::BitWriter as JxlBitWriter;pub use jpegxl::DecodedImage as JxlImage;pub use jpegxl::JxlColorSpace;pub use jpegxl::JxlConfig;pub use jpegxl::JxlDecoder;pub use jpegxl::JxlEncoder;pub use jpegxl::JxlFrameEncoding;pub use jpegxl::JxlHeader;pub use jpegxl::JxlStreamingDecoder;pub use jpegxl::ModularDecoder;pub use jpegxl::ModularEncoder;pub use avif::AvifConfig;pub use avif::AvifDecoder;pub use avif::AvifEncoder;pub use avif::AvifImage;pub use avif::AvifProbeResult;pub use avif::YuvFormat;
Modules§
- apng
- APNG (Animated Portable Network Graphics) top-level encoder and decoder.
- audio
- Audio frame types and sample format definitions.
- av1
- AV1 codec implementation.
- av1_obu
- AV1 Open Bitstream Unit (OBU) parsing structures.
- avif
- AVIF (AV1 Image File Format) encoder and decoder.
- bitrate_
model - Bitrate modelling and estimation for video encoding.
- bitstream_
filter - Bitstream filters for codec-level NAL and OBU transformations.
- bitstream_
writer - Bitstream reading and writing utilities.
- celt
- Standalone CELT frame decoding types and scaffolding.
- codec_
caps - Codec capability discovery and hardware acceleration detection.
- codec_
probe - Codec identification from raw bitstream bytes.
- codec_
profile - Codec profile and level definitions, and constraint validation.
- codec_
registry - Codec registry — register and look up codecs by name, FOURCC, or
CodecId. - color_
range - Color range and level mapping for codec output.
- container
- ISOBMFF (ISO Base Media File Format) box utilities for container formats.
- entropy_
coding - Entropy coding primitives.
- entropy_
tables - Table-based CDF arithmetic coding for AV1 entropy coding optimization.
- error
- Codec-specific error types.
- error_
concealment - Error concealment for lost or corrupted video frames.
- features
- Codec capability and feature detection.
- ffv1
- FFV1 (FF Video Codec 1) lossless video codec.
- flac
- FLAC (Free Lossless Audio Codec) encoder and decoder.
- flac_
codec - Simplified FLAC codec using fixed linear prediction + Rice coding.
- frame
- Video frame types.
- frame_
queue - Encoder frame queue with PTS-ordered input, B-frame reorder buffer, and DTS calculation.
- frame_
types - Frame type management for video encoding.
- gif
- GIF (Graphics Interchange Format) codec implementation.
- gop_
structure - GOP (Group of Pictures) structure analysis and planning.
- hdr
- HDR Tone Mapping operators for High Dynamic Range to Standard Dynamic Range conversion.
- image
- Image I/O for thumbnails and frame extraction.
- intra
- Shared intra prediction module for AV1 and VP9 decoders.
- jpegxl
- JPEG-XL (ISO/IEC 18181) codec implementation.
- motion
- Motion estimation module for video encoders.
- multipass
- Multi-pass encoding with look-ahead for OxiMedia codecs.
- multipass_
quality - Multipass encoding quality comparison.
- nal_
unit - NAL unit handling for H.264/H.265.
- packet_
builder - Codec packet and frame building utilities.
- packet_
queue - Codec packet queuing and reordering.
- packet_
splitter - Packet splitting and fragment reassembly for codec bitstreams.
- pcm
- PCM (Pulse Code Modulation) codec — trivial encode/decode for raw audio.
- picture_
timing - Picture timing supplemental enhancement information (SEI) types.
- png
- PNG (Portable Network Graphics) codec implementation.
- profile_
level - Codec profile and level definitions.
- psycho_
visual - Psycho-visual masking model for perceptual rate control.
- quality_
metrics - Quality metrics for codec evaluation.
- rate_
control - Rate control module for video encoders.
- rate_
control_ accuracy - Rate control accuracy verification.
- reconstruct
- Video frame reconstruction pipeline.
- reference_
frames - Reference frame management for H.264/H.265 decoded picture buffers (DPB).
- scene_
change_ idr - Scene-change detection and adaptive I-frame (IDR) insertion.
- sei_nal
- SEI / NAL-unit helpers for VP8/AV1 metadata attachment.
- silk
- Standalone SILK frame decoding types and scaffolding.
- simd
- SIMD abstraction layer for video codec implementations.
- slice_
header - H.264/H.265 slice header types and parsing utilities.
- stats
- Bitstream quality statistics.
- stream_
info - Stream information parsing and media container metadata.
- tile
- Generic tile-based parallel frame encoding for OxiMedia codecs.
- tile_
encoder - Tile-based parallel frame encoding for OxiMedia codecs.
- traits
- Codec traits for video encoding and decoding.
- vbr_
twopass - VBR two-pass encoding state tracking.
- vorbis
- Vorbis audio encoder and decoder.
- webp
- WebP codec support.