Converting HDR down to SDR requires tone mapping, which folds the brightness range into a smaller one. What each stage of the ffmpeg filter chain does.
Sometimes you have to upload HDR video to a place that supports only SDR. If you simply treat the PQ code values as BT.709 video, the whole picture comes out hazy and dark. You need the tone mapping from Chapter 1: rearranging a wide brightness range to fit a narrow one.
ffmpeg -i input_hdr.mp4 \
-vf "zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p" \
-c:v libx264 -crf 18 -preset slow \
-color_primaries bt709 -color_trc bt709 -colorspace bt709 \
-c:a copy output_sdr.mp4Tone mapping has to be done in linear light. If you fold the brightness on top of nonlinear code values like PQ, the curve comes out wrong. So keep to the order: unwrap to linear, convert the gamut, tone map, then encode with the SDR curve again.
tin=arib-std-b67). PQ and HLG are unwrapped with different curves.tin, pin, min, and so on.ffmpeg -filters.hable, mobius, and reinhard differ in taste, in how to squeeze the highlights in. The same scene gets different highlight detail and a different overall brightness feel depending on the curve. Try the curves on a short clip (a few seconds), compare by eye, then run the whole video. If accurate color reproduction matters, then in principle it's better to grade a separate SDR version in your editor than to rely on automatic conversion.
An ffmpeg filter based on libzimg. It handles color gamut, transfer function, matrix, and range conversion, plus high-quality scaling.
A zscale option. The peak brightness (nits) used as the reference during the linear conversion.
The highlight compression curves offered by ffmpeg's tonemap filter.
Using only 16 to 235 in 8-bit versus using the whole 0 to 255. If they mismatch, blacks look lifted or crushed.
In an HDR-to-SDR tone mapping filter chain, why do we first convert the PQ code values to linear?