Skip to main content

ff_encode/video/builder/
color.rs

1//! Color, HDR, and pixel format settings for [`VideoEncoderBuilder`].
2
3use super::VideoEncoderBuilder;
4
5impl VideoEncoderBuilder {
6    /// Override the pixel format for video encoding.
7    ///
8    /// When omitted the encoder uses `yuv420p` by default, except that
9    /// H.265 `Main10` automatically selects `yuv420p10le`.
10    #[must_use]
11    pub fn pixel_format(mut self, fmt: ff_format::PixelFormat) -> Self {
12        self.pixel_format = Some(fmt);
13        self
14    }
15
16    /// Embed HDR10 static metadata in the output.
17    ///
18    /// Sets `color_primaries = BT.2020`, `color_trc = SMPTE ST 2084 (PQ)`,
19    /// and `colorspace = BT.2020 NCL` on the codec context, then attaches
20    /// `AV_PKT_DATA_CONTENT_LIGHT_LEVEL` and
21    /// `AV_PKT_DATA_MASTERING_DISPLAY_METADATA` packet side data to every
22    /// keyframe.
23    ///
24    /// Pair with [`codec_options`](Self::codec_options) using
25    /// `H265Options { profile: H265Profile::Main10, .. }`
26    /// and [`pixel_format(PixelFormat::Yuv420p10le)`](Self::pixel_format) for a
27    /// complete HDR10 pipeline.
28    #[must_use]
29    pub fn hdr10_metadata(mut self, meta: ff_format::Hdr10Metadata) -> Self {
30        self.hdr10_metadata = Some(meta);
31        self
32    }
33
34    /// Override the color space (matrix coefficients) written to the codec context.
35    ///
36    /// When omitted the encoder uses the FFmpeg default. HDR10 metadata, if set
37    /// via [`hdr10_metadata()`](Self::hdr10_metadata), automatically selects
38    /// BT.2020 NCL — this setter takes priority over that automatic choice.
39    #[must_use]
40    pub fn color_space(mut self, cs: ff_format::ColorSpace) -> Self {
41        self.color_space = Some(cs);
42        self
43    }
44
45    /// Override the color transfer characteristic (gamma curve) written to the codec context.
46    ///
47    /// When omitted the encoder uses the FFmpeg default. HDR10 metadata
48    /// automatically selects PQ (SMPTE ST 2084) — this setter takes priority.
49    /// Use [`ColorTransfer::Hlg`](ff_format::ColorTransfer::Hlg) for HLG broadcast HDR.
50    #[must_use]
51    pub fn color_transfer(mut self, trc: ff_format::ColorTransfer) -> Self {
52        self.color_transfer = Some(trc);
53        self
54    }
55
56    /// Override the color primaries written to the codec context.
57    ///
58    /// When omitted the encoder uses the FFmpeg default. HDR10 metadata
59    /// automatically selects BT.2020 — this setter takes priority.
60    #[must_use]
61    pub fn color_primaries(mut self, cp: ff_format::ColorPrimaries) -> Self {
62        self.color_primaries = Some(cp);
63        self
64    }
65}