HDR -> SDR conversion

These CUDA filters are packaged into DGDecodeNV, which is part of DGDecNV.
Post Reply
User avatar
DJATOM
Posts: 176
Joined: Fri Oct 16, 2015 6:14 pm

Re: HDR -> SDR tonemapping

Post by DJATOM »

Narkyy wrote:
Sun Mar 25, 2018 2:49 pm
So I'm trying to test the DGTonemap plugin without DGSource (as I don't have a HEVC decoding GPU).
I'm not sure what the plugin expects as input. As 16 bit source, it returns double the height but a proper image at the top.
This is my script (cropping the bottom)

Code: Select all

LSMASHVideoSource("source.mp4", stacked=true, format="YUV420P16")
z_ConvertFormat(pixel_type="RGBPS",colorspace_op="2020ncl:st2084:2020:l=>rgb:linear:2020:l", dither_type="none")
dgtonemap(contrast=0.2, bright=7.0)
z_ConvertFormat(pixel_type="YV12",colorspace_op="rgb:linear:2020:l=>709:709:709:l",dither_type="ordered")
crop(0,280,0,-2440)
You can tell AviSynth+ about stacked things, but in your case you don't even need to spend cycles on conversion, just something like

Code: Select all

LSMASHVideoSource("source.mp4", format="YUV420P16")
ConvertFromDoubleWidth(16)
z_ConvertFormat(pixel_type="RGBPS",colorspace_op="2020ncl:st2084:2020:l=>rgb:linear:2020:l", dither_type="none")
dgtonemap(contrast=0.2, bright=7.0)
z_ConvertFormat(pixel_type="YV12",colorspace_op="rgb:linear:2020:l=>709:709:709:l",dither_type="ordered")
crop(0,280,0,-2440)
should work for you.
PC: RTX 2070 | Ryzen R9 5950X (no OC) | 64 GB RAM
Notebook: RTX 4060 | Ryzen R9 7945HX | 32 GB RAM
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

Cool, thanks for notifying us about that possibility. I'd never heard of that.
DAE avatar
Narkyy
Posts: 51
Joined: Thu May 25, 2017 11:51 pm

Re: HDR -> SDR tonemapping

Post by Narkyy »

Unfortunately that only made the width 1920, there was still garbage in the extra bottom 2160 pixels.
This is what worked though if anyone's interested: ConvertFromStacked(16) and crop(0,280,0,-280)
I'm not sure why but that works and it doesn't when LSMASH loads as stacked=false

Thanks for the help, I'll probably post some test samples soon :)
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

Maybe DJATOM knows something about that.

@all

I released a new version of DGTonemap that adds the Hable operator. Read the
DGTonemap.txt file as the usage has changed. Hable seems to preserve details
better to my eye.

http://rationalqm.us/DGTonemap.rar
User avatar
DJATOM
Posts: 176
Joined: Fri Oct 16, 2015 6:14 pm

Re: HDR -> SDR tonemapping

Post by DJATOM »

Code: Select all

