HDR -> SDR conversion

These CUDA filters are packaged into DGDecodeNV, which is part of DGDecNV.
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

Shiny new toys, never a waste
Besides, if I leave it behind someone else will just waste it on different shiny new toys
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

Here's a release of the initial software version of the DGTonemap filter. The distribution includes a help file with full instructions and a sample script. Your testing and suggestions will be appreciated. This is the starting point for everything.

http://rationalqm.us/DGTonemap.rar

I thought the COPYING file from zimg was funny. ??? is a four-letter expletive beginning with the letter F. Here it is:

Code: Select all

            DO WHAT THE ??? YOU WANT TO PUBLIC LICENSE
                    Version 2, December 2004

 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

 Everyone is permitted to copy and distribute verbatim or modified
 copies of this license document, and changing it is allowed as long
 as the name is changed.

            DO WHAT THE ??? YOU WANT TO PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. You just DO WHAT THE ??? YOU WANT TO.
User avatar
hydra3333
Posts: 394
Joined: Wed Oct 06, 2010 3:34 am
Contact:

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by hydra3333 »

Thank you.
loadplugin("dgdecodenv.dll")
loadplugin("DGTonemap.dll")
loadplugin("avsresize.dll")
SetFilterMTMode("z_ConvertFormat", MT_MULTI_INSTANCE) # May not be needed.
dgsource("THE GREAT WALL.dgi",fulldepth=true)
z_ConvertFormat(pixel_type="RGBPS",colorspace_op="2020ncl:st2084:2020:l=>rgb:linear:2020:l", dither_type="none")
dgtonemap(white=0.7)
z_ConvertFormat(pixel_type="YV12",colorspace_op="rgb:linear:2020:l=>709:709:709:l",dither_type="ordered")
prefetch(2)
I know we ought not mention the vs word a lot ... but is there a vapoursynth equivalent script (eg I have never seen nor used "avsresize" before ... and I no longer have avisynth installed) ?
I really do like it here.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

I have no problem with the VS word or discussing it.

It's not simple because Avisynth doesn't know RGBS and Vapoursynth doesn't know RGBPS. I am working on making a dual Vapoursynth/Avisynth version of both DGDecodeNV and DGTonemap. May be a while.

The reason for this partial step was to get some kind of HDR->SDR for Avisynth.
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

I thought the COPYING file from zimg was funny. ??? is a four-letter expletive beginning with the letter F. Here it is:
"Fudge" is actually 5 letters

Speed
Prefetch(2) gives me really low speeds, maybe in neighborhood pf 17 FPS
Prefetch(8) gives me in the neighborhood of about 47 FPS
but this is a hardware specific item, user must find his own sweet spot
Note... Prefetch(12) is actually slightly faster but it appears to be hitting the point of diminishing returns, 1 FPS faster at a cost of 30% more CPU usage
I realize, unless I am wrong (known to happen quite a lot), that is an intermediate step until porting to CUDA

Now, the good stuff
The image is great, color appears to be spot on or very, very close.
It is a dash bright, but on this sample it actually looks better than the original sdr sample
When I get a chance I will run bigger samples so a more complete picture can be obeserved, if so desired

Looking awesome :bow: :bravo: :D

Before I forget
hdr to sdr
Image
sdr
Image
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

Thanks, gonca. Your fps values are what? Playing in VirtualDub2? I don't get how you can have 47fps when I get only 21fps.
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

Apoogies, that is encoding speed with NVEncC
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

Ah, OK. Thanks for the clarification. I will try with AVSMeter64 right now just for fun.

EDIT: AVSMeter64 30fps at prefetch(8). Can you try that?
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

The script with prefetch(8) plays in real-time (23.976) in MPC-HC x64 (delivering YV12). So I guess VirtualDub2 has lots of display overhead.
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

I get 54.33 FPS
Frames processed: 1449 (0 - 1448)
FPS (min | max | average): 14.12 | 198.0 | 54.33
Memory usage (phys | virt): 2365 | 3100 MiB
Thread count: 35
CPU usage (average): 50%

