Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Announcements and Chat > General Discussion

Reply
 
Thread Tools Search this Thread Display Modes
Old 1st December 2024, 03:53   #1  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 401
HDR to SDR Full Conversion

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?
jay123210599 is offline   Reply With Quote
Old 1st December 2024, 04:53   #2  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Posts: 529
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+...deo+to+youtube

GIF? LOL.
Z2697 is offline   Reply With Quote
Old 1st December 2024, 09:42   #3  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 349
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):

Code:
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:

Code:
-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:

Code:
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:


Code:
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)."

Last edited by GeoffreyA; 1st December 2024 at 09:52.
GeoffreyA is offline   Reply With Quote
Old 1st December 2024, 15:43   #4  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 401
@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?
jay123210599 is offline   Reply With Quote
Old 1st December 2024, 17:13   #5  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 349
Quote:
Originally Posted by jay123210599 View Post
@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.
GeoffreyA is offline   Reply With Quote
Old 1st December 2024, 18:07   #6  |  Link
kolak
Registered User
 
Join Date: Nov 2004
Location: Poland
Posts: 2,869
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.
kolak is offline   Reply With Quote
Old 1st December 2024, 20:25   #7  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 401
Quote:
Originally Posted by kolak View Post
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)?

Last edited by jay123210599; 1st December 2024 at 20:36.
jay123210599 is offline   Reply With Quote
Old 2nd December 2024, 01:01   #8  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Posts: 529
@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.

Last edited by Z2697; 2nd December 2024 at 01:08.
Z2697 is offline   Reply With Quote
Old 2nd December 2024, 06:36   #9  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 349
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.

Quote:
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.

Quote:
Is that for APNGs? What about WEBPs (still and animated)?
Kolak is referring to video: film, drama, etc.

Last edited by GeoffreyA; 2nd December 2024 at 07:25.
GeoffreyA is offline   Reply With Quote
Old 2nd December 2024, 08:23   #10  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 401
But can APNGs and WEBPs (both still and animated) support HDR colors?
jay123210599 is offline   Reply With Quote
Old 2nd December 2024, 08:56   #11  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 349
Quote:
Originally Posted by jay123210599 View Post
But can APNGs and WEBPs (both still and animated) support HDR colors?
It seems that WebP can't: https://en.wikipedia.org/wiki/Compar...hnical_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/enhancin...dr-1e7506ad3e8
GeoffreyA is offline   Reply With Quote
Old 2nd December 2024, 14:26   #12  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 401
Quote:
Originally Posted by GeoffreyA View Post
It seems that WebP can't: https://en.wikipedia.org/wiki/Compar...hnical_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/enhancin...dr-1e7506ad3e8
In Wikipedia, it said that PNG can't support HDR colors.
jay123210599 is offline   Reply With Quote
Old 2nd December 2024, 18:40   #13  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 349
Quote:
Originally Posted by jay123210599 View Post
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.
GeoffreyA is offline   Reply With Quote
Old 2nd December 2024, 19:33   #14  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Posts: 529
Quote:
Originally Posted by GeoffreyA View Post
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.p...86#post2010086
Z2697 is offline   Reply With Quote
Old 3rd December 2024, 13:02   #15  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 401
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?
jay123210599 is offline   Reply With Quote
Old 3rd December 2024, 13:17   #16  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 349
Quote:
Originally Posted by jay123210599 View Post
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 is offline   Reply With Quote
Old 3rd December 2024, 13:18   #17  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 349
Quote:
Originally Posted by Z2697 View Post
There's more detail in replies of one of the trolling threads that the entity "Jay" starts.
https://forum.doom9.org/showthread.p...86#post2010086
That was a great explanation by JustinTArthur.
GeoffreyA is offline   Reply With Quote
Reply

Tags
hdr to sdr, image-quality, youtube hq videos

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 23:10.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.