View Full Version : HDR to SDR Near-Full Conversion
jay123210599
20th January 2025, 20:10
How do I convert HDR videos/movies to SDR, to the point where people will not notice the difference?
microchip8
20th January 2025, 20:21
You do tonemapping. Most people will not notice it's been converted if done right. Tonemapping is not perfect and will never be
GeoffreyA
20th January 2025, 20:54
How do I convert HDR videos/movies to SDR, to the point where people will not notice the difference?
https://forum.doom9.org/showthread.php?p=2011951#post2011951
jay123210599
20th January 2025, 22:48
https://forum.doom9.org/showthread.php?p=2011951#post2011951
But none of them will achieve the result I want?
GeoffreyA
20th January 2025, 23:24
But none of them will achieve the result I want?
Use the libplacebo version. Its results are excellent and, I reckon, will solve your problem. I'll post a cleaner version of the command tomorrow, but you can use that for now; it's the same and will work. The target resolution is 1080p, which you can adjust.
Are you aiming for a bit depth of 8 or 10 bits?
Also, what about your audio? Are you downmixing or copying straight over?
wonkey_monkey
21st January 2025, 01:24
How do I convert HDR videos/movies to SDR, to the point where people will not notice the difference?
If we could do that, there'd be no point in HDR in the first place.
jay123210599
21st January 2025, 03:00
Use the libplacebo version. Its results are excellent and, I reckon, will solve your problem. I'll post a cleaner version of the command tomorrow, but you can use that for now; it's the same and will work. The target resolution is 1080p, which you can adjust.
Are you aiming for a bit depth of 8 or 10 bits?
Also, what about your audio? Are you downmixing or copying straight over?
About my HDR video: It's a clip of a 2160p HDR movie with black bars. I want the output to trim out those black bars and I'm aiming for 10 bits.
GeoffreyA
21st January 2025, 10:24
This script will convert the video stream, discarding audio, to 10-bit BT.709 SDR, encoding as HEVC. Place in a BAT file, collapsing the FFmpeg command onto one line, set the crop values highlighted in bold, as well as x265 settings.
setlocal
set crop=Width:Height:Left:Top
ffmpeg -init_hw_device vulkan -i INPUT -map 0:v:0 -map_metadata -1 -vf libplacebo=upscaler=spline36:downscaler=spline36:w=1920:h=-1:
tonemapping=spline:gamut_mode=perceptual:
colorspace=bt709:color_trc=bt709:color_primaries=bt709:range=limited:format=yuv420p10le,
crop=%crop%:exact=true,sidedata=delete -c:v libx265 [...] OUTPUT
endlocal
pause
For my part, I prefer to add the cropping filter after libplacebo has processed everything, avoiding issues with scaling. The simplest way to get the cropping values are to open the source in VirtualDub2, add a resize filter to shrink to 1080p, and a crop filter after that. Crop the picture on a bright scene and note all numbers.
Now, where it says crop=Width:Height:Left:Top above, take your values from VD2 and substitute them. Generally, Height and Top are key. For example:
crop=1920:804:0:138
As others have noted, converting from HDR to SDR is a lossy process, and there is no one "right" way of doing it. A reasonable aim would be to match, come close to, or surpass the official 1080p version.
Z2697
21st January 2025, 21:46
It's not possible unless there's little to none highlight (when you playback them on non-crap HDR devices)
If the device is not HDR or crap HDR, it's likely been doing tonemapping already (or clipping which should be worse) so good tonemapping will give you similar or better looking
wswartzendruber
25th January 2025, 18:39
Question: Do you have control over which playback devices are used? I ask because I have found converting to HLG to work quite well. Most of the highlights are preserved on devices that can show them, yet it naturally looks like SDR when played back as such. The reason you need to control the playback is that some players absolutely suck at BT.2020->BT.709 color mapping.
GeoffreyA
26th January 2025, 07:24
Question: Do you have control over which playback devices are used? I ask because I have found converting to HLG to work quite well. Most of the highlights are preserved on devices that can show them, yet it naturally looks like SDR when played back as such. The reason you need to control the playback is that some players absolutely suck at BT.2020->BT.709 color mapping.
If you mean in reference to libplacebo, I'm not too sure but expect it to be able, having a rich selection of settings.
https://github.com/haasn/libplacebo/blob/master/docs/options.md
https://ffmpeg.org/ffmpeg-filters.html#libplacebo
wswartzendruber
27th January 2025, 16:35
If you mean in reference to libplacebo, I'm not too sure but expect it to be able, having a rich selection of settings.
https://github.com/haasn/libplacebo/blob/master/docs/options.md
https://ffmpeg.org/ffmpeg-filters.html#libplacebo
I wasn't referring to libplacebo specifically. I have written a tool set for converting from PQ to HLG:
Source: https://github.com/wswartzendruber/hlg-tools
Wiki: https://github.com/wswartzendruber/hlg-tools/wiki
Binaries: https://github.com/wswartzendruber/hlg-tools/releases
I'm not going to act like this is objectively the best way to go about things, but it does address what I believe to be the elephant in the room: 4K UltraHD discs are mastered with wildly varying levels of brightness. Fundamentally, if someone is downconverting from absolute brightness (HDR-PQ) to relative brightness (HDR-HLG and SDR), they have to know where reference white is on the PQ source. This is because the implicit definition of HDR-PQ over HDR-HLG and SDR is expanding the room between reference white and max white. And because of this, downconversion is the inverse: compressing the space between reference white and max white. If you get reference white wrong, you'll either over-compress or under-compress different brightness ranges.
lollo2
28th January 2025, 11:03
If we could do that, there'd be no point in HDR in the first place.
the only appropriate comment in this thread
wswartzendruber
28th January 2025, 18:14
the only appropriate comment in this thread
That's kind of why I proposed HLG as an alterative to SDR. Again, this depends on:
1. Correct brightness adjustment.
2. SDR playback on a BT.2020-aware player.
GeoffreyA
28th January 2025, 19:47
I wasn't referring to libplacebo specifically. I have written a tool set for converting from PQ to HLG:
Source: https://github.com/wswartzendruber/hlg-tools
Wiki: https://github.com/wswartzendruber/hlg-tools/wiki
Binaries: https://github.com/wswartzendruber/hlg-tools/releases
I'm not going to act like this is objectively the best way to go about things, but it does address what I believe to be the elephant in the room: 4K UltraHD discs are mastered with wildly varying levels of brightness. Fundamentally, if someone is downconverting from absolute brightness (HDR-PQ) to relative brightness (HDR-HLG and SDR), they have to know where reference white is on the PQ source. This is because the implicit definition of HDR-PQ over HDR-HLG and SDR is expanding the room between reference white and max white. And because of this, downconversion is the inverse: compressing the space between reference white and max white. If you get reference white wrong, you'll either over-compress or under-compress different brightness ranges.
I think it's an interesting tool. Using HLG as an alternative to SDR hadn't occurred to me.
lollo2
28th January 2025, 20:02
That's kind of why I proposed HLG as an alterative to SDR. Again, this depends on:
1. Correct brightness adjustment.
2. SDR playback on a BT.2020-aware player.
Makes sense. But note that the OP is a well known troll (videohelp forums are full of his non-sense) and he asked in purpose "to the point where people will not notice the difference?"
wswartzendruber
29th January 2025, 07:01
Makes sense. But note that the OP is a well known troll (videohelp forums are full of his non-sense) and he asked in purpose "to the point where people will not notice the difference?"
Perhaps by that he means that someone should not realize just from watching the video that it comes from a PQ source.
GeoffreyA
29th January 2025, 07:43
Perhaps by that he means that someone should not realize just from watching the video that it comes from a PQ source.
That's what I think: that the video should be indistinguishable from the "official" SDR version.
rwill
29th January 2025, 08:42
Makes sense. But note that the OP is a well known troll (videohelp forums are full of his non-sense) and he asked in purpose "to the point where people will not notice the difference?"
Regarding noticing if something has been hand graded to SDR or tonemapped down from HDR, it is more or less the same concept as at which point do people notice the difference between an honest question and a troll. Some will notice right away, some will if it is pointed out to them, some will never.
lollo2
29th January 2025, 15:39
That's what I think: that the video should be indistinguishable from the "official" SDR version.
OP meant SDR indistinguishable from HDR, that’s why he’s trolling
wswartzendruber
29th January 2025, 17:46
Regarding noticing if something has been hand graded to SDR or tonemapped down from HDR, it is more or less the same concept as at which point do people notice the difference between an honest question and a troll. Some will notice right away, some will if it is pointed out to them, some will never.
You can come close with HLG. Different players/services have different interpretations on how to render HLG on BT.709 displays, however.
https://wswartzendruber.net/images/alita-comparison-2.png
The top one is the SDR Blu-ray. The other two are sourced from the 4K UltraHD disc with the tool I wrote being used to do considerable exposure adjustment. (The HDR mastering on that disc is somewhat rancid.)
EDIT: YouTube Link (https://www.youtube.com/watch?v=9hqkMBvwqSc)
GeoffreyA
30th January 2025, 16:18
I think the middle one looks the best. The official SDR is somewhat too bright and flat, and the third one looks over-saturated.
By the way, regarding PQ to BT.709 SDR conversion, here's a comparison (https://slow.pics/s/uoEAYMbs) of the 1080p Blu-ray and libplacebo's SDR version made from the UHD Blu-ray.
Z2697
30th January 2025, 18:43
I think the middle one looks the best. The official SDR is somewhat too bright and flat, and the third one looks over-saturated.
By the way, regarding PQ to BT.709 SDR conversion, here's a comparison (https://slow.pics/s/uoEAYMbs) of the 1080p Blu-ray and libplacebo's SDR version made from the UHD Blu-ray.
Just from the images in your comparison, I think I prefer the official one. Tonemapped one looks too dark and saturated. But I don't know how original HDR looks in HDR environment.
huhn
30th January 2025, 18:56
the native bt 709 one clearly that's the creators intend.
wswartzendruber
31st January 2025, 02:56
Just from the images in your comparison, I think I prefer the official one. Tonemapped one looks too dark and saturated. But I don't know how original HDR looks in HDR environment.
EDIT: BLEH. I thought this was a response to me and it wasn't. I'm so important it's all about me! Apparently.
I don't think YouTube is handling things correctly. But the last time I looked at VLC's interpretation of HLG on Windows, it was pretty much right on the money.
HLG that's correctly graded is going to look a tad darker than native SDR. This is because SDR usually puts reference white at 91% signal strength while HLG puts it at 75% signal strength.
Of course, if you don't have a native SDR image for a side-by-side comparison, can you even tell that something is HLG-over-SDR in the first place?
https://wswartzendruber.net/images/insurrection-hlg-vlc-windows.png
GeoffreyA
31st January 2025, 10:34
Just from the images in your comparison, I think I prefer the official one. Tonemapped one looks too dark and saturated. But I don't know how original HDR looks in HDR environment.
the native bt 709 one clearly that's the creators intend.
It does look too saturated (much too orange and pink, I would say). I thought it was all right until this comparison. However, I haven't got an HDR TV or monitor. But, looking at these small sections on an HDR phone, I think the colour matches the libplacebo version. Perhaps the 4K was graded extravagantly; I don't know. Here are samples of those scenes (https://we.tl/t-qKRlgELhzN) (the second is not the exact shot but close).
HLG that's correctly graded is going to look a tad darker than native SDR. This is because SDR usually puts reference white at 91% signal strength while HLG puts it at 75% signal strength.
Of course, if you don't have a native SDR image for a side-by-side comparison, can you even tell that something is HLG-over-SDR in the first place?
Yes, native SDR versions tend to be brighter.
Z2697
31st January 2025, 11:48
It does look too saturated (much too orange and pink, I would say). I thought it was all right until this comparison. However, I haven't got an HDR TV or monitor. But, looking at these small sections on an HDR phone, I think the colour matches the libplacebo version. Perhaps the 4K was graded extravagantly; I don't know. Here are samples of those scenes (https://we.tl/t-qKRlgELhzN) (the second is not the exact shot but close).
Yes, native SDR versions tend to be brighter.
I managed to take a look at that movie in HDR, yes it does look like that...
huhn
31st January 2025, 12:48
It does look too saturated (much too orange and pink, I would say). I thought it was all right until this comparison. However, I haven't got an HDR TV or monitor. But, looking at these small sections on an HDR phone, I think the colour matches the libplacebo version. Perhaps the 4K was graded extravagantly; I don't know. Here are samples of those scenes (https://we.tl/t-qKRlgELhzN) (the second is not the exact shot but close).
Yes, native SDR versions tend to be brighter.
did you calibrate your device?
we don't know how the 4K was mastered we don't look at it.
wswartzendruber
31st January 2025, 17:02
Is there a PQ still of the image in question somewhere? Maybe like a 16-bit PNG or something.
Z2697
31st January 2025, 17:48
Using FFmpeg I copied one single I frame from the source as HEVC elementary stream. (Thanks to the short GOP of UHD / Bluray encoding)
My cut point is 07:56 and 08:37.
https://www.mediafire.com/folder/17wfvapz43qli
I didn't register to mediafire, maybe the link will expire after some time.
The movie is The Substance (2024)
GeoffreyA
31st January 2025, 19:28
did you calibrate your device?
we don't know how the 4K was mastered we don't look at it.
I didn't. This was a haphazard "test," actually as a side comment on wswartzendruber's Alita comparison, but it led to some interesting discoveries :)
wswartzendruber
31st January 2025, 21:17
I converted these to SDR myself. First I used my pq2hlg tool to convert them to HLG, and then I used a completely different LUT I generated a while back to shrink the gamut from BT.2020 to BT.709.
I'm not sure what the reference white level of this movie is, so I provided four screenshots total. Two at 100 nits and two at 203 nits.
http://wswartzendruber.net/images/07-56-100nits.png
http://wswartzendruber.net/images/07-56-203nits.png
http://wswartzendruber.net/images/08-37-100nits.png
http://wswartzendruber.net/images/08-37-203nits.png
This second LUT works by using the relatively new Oklab color model to basically hard-clip the color gamut. When FranceBB compared this to his commercial LUT, it was nearly identical except in the deep blues.
FranceBB
2nd February 2025, 01:16
I also joined the party and I downloaded the still frame from above, then I used my own function to see what it was:
VideoTek(Mode="PQ", Type="nits", Detailed=true)
https://i.imgur.com/14H94PJ.png
In the scene highlighted above we can see how the white is peaking slightly below the 203 nits mark, I'd say something around 180 nits probably.
If we check the official BT709 SDR version we can see that the white seems to peak at 80 nits, thus leading us to the conclusion that it was probably mastered from a log source that doesn't go at more than 200 nits.
VideoTek(Mode="SDR", Type="nits", Detailed=True)
https://i.imgur.com/ci3p01F.png
Using my PQ_to_BT709_v1.cube LUT via LinearTransformation() the result is the following:
https://i.imgur.com/3sRzL8d.png
Here's the script that gathers all the comparisons done so far:
FFVideoSource("D:\07-56.265")
SinPowerResize(704, 396)
official_pq=last
ImageSource("P:\07-56-100nits.png")
SinPowerResize(704, 396)
Converttoyv12()
VideoTek(Mode="SDR", Type="nits", Detailed=True)
Subtitle("LUT - HLGTools + Oklab (William)")
Crop(0, 0, -0, -520)
william=last
FFImageSource("P:\Official SDR vs. libplacebo SDR\unknown 0_1080p-BD SDR.webp")
Converttoyv12()
AddBorders(0, 138, 0, 138)
SinPowerResize(704, 396)
VideoTek(Mode="SDR", Type="nits", Detailed=True)
Subtitle("Official BT709 SDR Version")
Crop(0, 0, -0, -520)
official_bt709=last
FFImageSource("P:\Official SDR vs. libplacebo SDR\unknown 0_libplacebo SDR from HDR 4K-BD.webp")
Converttoyv12()
AddBorders(0, 138, 0, 138)
SinPowerResize(704, 396)
VideoTek(Mode="SDR", Type="nits", Detailed=True)
Subtitle("libplacebo Tonemapping")
Crop(0, 0, -0, -520)
libplacebo=last
ConvertBits(official_pq, 16)
ConvertYUVtoXYZ(Color=0, OutputMode=1, HDRMode=0, fullrange=false)
ConvertXYZ_Hable_HDRtoSDR(exposure_X=13)
ConvertXYZtoYUV(pColor=0)
Converttoyuv420()
ConvertBits(bits=8, dither=1)
VideoTek(Mode="SDR", Type="nits", Detailed=True)
Subtitle("Hable Tonemapping")
Crop(0, 0, -0, -520)
hable=last
ConvertBits(official_pq, 16)
ConvertYUVtoXYZ(Color=0, OutputMode=1, HDRMode=0, fullrange=false)
ConvertXYZ_Mobius_HDRtoSDR(exposure_X=38.5)
ConvertXYZtoYUV(pColor=0)
Converttoyuv420()
ConvertBits(bits=8, dither=1)
VideoTek(Mode="SDR", Type="nits", Detailed=True)
Subtitle("Mobius Tonemapping")
Crop(0, 0, -0, -520)
mobius=last
ConvertBits(official_pq, 16)
ConvertYUVtoXYZ(Color=0, OutputMode=1, HDRMode=0, fullrange=false)
ConvertXYZ_Reinhard_HDRtoSDR(exposure_X=20.5, contrast_X=0.7)
ConvertXYZtoYUV(pColor=0)
Converttoyuv420()
ConvertBits(bits=8, dither=1)
VideoTek(Mode="SDR", Type="nits", Detailed=True)
Subtitle("Reinhard Tonemapping")
Crop(0, 0, -0, -520)
reinhard=last
ConvertBits(official_pq, 16)
ConvertToPlanarRGB()
Cube("C:\Programmi\AviSynth+\LUTs\PQ_to_BT709_v1.cube")
Converttoyuv420()
ConvertBits(bits=8, dither=1)
VideoTek(Mode="SDR", Type="nits", Detailed=True)
Subtitle("LinearTransformation")
Crop(0, 0, -0, -520)
francebb=last
VideoTek(official_pq, Mode="PQ", Type="nits", Detailed=True)
Subtitle("Official BT2020 PQ Version")
Crop(0, 0, -0, -520)
pq=last
StackVertical(pq, official_bt709, libplacebo, william, hable, mobius, reinhard, francebb)
https://i.imgur.com/0y1G54f.png
Z2697
2nd February 2025, 05:57
Why "around"? Make more graduations under 203!
Or maybe add a line across the peak with values displayed. :o
GeoffreyA
2nd February 2025, 11:04
Bravo. I see fantastic work is going on here. I'll catch up soon, but I've been out of action, upgrading my CPU to a 5500GT, which doesn't seem to be working right with my B450 Tomahawk :(
kolak
2nd February 2025, 14:04
SDR version is not really a reference point as this is creative version of HDR grade done by colorist. You can't make a conversion which will give you "correct" SDR look for all titles out there. They all will be different as in most cases they are done by creative process, not math. This means you would have to take 1000 titles and make a conversion which works best for all of them on average.
In other words- taking one title as an example and trying to create best conversion (so it matches 'official SDR') is not the way to go.
wswartzendruber
2nd February 2025, 15:23
Oh hey, the gang who helped me write hlg-tools is showing up!
SDR version is not really a reference point as this is creative version of HDR grade done by colorist. You can't make a conversion which will give you "correct" SDR look for all titles out there. They all will be different as in most cases they are done by creative process, not math. This means you would have to take 1000 titles and make a conversion which works best for all of them on average.
In other words- taking one title as an example and trying to create best conversion (so it matches 'official SDR') is not the way to go.
This is what I was trying to get at with having to know where reference white is for each movie. And even that is just an approximate way of doing this.
Z2697
2nd February 2025, 19:06
Bravo. I see fantastic work is going on here. I'll catch up soon, but I've been out of action, upgrading my CPU to a 5500GT, which doesn't seem to be working right with my B450 Tomahawk :(
Are the old architecture CPUs "re-released" really worth it?
It's good to see a platform have such a long life, but they can just keep manufacturing old models.
Maybe it's a good marketing strategy? I don't know.
Z2697
2nd February 2025, 19:18
SDR version is not really a reference point as this is creative version of HDR grade done by colorist. You can't make a conversion which will give you "correct" SDR look for all titles out there. They all will be different as in most cases they are done by creative process, not math. This means you would have to take 1000 titles and make a conversion which works best for all of them on average.
In other words- taking one title as an example and trying to create best conversion (so it matches 'official SDR') is not the way to go.
I was trying to confirm that libplacebo is doing "correct" to make the tonemapped result look like the real HDR (of course, it's just a not-so-close approximation), because in the two screenshot of The Substance first posted, SDR and tonemapped HDR look so different.
Then we (at least GeoffreyA and I) just accepted that they are really that different.
FranceBB
2nd February 2025, 20:35
Oh hey, the gang who helped me write hlg-tools is showing up!
Yaaay, we may not talk quite as regularly as we used to, but we're still here. :)
SDR version is not really a reference point as this is creative version of HDR grade done by colorist.
Yes, up until a few years ago I would have said that the raw footage is generally shot and edited in log and then three different grades are performed by three different colorists:
- DCI P3 XYZ 48 nits
- BT709 YUV 100 nits
- BT2020 PQ YUV xxx nits
The first being for the theatrical release at the various cinemas (and the chroma is generally cranked up a bit to compensate for the low light environment and the fact that we're in the mesopic vision in which we're capturing a lot of luma but not quite as much chroma), the second is for the SDR version (i.e normal BD) and the third is the HDR version (i.e UHD BD). The reason why I wrote "xxx nits" is that it can really be anything up to 10,000 nits although I've only ever seen movies peaking up at 5000 nits max (and they were only in the special effects).
Anyway, this is not always the case and I've seen many studios doing a direct conversion of the theatrical release to create the BT2020 HDR PQ version. The movie above, not The Substance that Z2697 was talking about, but rather the one William mentioned with the screenshots, Alita, was one such case if I remember correctly.
That being said, you're right in saying that generally those are three different grades from three different colorists originating from the original log and therefore it's not possible to get the BT709 SDR version from the BT2020 HDR PQ one, however it's still a valid reference point nonetheless. Last but not least, up until now I've only really talked about cinema and blurays, but if you've ever watched a linear tv channel in UHD what you're getting is almost definitely BT2020 HLG instead which means that pretty much all movies and tv series airing (not streaming) are converted to HLG all the time and those conversions are done by the broadcasters themselves as the studios don't really generally grade movies in HLG (however TV series and documentaries often are).
GeoffreyA
3rd February 2025, 21:06
Are the old architecture CPUs "re-released" really worth it?
It's good to see a platform have such a long life, but they can just keep manufacturing old models.
Maybe it's a good marketing strategy? I don't know.
For those still on AM4 and not ready to migrate to a new platform, Zen 3 is the best option and quite an improvement over Zen 1. Going from Zen 2 to 3 will be smaller, and arguably not worth it.
As for the 5500GT and 5600GT, they are, indeed, marketing re-releases, but good value, being cheaper than the 5600G, of which they are rebadged versions. The steppings, CZN-A0, are the same.
For my part, unluckily, the B450 Tomahawk has compatibility issues with Cezanne. Presumably, it is a BIOS issue, but MSI is not interested in fixing this. The 5500GT booted up all right, but by the next day, the problems were pervasive; it locked up constantly, with graphical distortions. I'll be returning it tomorrow and have decided to stick with my old, trusty CPU till I build a new system from scratch. Perhaps AM6 when it comes!
wswartzendruber
5th February 2025, 03:26
For those still on AM4 and not ready to migrate to a new platform, Zen 3 is the best option and quite an improvement over Zen 1. Going from Zen 2 to 3 will be smaller, and arguably not worth it.
I was originally resolved to keep my 3950X until 2029. Then I saw a 5950X for $380 and was like, "Why not..."
I did get a noticeable frame bump with x265, but it's not dramatic.
GeoffreyA
5th February 2025, 06:50
I was originally resolved to keep my 3950X until 2029. Then I saw a 5950X for $380 and was like, "Why not..."
Leaving a good deal, not to mention performance on the table, is painful!
Post-Sandy Bridge, most CPUs can easily go for a decade.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.