Add hdr_mode option: raw code-value decode for HDR sources - #6
Conversation
HDR/wide-gamut sources (PQ/HLG transfer or BT.2020 primaries) are
unconditionally routed through a tone-mapping pipeline (zscale linear ->
hable -> BT.709), so float32 output for HDR content is a display-oriented
SDR preview, not the source signal. Consumers that need the actual HDR
code values (training on PQ masters, colorimetric measurement) had no way
to opt out — measured on a PQ BT.2020 mezzanine, the tone-mapped output
carries 2.34x the chroma and inflated luminance vs the true code values.
hdr_mode="raw" skips the HDR block: YUV->RGB uses the stream's tagged
matrix and range only, and the transfer function is left untouched. The
default ("tonemap") is byte-identical to current behavior.
|
Runtime verification with the built wheel, on the PQ BT.2020 12-bit mezzanine (frame-0 float32 RGB vs an ffmpeg
|
A decoder should hand back the signal it decoded. The tone-mapped default silently corrupted signal-domain consumers (training targets, measurements), and its failure mode is invisible — plausible tensors with wrong values — while raw's failure mode in display pipelines is immediately visible (flat frames). Display consumers opt in with hdr_mode="tonemap". SDR sources are unaffected by either mode.
This reverts commit 407d04e.
|
Note on the last two commits: we briefly considered making |
HDR and wide-gamut sources, such as PQ, HLG, or BT.2020 content, are currently always passed through a tone-mapping pipeline before decoding: linearize with zscale, apply Hable tone mapping, then convert to BT.709. As a result, float32 output from HDR sources is an SDR preview intended for display, not a faithful representation of the original signal.
That is a problem for use cases that need the original HDR code values, such as training on PQ masters or performing colorimetric measurements. Until now, there was no way to disable tone mapping. On a PQ BT.2020 mezzanine file, for example, the tone-mapped output showed 2.34 times more chroma and higher luminance than the true source values.
The new
hdr_mode="raw"option skips the HDR tone-mapping stage. YUV-to-RGB conversion still respects the stream’s tagged matrix and range, but the transfer function is left unchanged. The default,"tonemap", remains byte-for-byte identical to the current behavior.