5 releases (3 breaking)
| new 0.4.1 | Jan 6, 2026 |
|---|---|
| 0.4.0 | Oct 11, 2025 |
| 0.3.0 | Oct 10, 2025 |
| 0.2.0 | Sep 3, 2025 |
| 0.1.0 | Sep 3, 2025 |
#93 in Video
2,225 downloads per month
Used in 5 crates
(2 directly)
78KB
2K
SLoC
H.264 Annex B Parser
A Rust library for parsing H.264 Annex B bitstreams. This library provides parsing of NAL units, parameter sets (SPS/PPS), slice headers, and access unit assembly.
Features
- Annex B parsing: Handles start codes (0x000001 and 0x00000001)
- NAL unit parsing: Extracts and processes Network Abstraction Layer units
- Parameter sets: Decodes SPS (Sequence Parameter Set) and PPS (Picture Parameter Set)
- Access Units: Groups NAL units into frames/pictures
- Keyframe detection: Identifies IDR frames and recovery points
- SEI parsing: Basic support for Supplemental Enhancement Information
- Streaming support: Handles chunked input data
Usage
Add to your Cargo.toml:
[dependencies]
h264-parser = "0.4.1"
Basic example:
use h264_parser::AnnexBParser;
use std::fs::File;
use std::io::Read;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut file = File::open("video.h264")?;
let mut buffer = Vec::new();
file.read_to_end(&mut buffer)?;
let mut parser = AnnexBParser::new();
parser.push(&buffer);
while let Ok(Some(au)) = parser.next_access_unit() {
println!("Frame: keyframe={}", au.is_keyframe());
if let Some(ref sps) = au.sps {
println!(" Resolution: {}x{}", sps.width, sps.height);
}
for nal in au.nals() {
println!(" NAL: {:?}", nal.nal_type);
}
}
Ok(())
}
Architecture
The library is organized into the following modules:
- bytescan: Start code detection and NAL unit tokenization
- nal: NAL header parsing and EBSP/RBSP conversion
- bitreader: Bit-level reading utilities
- eg: Exp-Golomb encoding/decoding
- sps: Sequence Parameter Set parsing
- pps: Picture Parameter Set parsing
- sei: SEI message parsing
- slice: Slice header parsing
- au: Access Unit assembly
- parser: Main parser facade
Supported NAL Unit Types
- Non-IDR slices (P/B frames)
- IDR slices (I frames)
- SPS (Sequence Parameter Set)
- PPS (Picture Parameter Set)
- SEI (Supplemental Enhancement Information)
- AUD (Access Unit Delimiter)
- End of sequence/stream markers
Limitations
This is a parsing-only library that:
- Does not perform full H.264 decoding
- Does not manage DPB (Decoded Picture Buffer)
- Does not handle RTP packetization
- Does not provide muxing/demuxing capabilities