HDR -> SDR conversion

These CUDA filters are packaged into DGDecodeNV, which is part of DGDecNV.
DAE avatar
douzi
Posts: 6
Joined: Fri May 25, 2018 3:28 am

Re: HDR -> SDR tonemapping

Post by douzi »

Hi,

I have trouble loading the plugin DGHDRtoSDR.dll

I am using AviSynth+ 0.1 (r2664, MT, x86_64), with 64bit AvsPmod. I have VC++ redistributable 2005,2008,2010,2012,2013,2017 (x64) installed.

Script:
LoadPlugin("C:\Program Files (x86)\AviSynth+\plugins64+\DGHDRtoSDR.dll")

Error:
Cannot load file 'C:/Program Files (x86)/AviSynth+/plugins64+/DGHDRtoSDR.dll". Platform returned code 126: The specified module could not be found.

I don't have DGDecodeNV and I don't have an nVidia GPU.

Could you please help to locate where is the problem?

Thanks!
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

douzi wrote:
Fri May 25, 2018 3:33 am
I have trouble loading the plugin DGHDRtoSDR.dll
Greetings douzi and welcome to the forum.

Please re-download and try again, as I have configured nvcuda.dll as delay loading. Of course you need the parameter impl="sw" or you will receive an error. Please advise if it is loading for you.

Be warned that software mode is slow.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

To those who have posted samples and suggested new default values: Thank you! Before deciding on the final defaults, which of course will use your input, I am adding a graph feature that will allow the tonemapping curve to be visualized. It should help us both to be more scientific in our conclusions and to more easily know the effects of our parameter settings.
DAE avatar
Guest

Re: HDR -> SDR tonemapping

Post by Guest »

admin wrote:
Fri May 25, 2018 8:49 am
To those who have posted samples and suggested new default values: Thank you! Before deciding on the final defaults, which of course will use your input, I am adding a graph feature that will allow the tonemapping curve to be visualized. It should help us both to be more scientific in our conclusions and to more easily know the effects of our parameter settings.
That would be a great help to hopefully point out small effects
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

For sure. I have it working and I have already discovered that Hable (with the commonly used parameters) is not doing what we think, it looks like a gamma correction; there is no toe, linear section, and shoulder. I have searched for a user-friendly description of the 8 (!) parameters but not found anything useful, and I haven't been able to find parameters that give the filmic curve. I'm planning to write my own filmic operator with intuitive parameters.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

@douzi

I tested on my laptop with no nVidia and the DLL loads and runs fine. Make sure you have Avisynth+ installed with its run-time dependencies. You can use AVSMeter -avsinfo to check the installation.
DAE avatar
Guest

Re: HDR -> SDR tonemapping

Post by Guest »

admin wrote:
Fri May 25, 2018 3:33 pm
For sure. I have it working and I have already discovered that Hable (with the commonly used parameters) is not doing what we think, it looks like a gamma correction; there is no toe, linear section, and shoulder. I have searched for a user-friendly description of the 8 (!) parameters but not found anything useful, and I haven't been able to find parameters that give the filmic curve. I'm planning to write my own filmic operator with intuitive parameters.
The problem now is that we are trying to pick settings for what is meant for a video from a handful of frames
It might look good on 5 frames but not so good on the other 99995 frames in the video
The graph will allow a "visualization" of the overall effect
Great idea :bravo:
DAE avatar
douzi
Posts: 6
Joined: Fri May 25, 2018 3:28 am

Re: HDR -> SDR tonemapping

Post by douzi »

Hi,

Thanks for the quick reply.

I redownloaded the plugin (1.2 version) and tried again, still not loading. As for sw mode it is specified when doing the tonemap not in loading the plugin so I don't think that is the issue.

AVSmeter64 log:
AVSMeter 2.7.6 (x64) - Copyright (c) 2012-2018, Groucho2004