Time (elapsed): 00:00:26.671


[Script]
LoadPlugin("C:\Program Files (Portable)\dgdecnv\x64 Binaries\DGDecodeNV.dll")
LoadPlugin("C:\Program Files (Portable)\AVS Templates\DGTonemap\x64\DGTonemap.dll")
LoadPlugin("C:\Program Files (Portable)\AVS Templates\avsresize\x64\Release\avsresize.dll")
SetFilterMTMode("z_ConvertFormat", MT_MULTI_INSTANCE) # May not be needed.
DGSource("D:\#test\#hdr\THE GREAT WALL.dgi", fieldop=0, fulldepth=True)
z_ConvertFormat(pixel_type="RGBPS",colorspace_op="2020ncl:st2084:2020:l=>rgb:linear:2020:l", dither_type="none")
dgtonemap(white=0.7)
z_ConvertFormat(pixel_type="YV12",colorspace_op="rgb:linear:2020:l=>709:709:709:l",dither_type="ordered")
prefetch(8)
My point with NVEncC is that on the fly transcoding for streaming can be done
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

Regarding using longer samples
Do you want me to go ahead with it?
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

It's not really needed. Just spot checking of interesting scenes would be good.

But I want to know why you are getting 54 fps while I get only 30! What are your system details? What is your frame size?
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

i7-6900k
octocore at 3.2 GHz
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

octocore? 8 real cores or 8 logical cores? What OS?

What is the frame size? Please give the initial lines from AVSMeter64.
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

8 real cores
16 logical cores
entire log

Code: Select all

Log file created with:      AVSMeter 2.7.5 (x64)
Script file:                D:\#test\#hdr\THE GREAT WALL.avs
Log file directory:         C:\Users\LUIS\Desktop\AVSMeter275

[OS/Hardware info]
Operating system:           Windows 10 (x64) (Build 14393)
CPU brand string:           Intel(R) Core(TM) i7-6900K CPU @ 3.20GHz
CPU features:               MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX, AVX2, FMA3, MOVBE, POPCNT, AES, F16C


