VideoColorSpace
TheVideoColorSpace class describes the color representation of video content. It specifies how color values should be interpreted, including the color gamut (primaries), brightness encoding (transfer), and YUV conversion (matrix).
This class follows the W3C WebCodecs VideoColorSpace specification.
Quick Example
Constructor
Creates a newVideoColorSpace from initialization data.
Optional configuration object for the color space.
Properties
All properties are readonly after construction.The color primaries defining the color gamut. Returns
null if not specified.The transfer characteristics (gamma/EOTF) for brightness encoding. Returns
null if not specified.The matrix coefficients for RGB-to-YUV conversion. Returns
null if not specified.Whether full range (0-255) or limited range (16-235) is used. Returns
null if not specified.Methods
toJSON()
Returns a plain object representation of the color space, suitable for serialization.VideoColorSpaceInit object containing all color space properties.
Example: Serializing color space
Example: Serializing color space
Color Primaries
Color primaries define the color gamut (range of colors) that can be represented.| Primary | Description | Use Case |
|---|---|---|
bt709 | BT.709 (Rec. 709) | SDR, HD video, web video |
bt2020 | BT.2020 (Rec. 2020) | HDR, 4K/8K, wide color gamut |
smpte432 | DCI-P3 | Digital cinema, Apple displays |
bt470bg | BT.470 BG | Legacy PAL/SECAM |
smpte170m | SMPTE 170M | Legacy NTSC |
BT.709 - Standard Definition
BT.709 - Standard Definition
The standard for HD television and web video. Covers approximately 35% of visible colors.
This is the default for most SDR content and should be used for web distribution.
BT.2020 - Wide Color Gamut
BT.2020 - Wide Color Gamut
The standard for HDR and UHD content. Covers approximately 75% of visible colors.
Required for HDR10 and HLG content. Use with
pq or hlg transfer functions.DCI-P3 - Digital Cinema
DCI-P3 - Digital Cinema
Used in digital cinema projection and Apple displays. Covers approximately 45% of visible colors.
A middle ground between BT.709 and BT.2020.
Transfer Characteristics
Transfer characteristics (also called EOTF - Electro-Optical Transfer Function) define how brightness values are encoded.| Transfer | Description |
|---|---|
bt709 | SDR gamma curve (~2.4) |
pq | HDR10 Perceptual Quantizer (ST.2084) |
hlg | Hybrid Log-Gamma for broadcast HDR |
linear | Linear light (no gamma) |
iec61966-2-1 | sRGB (~2.2 gamma) |
smpte170m | SMPTE 170M (NTSC gamma) |
BT.709 - SDR Standard
BT.709 - SDR Standard
The standard gamma curve for SDR content. Uses approximately 2.4 gamma with a linear segment near black.
Use for all standard web and broadcast video.
PQ (Perceptual Quantizer) - HDR10
PQ (Perceptual Quantizer) - HDR10
The transfer function for HDR10 content (SMPTE ST.2084). Encodes absolute brightness up to 10,000 nits.
Provides the best HDR quality but requires display calibration. Most common HDR format.
HLG (Hybrid Log-Gamma) - Broadcast HDR
HLG (Hybrid Log-Gamma) - Broadcast HDR
A relative brightness encoding that is backward-compatible with SDR displays.
Used primarily in broadcast (BBC, NHK). Simpler than PQ and degrades gracefully on SDR displays.
Linear - Raw Light Values
Linear - Raw Light Values
No gamma correction applied. Values represent linear light intensity.
Used for compositing and color grading workflows, not for display.
Matrix Coefficients
Matrix coefficients define how RGB values are converted to/from YUV color space.| Matrix | Description | Use Case |
|---|---|---|
rgb | No conversion (RGB) | RGB-only formats |
bt709 | BT.709 coefficients | SDR HD video |
bt2020-ncl | BT.2020 non-constant luminance | HDR video |
bt470bg | BT.470 BG | Legacy PAL |
smpte170m | SMPTE 170M | Legacy NTSC |
For HDR content, always use
bt2020-ncl (non-constant luminance). The bt2020-cl (constant luminance) variant exists but is rarely used in practice.Common Presets
BT.709 SDR (Standard Web Video)
BT.2020 HDR10
BT.2020 HLG
DCI-P3 (Apple Devices)
Full Range RGB (Computer Graphics)
VideoColorSpaceInit Interface
The initialization object used to construct aVideoColorSpace.
null, meaning the value is unknown or unspecified.