VersionString: AviSynth+ 0.1 (r2664, MT, x86_64)
VersionNumber: 2.60
File / Product version: 0.1.0.0 / 0.1.0.0
Interface Version: 6
Multi-threading support: Yes
Avisynth.dll location: C:\Windows\SYSTEM32\avisynth.dll
Avisynth.dll time stamp: 2018-03-29, 03:59:26 (UTC)
PluginDir2_5 (HKLM, x64): C:\Program Files (x86)\AviSynth+\plugins64
PluginDir+ (HKLM, x64): C:\Program Files (x86)\AviSynth+\plugins64+


[CPP 2.6 Plugins (64 Bit)]
C:\Program Files (x86)\AviSynth+\plugins64+\ConvertStacked.dll [2018-03-29]
C:\Program Files (x86)\AviSynth+\plugins64+\DGHDRtoSDR.dll [2018-05-22]
C:\Program Files (x86)\AviSynth+\plugins64+\DirectShowSource.dll [2018-03-29]
C:\Program Files (x86)\AviSynth+\plugins64+\ffms2.dll [2016-12-29]
C:\Program Files (x86)\AviSynth+\plugins64+\ImageSeq.dll [2018-03-29]
C:\Program Files (x86)\AviSynth+\plugins64+\Shibatch.dll [2018-03-29]
C:\Program Files (x86)\AviSynth+\plugins64+\TimeStretch.dll [2018-03-29]
C:\Program Files (x86)\AviSynth+\plugins64+\VDubFilter.dll [2018-03-29]

[Scripts (AVSI)]
C:\Program Files (x86)\AviSynth+\plugins64+\colors_rgb.avsi [2016-07-05]
C:\Program Files (x86)\AviSynth+\plugins64+\FFMS2.avsi [2015-05-22]

[Uncategorized files]
C:\Program Files (x86)\AviSynth+\plugins64+\colors_rgb.txt [2016-07-05]



[Plugin errors]
______________________________________________________________________________________________________________________

Cannot load file 'C:/Program Files (x86)/AviSynth+/plugins64+/DGHDRtoSDR.dll'. Platform returned code 126:
The specified module could not be found.

Dependencies that could not be loaded:
nvcuda.dll
______________________________________________________________________________________________________________________
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

Are you absolutely sure you got and are loading the new one from today? Try loading it manually not through the plugins dir. It's working fine for me.
DAE avatar
douzi
Posts: 6
Joined: Fri May 25, 2018 3:28 am

Re: HDR -> SDR tonemapping

Post by douzi »

Sorry I used the link in previous post.

Anyway redownload from http://rationalqm.us/misc/ and now it is successfully loading and with sw mode I can do the tonemap.

Thanks for your hard work!
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

Great to hear, douzi. Thanks for the update.
DAE avatar
Narkyy
Posts: 51
Joined: Thu May 25, 2017 11:51 pm

Re: HDR -> SDR tonemapping

Post by Narkyy »

I think light defaults for Gamma should be left like they are now, it all depends on the film tonemapped so it should be adjusted by the user.
Resized to 720p to take less space

default vs light=0.55
1.png
2.png
3.png
4.png
DAE avatar
douzi
Posts: 6
Joined: Fri May 25, 2018 3:28 am

Re: HDR -> SDR tonemapping

Post by douzi »

Hi,

I encountered some issue with highlights with DGHDRtoSDR.

Here's three-way comparison between DG(sw mode, hable) vs. MadVR (130nits, dumb mode, late gamut conversion) vs.VS Hable
The third one with Hable in vapoursynth is using the script here: https://forum.doom9.org/showthread.php? ... ost1832071

Same issue for "gamma" and "reinhard" too.

Image Image Image

Here's a link to the sample (screenshots at frame #400):
https://mega.nz/#!O0sEDTKZ!f-2a2cJEcKpx ... fTn4YMlPao
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

"I encountered some issue with highlights with DGHDRtoSDR."

Can you please tell me what the issue is specifically? Refer to specific areas of specific frames and say what you think is wrong with them. I'm not good at guessing games. ;)
DAE avatar
douzi
Posts: 6
Joined: Fri May 25, 2018 3:28 am

