Expand description
§rusty_h264
A ground-up, pure-Rust H.264 codec — a Remade With Rust rebuild of
Cisco’s openh264. Unlike the FFI
bindings in openh264-rs, there is no C in the dependency tree: the codec
core is #![forbid(unsafe_code)], BSD-2 licensed, and embeddable anywhere.
The encoder produces compressed Constrained Baseline streams (intra
I_16x16/I_4x4/I_PCM, inter P-frames with quarter-pel motion
compensation, in-loop deblocking, and rate control) that decode bit-exactly
under reference decoders. The decoder handles the full Constrained
Baseline subset and is validated bit-exact against Cisco’s h264dec.
This facade re-exports the encoder, decoder, and shared types so downstream users depend on a single crate.
§Decoding a whole stream
Decoder::decode_stream is the one-call entry point — it splits access
units, assembles multi-slice pictures, and returns frames in display order:
use rusty_h264::{Encoder, EncoderConfig, Decoder, YuvFrame};
// Encode three frames.
let mut enc = Encoder::new(EncoderConfig::new(32, 32)).unwrap();
let mut stream = Vec::new();
for _ in 0..3 {
stream.extend_from_slice(&enc.encode(&YuvFrame::black(32, 32)));
}
let frames = Decoder::new().decode_stream(&stream).unwrap();
assert_eq!(frames.len(), 3);
assert_eq!((frames[0].width, frames[0].height), (32, 32));For streaming use, the lower-level Decoder::decode returns one picture per
access unit in decode order (pair it with Decoder::last_poc to reorder).
Structs§
- Decoder
- A Constrained Baseline H.264 decoder. Holds the most recent parameter sets and the previous decoded picture (the inter reference) across calls.
- Encoder
- A Constrained Baseline H.264 encoder.
- Encoder
Config - Configuration for an
crate::Encoder. - NalUnit
- A NAL unit: a header (type +
nal_ref_idc) plus its raw RBSP payload. - YuvFrame
- A raw planar YUV 4:2:0 frame (8-bit). Plane strides equal their widths; chroma planes are half-resolution in each dimension.
Enums§
- Chroma
Format - Chroma subsampling. The encoder supports 4:2:0 only for now.
- Decode
Error - Decode errors.
- Encode
Error - Errors that can arise constructing or driving the encoder.
- NalUnit
Type - NAL unit type (
nal_unit_type, 5 bits). Only the subset relevant to a Constrained Baseline encoder/decoder is named; others areOther. - Preset
- Speed/quality trade-off, in the spirit of x264’s
-preset. The bitstream is valid (and decodes bit-exactly) either way; only the encoder’s effort differs. - Profile
- H.264 profile. The encoder targets Constrained Baseline; the rest are named for parsing/identification only.
Constants§
- VERSION
- The crate version string.