LwlibavVideoSource("D:\ACCEL_WORLD_INFINITE_BURST_UHD\BDMV\STREAM\00004.m2ts")
ConvertFromDoubleWidth(bits=10)
ConvertBits(16)
That way I get native 16 bit video (checked with ConvertBits(8,dither=0) and ConvertToStacked(), both produce valid output for me.
PC: RTX 2070 | Ryzen R9 5950X (no OC) | 64 GB RAM
Notebook: RTX 4060 | Ryzen R9 7945HX | 32 GB RAM
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

Sweet! Thanks DJ. :salute:
User avatar
DJATOM
Posts: 176
Joined: Fri Oct 16, 2015 6:14 pm

Re: HDR -> SDR tonemapping

Post by DJATOM »

Also checked without up-conversion to 16 bits, that works as intended.

Code: Select all

LwlibavVideoSource("D:\ACCEL_WORLD_INFINITE_BURST_UHD\BDMV\STREAM\00004.m2ts")
ConvertFromDoubleWidth(bits=10)
z_ConvertFormat(pixel_type="RGBPS",colorspace_op="2020ncl:st2084:2020:l=>rgb:linear:2020:l", dither_type="none")
DGReinhard(contrast=0.55, bright=2.35)
z_ConvertFormat(pixel_type="YV12",colorspace_op="rgb:linear:2020:l=>709:709:709:l",dither_type="ordered")
PC: RTX 2070 | Ryzen R9 5950X (no OC) | 64 GB RAM
Notebook: RTX 4060 | Ryzen R9 7945HX | 32 GB RAM
DAE avatar
Guest

Re: HDR -> SDR tonemapping

Post by Guest »

In approximately two hours I will be able to post some comparative images of both filters versus sdr sample
DAE avatar
Guest

Re: HDR -> SDR tonemapping

Post by Guest »

New comparisons
Note
DGHable and DGReinhard at default
HDR clip was not not resized to 1080p
sdr 1
sdr 1.jpg
DGHable 1
DGHable 1.jpg
DGReinhard 1
DGReinhard 1.jpg
DAE avatar
Guest

Re: HDR -> SDR tonemapping

Post by Guest »

sample 2
sdr
sdr 2.jpg
DGHable
DGHable 2.jpg
DGReinhard
DGReinhard 2.jpg
DAE avatar
Guest

Re: HDR -> SDR tonemapping

Post by Guest »

sample 3
sdr
sdr 3.jpg
DGHable
DGHable 3.jpg
DGReinhard
DGReinhard 3.jpg
DAE avatar
Guest

Re: HDR -> SDR tonemapping

Post by Guest »

sample 4
sdr
sdr 4.jpg
DGHable
DGHable 4.jpg
DGReinhard
DGReinhard 4.jpg
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

Thank you, gonca. Great variety of scene types. :salute:

Maybe Hable needs to come down a notch in exposure to 2.0. Both operators work acceptably. I'm not sure which I prefer.
DAE avatar
Guest

Re: HDR -> SDR tonemapping

Post by Guest »

It might be a relevant point that those images are in jpg format, forum doesn't allow bmp
DAE avatar
Narkyy
Posts: 51
Joined: Thu May 25, 2017 11:51 pm

Re: HDR -> SDR tonemapping

Post by Narkyy »

I think default settings really don't do it justice. SDR is first.
Settings I used (adjusted for other scenes too): exposure=1.6, b=0.40, c=0.11, d=0.30, e=0.019, w=20
I prefer Hable because it's more flexible, while Reinhard only has contrast/white adjustments.

01.png
02.png
03.png
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

gonca wrote:
Mon Mar 26, 2018 7:52 pm
It might be a relevant point that those images are in jpg format, forum doesn't allow bmp
I added BMP to the allowed extensions.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

Narkyy wrote:
Mon Mar 26, 2018 7:55 pm
I think default settings really don't do it justice.
Thanks for the testing and yes, I agree Hable needs a smaller default exposure.
DAE avatar
dmcs
Posts: 36
Joined: Sat Oct 21, 2017 9:40 pm

Re: HDR -> SDR tonemapping

Post by dmcs »

I feel like without an HDR monitor as a reference, every setting would be a guess-timate. Trying to pick the right setting is quite a challenge. :D
DAE avatar
Guest

Re: HDR -> SDR tonemapping

Post by Guest »

I have a HDR TV being used as a monitor
The problem is that I can't capture a picture from the UHD source while retaining the HDR, metadata, of the original to post
I can compare by playing the clips but then no one else sees them
DAE avatar
Dion
Posts: 28
Joined: Sun Dec 04, 2016 12:30 am

Re: HDR -> SDR tonemapping

Post by Dion »

dmcs wrote:
Mon Mar 26, 2018 8:05 pm
I feel like without an HDR monitor as a reference, every setting would be a guess-timate. Trying to pick the right setting is quite a challenge. :D
HDR color mapping is set by the user.. and in the case of Monitor / TV's the manufacturer LG, Sony & Samsung etc..

So there is no correct way.. It's all your way.
User avatar
Selur
Posts: 134
Joined: Mon Nov 05, 2012 3:49 pm
Location: Germany
Contact:

Re: HDR -> SDR tonemapping

Post by Selur »

Small note about nvhsp: It only patches the first header and is only meant for the output of nvencc, but is not really needed nowadays since nvencc itself supports hdr related signaling.

@admin: Are you planning to port DGTonemap to Vapoursynth? (I'd like a gpu based alternative to tonemap)

Cu Selur
DAE avatar
Guest

Re: HDR -> SDR tonemapping

Post by Guest »

NVEncC does accept the HDR signalling through the command line since a few versions ago.
Both work, so they are both good, depending on workflow
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

Thanks for the useful info, guys.
Selur wrote:
Sun Apr 01, 2018 6:41 am
Are you planning to port DGTonemap to Vapoursynth? (I'd like a gpu based alternative to tonemap)
Yes, I will. And I'm depackaging filters so they can be open-sourced. Only DGSource() will remain closed.
DAE avatar
Nginx
Posts: 26
Joined: Fri Mar 23, 2018 12:48 am

Re: HDR -> SDR tonemapping

Post by Nginx »

admin wrote:
Sun Apr 01, 2018 7:40 am
Thanks for the useful info, guys.
Selur wrote:
Sun Apr 01, 2018 6:41 am
Are you planning to port DGTonemap to Vapoursynth? (I'd like a gpu based alternative to tonemap)
Yes, I will. And I'm depackaging filters so they can be open-sourced. Only DGSource() will remain closed.
Sounds real great. :hat:
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

Ready for a splash of ice water in the face, guys? I already took one. :(

Here's the deal. A CUDA version of DGTonemap is currently useless, for two reasons: a) the overhead of transferring three (R, G, B) float images to/from the GPU makes the CUDA version perform worse than simply doing things in SW with a decent prefetch, and b) the overall time is heavily dominated by the SW conversions, so that even if the tonemapping part performed better with CUDA, it would have little overall effect.

So, what is the morale of this story? Everything has to be done on the GPU, i.e, ship up one 16-bit frame, convert to 709 and tonemap, and ship back the frame. Then we could expect a large speedup. Got my work cut out for me. :scratch:
Post Reply