Re: HDR -> SDR tonemapping

Post by douzi »

Sorry, forgot to point out its in the highlights, look at the lighting in the blue light bars, it looks very unnatural in your implementation while it is ok on source, MadVR and VS's hable tonemap.

The screenshots are taken from frame #400 in the sample clip.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

Thank you. Investigating...
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

I hope everyone had a great Memorial Day.

The problem with douzi's stream is caused by my using a shortcut (for performance reasons) to avoid implementing the full EETF of ITU-R BT.2390. It works well for some streams but it's clear now that it does badly on some streams and I cannot avoid implementing the full EETF. It's going to take some time to implement.

As I mentioned, I'm learning a lot. ;)
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

Status update: Hmm, well, implementing the EETF didn't make much difference and didn't fix douzi's stream! Digging deeper I found that it is the 2020->709 gamut mapping that is responsible. That is surprising to me as it is just the inverse of BT.2087 and is recommended in several papers I read. I'm going to dig way deeper into this but for now I will probably give you a version tomorrow that at least fixes douzi's stream. I have it working but don't expect it to be the final solution.

Still learning. ;)
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

Here is an interim fix for douzi's stream. A new gamut mapping option was added called gm. Read the user manual for details. This may not be the final solution as I am still researching gamut mapping methods. gm is a hand-rolled method that seems to perform reasonably.

This version may be ~5-10% faster when using gm="compress".

http://rationalqm.us/misc/DGHDRtoSDR_1.3.rar

Here is douzi's frame 400 with gm="compress":

douzi.bmp
DAE avatar
Narkyy
Posts: 51
Joined: Thu May 25, 2017 11:51 pm

Re: HDR -> SDR tonemapping

Post by Narkyy »

I'm not sure if it's of any use (since there's not much documentation about the code), but there's this plugin which does conversion from BT2020 (and others) to BT709, as well as linear HDR -> SDR
https://github.com/jpsdr/HDRTools

I've been able to get good results (other than the linear lighting) with this script:
FFVideoSource("source.hevc", colorspace="YUV420P16")
ConvertYUVtoXYZ(Color=0,OutputMode=1, Gx=0.170,Gy=0.797,Bx=0.131,By=0.046,Rx=0.708,Ry=0.292,Wx=0.31271,Wy=0.32902) #BT2020 chromacity parameters
ConvertXYZ_HDRtoSDR(MinMastering=1, MaxMastering=1000,Coeff_X=20, Coeff_Y=20, Coeff_Z=20)
ConvertXYZtoYUV(Color=2, OutputMode=2, pColor=0)
z_ConvertFormat(pixel_type="YV12")
With example sample above: Image

Thanks for the update :hat:
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

You're welcome and thanks for pointing out HDRTools. I'll definitelt check it out. Looks like jpsdr has done some serious research on all this.

Don't forget that I'm going for speed and that way looks a bit sluggish.

BTW, don't you use DGSource()? If you have an nVidia card I'll give you a free license.
DAE avatar
Narkyy
Posts: 51
Joined: Thu May 25, 2017 11:51 pm

Re: HDR -> SDR tonemapping

Post by Narkyy »

Yes, it is slow. I'm just mentioning it because the conversions seem accurate.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

Yes, I'm interested to see what he is doing for gamut mapping. Going through XYZ space is interesting but can be slow.

I'm probably going to open source my plugin code too at some point.

Check the last line in my previous post.
DAE avatar
Narkyy
Posts: 51
Joined: Thu May 25, 2017 11:51 pm

Re: HDR -> SDR tonemapping

Post by Narkyy »

I have a license already, I just can't use it for HEVC ;)
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping

Post by admin »

Ah, wrong card!

Timings for prefetch=6 on my i7-7700K + 1080 Ti:

HDRTools: 15.25 fps
DGHDRtoSDR: 102.4 fps

Don't know if I have maxed out HDRTools because the multithreading instructions are a bit complicated and confusing (to me). I'm not sure I like the idea of internal multithreading in the filters.
Post Reply