[Avisynth info]
VersionString:              AviSynth+ 0.1 (r2508, 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:    2017-06-29, 15:09:32 (UTC)
PluginDir2_5 (HKLM, x64):   C:\Program Files (x86)\AviSynth+\plugins64
PluginDir+   (HKLM, x64):   C:\Program Files (x86)\AviSynth+\plugins64+


[Clip info]
Number of frames:                 1449
Length (hh:mm:ss.ms):     00:01:00.435
Frame width:                      3840
Frame height:                     2160
Framerate:                      23.976 (24000/1001)
Colorspace:                       YV12
Audio channels:                    n/a
Audio bits/sample:                 n/a
Audio sample rate:                 n/a
Audio samples:                     n/a


[Runtime info]
Frames processed:               1449 (0 - 1448)
FPS (min | max | average):      14.12 | 198.0 | 54.33
Memory usage (phys | virt):     2365 | 3100 MiB
Thread count:                   35
CPU usage (average):            50%

Time (elapsed):                 00:00:26.671


[Script]
LoadPlugin("C:\Program Files (Portable)\dgdecnv\x64 Binaries\DGDecodeNV.dll")
LoadPlugin("C:\Program Files (Portable)\AVS Templates\DGTonemap\x64\DGTonemap.dll")
LoadPlugin("C:\Program Files (Portable)\AVS Templates\avsresize\x64\Release\avsresize.dll")
SetFilterMTMode("z_ConvertFormat", MT_MULTI_INSTANCE) # May not be needed.
DGSource("D:\#test\#hdr\THE GREAT WALL.dgi", fieldop=0, fulldepth=True)
z_ConvertFormat(pixel_type="RGBPS",colorspace_op="2020ncl:st2084:2020:l=>rgb:linear:2020:l", dither_type="none")
dgtonemap(white=0.7)
z_ConvertFormat(pixel_type="YV12",colorspace_op="rgb:linear:2020:l=>709:709:709:l",dither_type="ordered")
prefetch(8)


[Performance data]
       Frame    Frames/sec   Time/frame(ms)   CPU(%)   Threads  PhysMEM(MiB)  VirtMEM(MiB)
          10        14.120        70.820129       33        35          1823          2661
          20        71.081        14.068407       48        35          1890          2708
          30        53.347        18.745030       51        35          1890          2708
          40        58.178        17.188642       51        35          1890          2708
          50        45.712        21.876308       50        35          1997          2827
          60        72.145        13.860956       47        35          2009          2827
          70        54.664        18.293668       50        35          2009          2827
          80        51.518        19.410697       49        35          2032          2851
          90        58.174        17.189794       51        35          2032          2851
         100        51.543        19.401445       51        35          2079          2922
         110        60.476        16.535589       50        35          2127          2922
         120        52.790        18.943104       51        35          2139          2934
         130        70.402        14.204126       51        35          2163          2958
         140        54.520        18.342002       48        35          2163          2958
         150        48.750        20.512617       50        35          2163          2898
         160        49.240        20.308621       51        35          2163          2898
         170        42.883        23.319416       51        35          2163          2898
         180        71.111        14.062614       54        35          2163          2898
         190        53.331        18.750729       48        35          2163          2898
         200        60.110        16.636162       52        35          2163          2898
         210        56.370        17.740003       50        35          2163          2898
         220        53.331        18.750824       51        35          2163          2898
         230        70.435        14.197437       52        35          2163          2898
         240        52.976        18.876492       50        35          2163          2898
         250        60.854        16.432679       52        35          2163          2898
         260        41.781        23.934089       50        35          2163          2898
         270        86.001        11.627795       52        35          2163          2898
         280        43.958        22.748978       51        35          2163          2898
         290        53.331        18.750697       51        35          2163          2898
         300        60.677        16.480597       51        35          2163          2898
         310        57.002        17.543146       51        35          2163          2898
         320        48.388        20.666261       52        35          2163          2898
         330        74.025        13.508981       51        35          2163          2898
         340        44.582        22.430709       49        35          2163          2898
         350        53.328        18.751784       50        35          2163          2898
         360        71.853        13.917292       50        35          2163          2898
         370        52.269        19.131959       51        35          2163          2898
         380        46.213        21.638927       50        35          2163          2898
         390        75.131        13.310075       49        35          2163          2898
         400        51.144        19.552721       52        35          2163          2898
         410        42.754        23.389484       48        35          2163          2898
         420        63.989        15.627805       53        35          2163          2898
         430        76.218        13.120228       48        35          2163          2898
         440        49.793        20.083211       50        35          2163          2898
         450        46.542        21.485859       49        35          2163          2898
         460        73.378        13.628087       49        35          2163          2898
         470        61.302        16.312579       52        35          2163          2898
         480        38.009        26.309628       49        35          2163          2898
         490        53.330        18.751177       52        35          2163          2898
         500        69.224        14.445894       47        35          2163          2898
         510        34.876        28.672684       51        35          2166          2921
         520        99.919        10.008156       53        35          2187          2921
         530        55.855        17.903538       50        35          2187          2921
         540        35.156        28.444552       50        35          2187          2921
         550       100.949         9.905983       52        35          2199          2933
         560        51.915        19.262077       48        35          2199          2933
         570        35.502        28.167289       50        35          2199          2933
         580        71.966        13.895494       50        35          2199          2933
         590        67.806        14.748029       50        35          2199          2933
         600        69.079        14.476238       52        35          2199          2933
         610        53.102        18.831583       49        35          2199          2933
         620        74.804        13.368332       50        35          2199          2933
         630        54.849        18.231921       50        35          2199          2933
         640        54.140        18.470582       51        35          2199          2933
         650        56.928        17.566000       50        35          2199          2933
         660        54.056        18.499167       52        35          2199          2933
         670        53.899        18.553327       50        35          2199          2933
         680        53.893        18.555344       50        35          2199          2933
         690        42.312        23.634036       50        35          2199          2933
         700        52.781        18.946337       52        35          2199          2933
         710        97.731        10.232189       50        35          2199          2933
         720        34.503        28.982918       50        35          2199          2933
         730        70.543        14.175766       50        35          2199          2933
         740        71.259        14.033390       50        35          2199          2933
         750        35.391        28.256083       51        35          2202          2945
         760        71.060        14.072568       48        35          2211          2945
         770       197.977         5.051100       50        35          2211          2945
         780        39.013        25.632536       50        35          2211          2945
         790        57.415        17.417060       54        35          2211          2945
         800        82.951        12.055279       47        35          2211          2945
         810        34.148        29.284093       50        35          2211          2945
         820        68.254        14.651073       48        35          2211          2945
         830        75.843        13.185047       53        35          2211          2945
         840        47.773        20.932386       49        35          2211          2945
         850        69.338        14.422015       52        35          2211          2945
         860        53.588        18.660942       48        35          2211          2945
         870        53.853        18.569203       51        35          2211          2945
         880        61.368        16.295198       51        35          2211          2945
         890        46.702        21.412557       49        35          2211          2945
         900        68.201        14.662436       50        35          2211          2945
         910        50.781        19.692473       51        35          2211          2945
         920        58.619        17.059356       52        35          2211          2945
         930        59.689        16.753508       51        35          2211          2945
         940        56.011        17.853508       51        35          2211          2945
         950        53.598        18.657453       51        35          2211          2945
         960        51.488        19.421931       48        35          2211          2945
         970        38.784        25.783780       51        35          2211          2945
         980       136.989         7.299849       47        35          2211          2945
         990        34.773        28.758340       49        35          2211          2945
        1000        91.411        10.939595       50        35          2211          2945
        1010        49.233        20.311758       49        35          2211          2945
        1020        60.010        16.663881       52        35          2211          2945
        1030        69.848        14.316737       51        35          2211          2945
        1040        35.064        28.519550       50        35          2211          2945
        1050        71.177        14.049395       50        35          2211          2945
        1060        71.663        13.954230       45        35          2211          2945
        1070        34.451        29.026643       51        35          2211          2945
        1080        69.282        14.433665       48        35          2211          2945
        1090        89.045        11.230303       49        35          2211          2945
        1100        59.207        16.889900       50        35          2211          2945
        1110        63.188        15.825782       51        35          2211          2945
        1120        48.098        20.791065       50        35          2211          2945
        1130        53.818        18.581303       52        35          2211          2945
        1140        64.346        15.540932       50        35          2211          2945
        1150        57.840        17.289184       47        35          2211          2945
        1160        34.446        29.030835       51        35          2211          2945
        1170        66.506        15.036145       51        35          2211          2945
        1180        87.111        11.479591       48        35          2211          2945
        1190        59.125        16.913363       51        35          2211          2945
        1200        33.970        29.437355       49        35          2211          2945
        1210       115.074         8.690077       49        35          2211          2945
        1220        34.536        28.955166       50        35          2211          2945
        1230        69.726        14.341799       51        35          2211          2945
        1240        69.735        14.340070       51        35          2211          2945
        1250        70.146        14.255918       51        35          2211          2945
        1260        34.354        29.108779       49        35          2211          2945
        1270        68.969        14.499189       54        35          2211          2945
        1280        69.832        14.320096       51        35          2211          2945
        1290        69.430        14.402906       49        35          2211          2945
        1300        34.810        28.727001       48        35          2211          2945
        1310       100.016         9.998394       54        35          2211          2945
        1320        62.252        16.063708       48        35          2211          2945
        1330        58.047        17.227566       49        35          2211          2945
        1340        35.385        28.260402       48        35          2285          3040
        1350       169.745         5.891184       51        35          2306          3040
        1360        38.008        26.310108       50        35          2306          3040
        1370        64.188        15.579311       47        35          2306          3040
        1380        67.413        14.834006       51        35          2306          3040
        1390        34.413        29.058620       50        35          2306          3040
        1400        63.104        15.846876       48        35          2306          3040
        1410        72.740        13.747610       50        35          2306          3040
        1420        70.397        14.205152       51        35          2306          3040
        1430        35.413        28.237900       50        35          2306          3040
        1440        72.570        13.779780       48        35          2317          3052
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

Ah, 8 real cores. I hate you.

My processor is a 7700K @4.2GHz with 64GB RAM, 8M cache. 4 real cores.

D:\Don\Programming\C++\Avisynth filters\DGTonemap\Test>avsmeter64 "the great wall.avs"

AVSMeter 2.7.5 (x64) - Copyright (c) 2012-2017, Groucho2004
AviSynth+ 0.1 (r2508, MT, x86_64) (0.1.0.0)

Number of frames: 1771
Length (hh:mm:ss.ms): 00:01:13.865
Frame width: 3840
Frame height: 2160
Framerate: 23.976 (24000/1001)
Colorspace: YV12

Frames processed: 1771 (0 - 1770)
FPS (min | max | average): 2.213 | 80423 | 29.97
Memory usage (phys | virt): 2151 | 2988 MiB
Thread count: 24
CPU usage (average): 67%

Time (elapsed): 00:00:59.096

D:\Don\Programming\C++\Avisynth filters\DGTonemap\Test>avsmeter64 -avsinfo

AVSMeter 2.7.5 (x64) - Copyright (c) 2012-2017, Groucho2004

VersionString: AviSynth+ 0.1 (r2508, 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: 2017-06-29, 09:09:33 (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 [2017-06-03]
C:\Program Files (x86)\AviSynth+\plugins64+\DirectShowSource.dll [2017-05-28]
C:\Program Files (x86)\AviSynth+\plugins64+\ImageSeq.dll [2017-06-03]
C:\Program Files (x86)\AviSynth+\plugins64+\Shibatch.dll [2017-06-03]
C:\Program Files (x86)\AviSynth+\plugins64+\TimeStretch.dll [2017-06-03]
C:\Program Files (x86)\AviSynth+\plugins64+\VDubFilter.dll [2017-06-03]
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

If I may point out
50% usage on my cpu is about the same as 100% on a quadcore
The difference might be in avs+ or the filters ability (or lack thereof) to max out the cpu
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

Well, as I edited, I just realized you have 8 real cores versus my 4. And your cache is 20 versus my 8. So no mystery.

Damn I didn't even know that such a processor existed. :roll:

Time for a CPU upgrade.
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

Damn I didn't even know that such a processor existed
Considering what it cost, I sometimes wish that too, especially now that I am using the video card more and more in my workflow

Looks that prefetch(8) is as good as it gets in speed, tested all the way to 16
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

At least I can run the script in real-time in MPC-HC with my crappy processor.
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

The 7700k is actually a good processor, which can beat mine in single threaded applications
Besides, if you port the script to CUDA then its the video card determining the speed
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

:cry: wah wah wah :cry:
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

Is VDub2 a single threaded application?
That would explain the low numbers
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

Could be. I don't care. It's not intended as a player application. I only used it for benchmarking because I didn't know how to run AVSMeter in Vapoursynth (hint, you can't), and I had never heard of VSEditor or vspipe.

So I found the sweet spot at prefetch(4) for my system -> 32fps.

But just changing it to 2 or 8 drops it by 10 and 5 fps, respectively. That is crazy that you have to tweak it manually. C'est la vie.
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

I did some more testing on the DGTonemapping filter using the same movie, in full, that has been used so far.
Observations
Color hdr to sdr vs sdr
Color is very, very close or spot on
Brightness
DGTonemapping is a small little bit brighter but, to my eyes, it looks better than the original sdr version

Random spots were looked at, bright dark and "colorful" areas were looked at
Post Reply