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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//! Transparent HEVC via an auxiliary alpha layer (H.265 Annex F) — the
//! Apple/QuickTime/Safari format.
//!
//! # What a transparent HEVC access unit looks like
//!
//! Reverse-engineered byte-for-byte from an AVFoundation `hevcWithAlpha` file
//! (see `tests`/scratch tooling). One frame is a base **color** layer plus an
//! independent **alpha** layer, both self-contained:
//!
//! | NAL | `nuh_layer_id` | role |
//! |-----|---------------|------|
//! | VPS | 0 | 2 layers; `vps_extension` marks layer 1 as `AUX_ALPHA` |
//! | SPS | 0 | base color (Main, 4:2:0) |
//! | SPS | 1 | alpha layer — **self-contained** (`MultiLayerExtSpsFlag = 0`) |
//! | PPS | 0 | base |
//! | PPS | 1 | alpha |
//! | SEI (prefix) | 0 | [`alpha_channel_info`](alpha_channel_info_sei) (payloadType 165) |
//! | slice | 0 | base color picture |
//! | slice | 1 | alpha picture |
//!
//! Key facts established from the reference:
//! - `vps_extension`: `vps_max_layers_minus1 = 1`, `scalability_mask[3] = 1`
//! (AUXILIARY), layer 1 `dimension_id = 1` ⇒ `AuxId = 1` (`AUX_ALPHA`), and
//! `direct_dependency_flag[1][0] = 0` — the alpha layer is coded independently
//! of color (no inter-layer prediction).
//! - The alpha SPS begins `01 01 60 …`: `sps_ext_or_max_sub_layers_minus1 = 0`,
//! so it carries its own profile/chroma/resolution rather than inheriting a
//! VPS rep_format. That means each layer can be a normal self-contained SPS.
//! - The PPSs and the alpha SEI are resolution-independent; the VPS is not (its
//! `rep_format` + `dpb_size` vary), so a general encoder must *generate* the
//! `vps_extension`, not template it.
//!
//! # Status
//!
//! Done + verified here: the [`alpha_channel_info`](alpha_channel_info_sei) SEI
//! (byte-exact to Apple) and the per-layer coding — the base color layer and the
//! monochrome alpha layer each decode losslessly standalone (see
//! `HevcEncoder::new_monochrome` and `tests/hevc_ffmpeg.rs`).
//!
//! Remaining for a QuickTime-playable file: a `vps_extension` + `dpb_size`
//! generator (multi-layer, `AUX_ALPHA`) and an ISOBMFF/MP4 muxer with the alpha
//! `hvcC`. Those are tracked in the crate roadmap.
use crate;
/// Reference `pic_parameter_set_rbsp` bytes captured verbatim from Apple's
/// encoder (resolution-independent). Kept for cross-checking a generated PPS.
pub const APPLE_REF_PPS_BASE: = ;
/// Reference alpha-layer PPS bytes from Apple's encoder (resolution-independent).
pub const APPLE_REF_PPS_ALPHA: = ;
/// Reference `alpha_channel_info` SEI RBSP (payloadType 165) from Apple: use_idc
/// 1, 8-bit, transparent 0, opaque 255. [`alpha_channel_info_sei`] reproduces it.
pub const APPLE_REF_ALPHA_SEI: = ;
/// How the auxiliary layer's samples map to opacity (`alpha_channel_info`, F.14.2).
/// Build the `alpha_channel_info` SEI RBSP (H.265 F.14.2), the prefix SEI that
/// tells the decoder to treat the auxiliary layer as alpha. 8-bit alpha only.
///
/// With [`AlphaChannelInfo::default`] this is byte-identical to
/// [`APPLE_REF_ALPHA_SEI`].