View Full Version : HDR to SDR Full Conversion
jay123210599
1st December 2024, 03:53
How do I fully convert HDR videos/movies to SDR, so that the output SDR will have all the colors from the HDR input? Or, if that's not possible, how do I upload HDR videos to YouTube with all of its colors?
Also, do gif files support HDR? If so, how do I make those files with all of the HDR colors?
Z2697
1st December 2024, 04:53
If the SDR by definition is in contrast to HDR then the answer is absolutely not.
If you mean tranfer chararistics often used in SDR content (e.g. bt.1886) then the answer is maybe you won't like it.
I have a useful link for you, again:
https://www.google.com/search?q=how+to+upload+hdr+video+to+youtube
GIF? LOL.
GeoffreyA
1st December 2024, 09:42
Converting from 10-bit BT.2020 HDR to 8-bit BT.709 SDR is a lossy operation, going from bigger to smaller. Also, there is no one accepted way of doing it properly; each method gives different results. The tone-mapping step varies greatly depending on the choice of function: Reinhard, Hable, and Mobius are popular and give good results, particularly the first two.
Using FFmpeg (just take out the line-breaks I put in for clarity):
ffmpeg -i "INPUT.mkv" -map 0 -vf zscale=t=linear:npl=203,format=gbrpf32le,
tonemap=reinhard:desat=0,zscale=1920:-1:f=spline36,
zscale=m=709:t=709:p=709:r=limited:dither=error_diffusion,format=yuv420p,sidedata=delete
-c:v libx264 -profile:v high -level 4.1 -preset veryslow -tune film -crf 18 -aq-mode 3 -c:a copy -c:s copy "OUTPUT.mkv"
The latter requires the colour-space metadata to be set; if it doesn't work, try the following:
-vf zscale=min=bt2020nc:tin=smpte2084:pin=2020:rin=limited:m=gbr:t=linear:p=2020:dither=none:npl=203,format=gbrpf32le,
tonemap=reinhard:desat=0,zscale=1920:-1:f=spline36,
zscale=m=709:t=709:p=709:r=limited:dither=error_diffusion,format=yuv420p,sidedata=delete
(Adjust "npl" to change brightness: smaller means brighter; bigger, darker.)
In VapourSynth, using fmtconv:
from vapoursynth import core
clip = core.lsmas.LWLibavSource(filename)
clip = clip.fmtc.bitdepth(bits=32)
clip = clip.fmtc.resample(css="444")
clip = clip.fmtc.matrix(mats="2020", matd="rgb")
clip = clip.fmtc.transfer(transs="2084", transd="linear", match=2)
clip = clip.tonemap.Reinhard(exposure=1, peak=100)
#clip = clip.tonemap.Mobius(exposure=0.7, transition=0.3, peak=100)
#clip = clip.tonemap.Hable(exposure=1.9)
clip = clip.resize.Spline36(1920, 1080)
clip = clip.fmtc.primaries(prims="2020", primd="709")
clip = clip.fmtc.transfer(transs="linear", transd="709")
clip = clip.fmtc.matrix(mats="rgb", matd="709")
clip = clip.fmtc.resample(css="420")
clip = clip.fmtc.bitdepth(bits=8)
clip.set_output()
In VapourSynth, using zimg:
import vapoursynth as vs
clip = vs.core.lsmas.LWLibavSource(filename)
clip = clip.resize.Bilinear(format=vs.RGBS, matrix_in_s="2020ncl", transfer_in_s="st2084", primaries_in_s="2020", range_in_s="limited",
matrix_s="rgb", transfer_s="linear", primaries_s="2020", dither_type="none", nominal_luminance=203)
clip = clip.tonemap.Reinhard(exposure=1, peak=100)
#clip = clip.tonemap.Mobius(exposure=0.7, transition=0.3, peak=100)
#clip = clip.tonemap.Hable(exposure=1.9)
clip = clip.resize.Spline36(1920, 1080)
clip = clip.resize.Bilinear(format=vs.YUV420P8, matrix_in_s="rgb", transfer_in_s="linear", primaries_in_s="2020",
matrix_s="709", transfer_s="709", primaries_s="709", range_s="limited", dither_type="error_diffusion")
clip.set_output()
If you don't want to shrink the picture to 1080p, omit the resizing steps: "zscale=1920:-1:f=spline36" or "clip = clip.resize.Spline36(1920, 1080)."
jay123210599
1st December 2024, 15:43
@GeoffreyA But generally, there's no possible way to fully convert HDR to SDR and for it contain all of its colors, right?
Also, do you know if GIFs and APNGs can contain HDR colors?
GeoffreyA
1st December 2024, 17:13
@GeoffreyA But generally, there's no possible way to fully convert HDR to SDR and for it contain all of its colors, right?
Also, do you know if GIFs and APNGs can contain HDR colors?
In theory, no, because the range of colours in BT.2020 is bigger than BT.709; it covers more colours of the CIE 1931 space. I think in practice, though, most 2020 material converts well to 709's range, and I also suspect that most 2020 material is largely using the 709 range. Tone mapping is another issue that has to be dealt with.
Concerning GIFs, no, they can't hold HDR colours. Remember, they only support up to 256 colours. As for APNGs, I'm not clued up on them so cannot comment, but if they support BT.2020, then yes.
kolak
1st December 2024, 18:07
Largely maybe not, but it's not full Rec.2020 either, but most likely P3.
Some grades (newer ones) use full P3, others go barely outside Rec.709.
jay123210599
1st December 2024, 20:25
Largely maybe not, but it's not full Rec.2020 either, but most likely P3.
Some grades (newer ones) use full P3, others go barely outside Rec.709.
Is that for APNGs? What about WEBPs (still and animated)?
Z2697
2nd December 2024, 01:01
@GeoffreyA @kolak The point is what does jay mean by "SDR" and "colors". I'm pretty sure he doesn't know anything about them, what worse is that he's not even trying to understand them. This "entity" is like ChatGPT, or even worse.
In the case of the real SDR, since HDR and SDR, by definition, in a simplified speaking, is like "SDR is the subset of HDR", so the conversion is simply impossile, period.
In the case of converting or even reinterpreting the EOTFs usually used in HDR (e.g. PQ) to/as the EOTFs usually used in SDR (e.g. BT.1886), it's very much possible (but the result is not real SDR).
Primaries, I think it's a separate topic, not related to the dynamic range.
GeoffreyA
2nd December 2024, 06:36
Z2697, I think when people talk of HDR to SDR in colloquial terms, the following is technically meant: BT.2020 NCL or BT.2100 matrix; PQ or HLG transfer; and BT.2020 primaries > BT.709 matrix; BT.709/BT.1886 transfer; and BT.709 primaries. Also, usually, shrinking to 1080p from 2160p and dropping the bit depth. HDR has turned into a colloquialism for high dynamic range, wide colour gamut, and, more often than not, 2160p resolution. Arguably, we've got 4K TV and BD marketing to thank for that.
I think Jay is referring to the primaries and colour space, not dynamic range. But of course, the latter has to be also dealt with and is the most challenging part of the process.
Largely maybe not, but it's not full Rec.2020 either, but most likely P3.
Some grades (newer ones) use full P3, others go barely outside Rec.709.
Yes, good point.
Is that for APNGs? What about WEBPs (still and animated)?
Kolak is referring to video: film, drama, etc.
jay123210599
2nd December 2024, 08:23
But can APNGs and WEBPs (both still and animated) support HDR colors?
GeoffreyA
2nd December 2024, 08:56
But can APNGs and WEBPs (both still and animated) support HDR colors?
It seems that WebP can't: https://en.wikipedia.org/wiki/Comparison_of_graphics_file_formats#Technical_details
Apparently, PNG can, so APNG quite likely. This Netflix article explains a lot on the topic you're addressing. It's all about HDR in images. I look forward to reading it later when I've got time.
https://netflixtechblog.com/enhancing-the-netflix-ui-experience-with-hdr-1e7506ad3e8
jay123210599
2nd December 2024, 14:26
It seems that WebP can't: https://en.wikipedia.org/wiki/Comparison_of_graphics_file_formats#Technical_details
Apparently, PNG can, so APNG quite likely. This Netflix article explains a lot on the topic you're addressing. It's all about HDR in images. I look forward to reading it later when I've got time.
https://netflixtechblog.com/enhancing-the-netflix-ui-experience-with-hdr-1e7506ad3e8
In Wikipedia, it said that PNG can't support HDR colors.
GeoffreyA
2nd December 2024, 18:40
In Wikipedia, it said that PNG can't support HDR colors.
Netflix was able to do it with 16-bit PNGs and ICC profiles, so it is possible.
Z2697
2nd December 2024, 19:33
Netflix was able to do it with 16-bit PNGs and ICC profiles, so it is possible.
There's more detail in replies of one of the trolling threads that the entity "Jay" starts.
https://forum.doom9.org/showthread.php?p=2010086#post2010086
jay123210599
3rd December 2024, 13:02
I get it now, png itself doesn't support HDR, but it can using ICC profiles.
A quote from the article: "The key realization was that we could add an ICC Profile to each image to signal the HDR color profile of that image."
By the way, if I use a image format that does support HDR and then convert it to PNG, will that work too?
GeoffreyA
3rd December 2024, 13:17
By the way, if I use a image format that does support HDR and then convert it to PNG, will that work too?
I think it will depend on the software used. As the article notes, it's one big mess. I suspect most software will not add the necessary information to the PNG. It would be advisable to use something more modern like JPEG XL.
GeoffreyA
3rd December 2024, 13:18
There's more detail in replies of one of the trolling threads that the entity "Jay" starts.
https://forum.doom9.org/showthread.php?p=2010086#post2010086
That was a great explanation by JustinTArthur.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.