1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//! Pure Rust H.264/AVC video decoder.
//!
//! A standalone, portable software H.264 decoder. Supports Baseline, Main,
//! and High profile (8-bit 4:2:0 progressive), with both CAVLC and CABAC
//! entropy coding, B-frames, multi-reference, weighted prediction, long-term
//! references, and multi-slice frames. NEON SIMD acceleration on aarch64.
//!
//! # Quick start
//!
//! ```no_run
//! use rust_h264::decoder::Decoder;
//! use rust_h264::nal::parse_annex_b;
//!
//! let bitstream = std::fs::read("input.h264").unwrap();
//! let nals = parse_annex_b(&bitstream);
//! let mut decoder = Decoder::new();
//!
//! for nal in &nals {
//! if let Ok(Some(frame)) = decoder.decode_nal(nal) {
//! // `frame` has y/u/v planes (4:2:0), width, height, pic_order_cnt
//! }
//! }
//! if let Some(frame) = decoder.flush() {
//! // final pending frame
//! }
//! ```
//!
//! # Input formats
//!
//! Two parsers are provided in the [`nal`] module:
//!
//! - [`nal::parse_annex_b`] for start-code delimited streams (`.h264` files,
//! RTP, broadcast TS).
//! - [`nal::parse_avcc`] + [`nal::parse_avcc_config`] for length-prefixed
//! streams from MP4/MKV containers.
//!
//! Both produce [`nal::NalUnit`] values that can be fed to
//! [`decoder::Decoder::decode_nal`].
//!
//! # Frame ordering
//!
//! [`decoder::Decoder::decode_nal`] returns frames in **decode order**, which
//! differs from display order whenever B-frames are present. To present
//! frames in display order, sort by `pic_order_cnt` within each GOP.
//!
//! Note that `decode_nal` returns the *previous* picture when it sees a new
//! one, so be careful about IDR boundary tracking — increment your GOP
//! counter **after** the call, not before. See `examples/dump_frames.rs` and
//! `examples/play.rs` for working patterns.
//!
//! # Not supported
//!
//! - Interlaced coding (MBAFF, field pictures)
//! - High 10 / 4:2:2 / 4:4:4 profiles (>8-bit, non-4:2:0 chroma)
//! - SP/SI slice types
//! - Slice groups / FMO