Skip to main content

ff_format/
hdr.rs

1//! HDR metadata types for high-dynamic-range video.
2//!
3//! This module provides [`Hdr10Metadata`] and [`MasteringDisplay`] for HDR10
4//! static metadata embedding.
5
6/// HDR10 static metadata (`MaxCLL` + `MaxFALL` + mastering display).
7///
8/// Pass to `VideoEncoderBuilder::hdr10_metadata` (in `ff-encode`) to embed
9/// HDR10 static metadata in the encoded output using
10/// `AV_PKT_DATA_CONTENT_LIGHT_LEVEL` and
11/// `AV_PKT_DATA_MASTERING_DISPLAY_METADATA` packet side data.
12///
13/// Setting this automatically configures the codec context with:
14/// - `color_primaries = BT.2020`
15/// - `color_trc = SMPTE ST 2084 (PQ)`
16/// - `colorspace = BT.2020 NCL`
17#[derive(Debug, Clone)]
18pub struct Hdr10Metadata {
19    /// Maximum Content Light Level in nits (e.g. 1000).
20    pub max_cll: u16,
21    /// Maximum Frame-Average Light Level in nits (e.g. 400).
22    pub max_fall: u16,
23    /// Mastering display colour volume (SMPTE ST 2086).
24    pub mastering_display: MasteringDisplay,
25}
26
27/// Mastering display colour volume (SMPTE ST 2086).
28///
29/// Chromaticity coordinates use a denominator of 50000 (each value represents
30/// `n / 50000` in CIE 1931 xy).  Luminance values use a denominator of 10000
31/// (each value represents `n / 10000` nits).
32///
33/// # Examples
34///
35/// BT.2020 D65 primaries / 1000 nit peak / 0.005 nit black:
36///
37/// ```
38/// use ff_format::hdr::MasteringDisplay;
39///
40/// let md = MasteringDisplay {
41///     red_x: 17000,   red_y: 8500,
42///     green_x: 13250, green_y: 34500,
43///     blue_x: 7500,   blue_y: 3000,
44///     white_x: 15635, white_y: 16450,
45///     min_luminance: 50,          // 0.005 nits
46///     max_luminance: 10_000_000,  // 1000 nits
47/// };
48/// ```
49#[derive(Debug, Clone)]
50pub struct MasteringDisplay {
51    /// Red primary x coordinate (×50000).
52    pub red_x: u16,
53    /// Red primary y coordinate (×50000).
54    pub red_y: u16,
55    /// Green primary x coordinate (×50000).
56    pub green_x: u16,
57    /// Green primary y coordinate (×50000).
58    pub green_y: u16,
59    /// Blue primary x coordinate (×50000).
60    pub blue_x: u16,
61    /// Blue primary y coordinate (×50000).
62    pub blue_y: u16,
63    /// White point x coordinate (×50000).
64    pub white_x: u16,
65    /// White point y coordinate (×50000).
66    pub white_y: u16,
67    /// Minimum display luminance (×10000, in nits).
68    pub min_luminance: u32,
69    /// Maximum display luminance (×10000, in nits).
70    pub max_luminance: u32,
71}