mpeg-pes
PES (Packetized Elementary Stream) depacketization + PTS/DTS — the sublayer between an MPEG-TS packet layer and an elementary-stream consumer. Per ISO/IEC 13818-1 (Rec. ITU-T H.222.0) §2.4.3.6 / §2.4.3.7.
#![no_std] (+ alloc), depends only on dvb-common, WASM-clean. Pairs with
dvb-si for the TS/PSI layer:
TsPacket payload + payload_unit_start ──► mpeg-pes ──► PesPacket { stream_id, pts, dts, payload }
Quickstart
use ;
let bytes = ;
let pkt = parse?;
assert_eq!;
assert!;
assert_eq!;
assert_eq!;
# Ok::
Features
| Feature | Default | Effect |
|---|---|---|
std |
✅ | Link std. Off → #![no_std] + alloc. |
serde |
– | serde::Serialize on the public types. |
Scope
In: PES packet header, stream_id, PES_packet_length (incl. unbounded video
0), the optional header flags, and PTS/DTS (33-bit @ 90 kHz). Out:
elementary-stream codec bitstream parsing (the consumer's job); network transport
(see dvb-stream).
Examples
Run with cargo run -p mpeg-pes --example <name>:
parse_pes_packet— parse one PES packet from raw bytes (stream_id + PTS + payload).extract_pts— depacketize a real capture, reassemble PES on a PID, and report the PTS timeline.build_pes_header— construct a PES packet header from typed fields (PTS+DTS, ESCR, DSM trick mode), serialize, re-parse, and verify round-trip.
Building & editing PES headers
The [PesPacket::serialize_into] method lets you re-serialize a parsed or
hand-built packet byte-for-byte. Because [PesHeader] is #[non_exhaustive],
constructors from outside the crate currently need to assemble the wire bytes
using the public typed field encoders and then parse:
// Build raw bytes with PTS+DTS using the typed field encoders, then parse.
let pts = Pts;
let dts = Dts;
// (full example: `cargo run -p mpeg-pes --example build_pes_header`)
// Once parsed, round-trip through serialize_into:
let pkt = parse.unwrap;
let mut buf = vec!;
pkt.serialize_into.unwrap;
let re_pkt = parse.unwrap;
assert_eq!;
Run the worked example:
License
MIT OR Apache-2.0.