HDR vs SDR
HDR (High Dynamic Range) is the newer and more advanced version of display technology that shows more colorful and brighter pictures on displays that support it. It is much superior to its predecessor SDR.
Videos in HDR format use 10-bits for storing color information and use different color transfer functions compared to SDR videos. For example SDR videos use the BT.709 color space whereas HDR uses BT.2020 along with SMPTE2084 color transfer function.
If you are working with an hdr video, there could be a number of reasons to convert it to SDR. If you are working on a system that does not support HDR, then the colors might look washed out (pale/faded). The only way to work around this to convert the video to SDR which will make it look similar (but inferior) to the HDR version without loosing too much color information.
In this post we shall take a look at how to convert an hdr video to sdr video using ffmpeg from the command line.
The original video details as shown by ffprobe:
ffprobe .\costa_rica_4k_60fps_hdr_uhd.webm -hide_banner |
Note the stream details indicating HDR:
yuv420p10le(tv, bt2020nc/bt2020/smpte2084) |
It indicates 10-bit color in bt2020 colorspace using smpte2084 color transfer function which is commonly used in HDR videos. If you see these details in any video then it is very likely saved in HDR format (and consequently needs an hdr capable display and media program to play properly).
The same details can be checked with VLC Player as well.
![](/2024/07/01/How-to-implement-the-HDR-content-to-SDR-content-by-ffmpeg/1.jpg)
First try converting a small duration of the clip with the ss and t options to verify if the output quality is acceptable or not.
ffmpeg -hide_banner -y -i .\costa_rica_4k_60fps_hdr_uhd.webm -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 -ss 5 -t 10 .\costa_rica_4k_60fps_sdr_uhd-10s.libx264.mp4 |
The above command will try to preserve the color and keep them as similar to the original, though it can never be like hdr quality. The filter process is a chain of multiple processing stages over here:
- zscale=t=linear:npl=100
- format=gbrpf32le
- zscale=p=bt709
- tonemap=tonemap=hable:desat=0
- zscale=t=bt709:m=bt709:r=tv
- format=yuv420p
Check the documentation of zscale filter and tonemap filter and format filter
Q: How to implement the HDR to SDR by ffmpeg?
A: Based on ffmpeg cmd:
another example:
ffmpeg -i video-input.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 libx265 -crf 22 -preset medium -tune fastdecode video-output.mp4 |