HDR -> SDR conversion

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

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

One other item
The color characteristics (BT2020nc etc) aren't added in, so they must be added in at the container level
My final format is MKV so I use MKVToolNix to add these in when I mux the patched HEVC stream with the audio, etc (no chapters :roll: )
User avatar
hydra3333
Posts: 394
Joined: Wed Oct 06, 2010 3:34 am
Contact:

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by hydra3333 »

would you be able to share an example commandline ?
I really do like it here.
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

hydra3333 wrote:
Sat Jan 27, 2018 8:27 pm
would you be able to share an example commandline ?
If you mean for MKVToolnix I simply add
--colour-matrix 0:9 --colour-transfer-characteristics 0:16 --colour-primaries 0:9
in the GUI in the input pane.
Note that the number 0 refers to the track id for the video

Edit
Tested it and the TV switches to HDR mode automatically
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
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 »

So, I've been doing some research and it's clear that there are a boatload of different tone-mapping algorithms that we could choose to implement with CUDA. I'm looking at Hable but also a method based on adaptive histogram equalization. The latter would be reminiscent of my VirtualDub windowed histogram equalization filter.

http://rationalqm.us/winhistogram.html

An interesting technical reference in this regard is:

http://citeseerx.ist.psu.edu/viewdoc/do ... 1&type=pdf

I may try to implement something like that. I think a spatially variable method would intuitively give better results, and a CUDA implementation could make it practical.

@gonca

How is the new TV working out and do you have some interesting HDR streams to share with us? Have you experimented with any HDR->SDR stuff?
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

The new set is working great, the hdr color is the best part.
Got the re encode somewhat figured out, the TV automatically switches to HDR mode automatically.
Note
When using MKVToolNix to mux raw streams, FPS must be specified or it uses 25FPS as default
I almost deleted a bunch of stuff because of synch issues, but I remember to check FPS in time.

I am using my movies as sources, and the set usually brings a 4K and BD discs, so HDR > SDR hasn't been an issue
However this does present a testing opportunity in the comparison stage
Tidbit
4K discs are for vast majority movie only, and they tend to 55GB to 90GB in size
I have seen bitrates, on the video, as high as 90+Mbps
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

Thanks for the info, gonca.

What set did you get?
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

Vizio M65 E0
https://www.amazon.com/VIZIO-M65-E0-Sma ... zio+m65-e0

Extra bit of info
With my single video card I am averaging 80 to 90 FPS on NVEnc encodes
The card is doing double duty, frame serving with DGDecodeNV and encoding with NVEnc
On a double GPU system the speeds could double?
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

Thanks. I cannot guess about the answer to your question, because it all depends on how the encoder uses the VP engine versus CUDA, and I don't know anything about that.
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

Quick test encode just to answer my own question
Seems that NVEnc is using 50% to 51% of the VPU
Hardware Monitor says that my VPU is under 97% + load
DGDecodeNV and NVEnc are sharing the VPU fairly equally
Two GPU cards should double the speed, more or less.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

Sounds reasonable.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

Hey gonca, if I read you correctly you are converting your UHD disks to MKV. How are you ripping these disks?
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

Three decryption tools work
MakeMKV > with hashed key file from MakeMKV website
AnyDVDHD > as is
DeUHD > as is

Note
Check the recommended drives, that is important
User avatar
hydra3333
Posts: 394
Joined: Wed Oct 06, 2010 3:34 am
Contact:

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by hydra3333 »

OK, mkv ...

Hmm, for a HDR file playback (vs playback of an SDR file via an older media player, since we are also talking about hdr->sdr) things like "Chromecast Ultra" seem to be becoming ubiquitous, where one can cast files to it from a local media server or from internet sources.

The Chomecast Ultra documentation is ambiguous, it seems to only accept cast files in webm or mp4 media containers per https://developers.google.com/cast/docs/media and it does not mention which container hevc goes into, eg

Code: Select all

Video codecs (Chromecast Ultra)
HEVC / H.265 Main and Main10 Profiles up to level 5.1 (2160p/60fps)
VP9 Profile 0 and Profile 2 up to level 5.1 (2160p/60fps)

Code: Select all

WebM video and audio
Format	Video codec	Audio codec	Media type string
WebM	VP8	Vorbis	video/webm; codecs="vp8, vorbis"
WebM (audio only)	Vorbis	audio/webm; codecs="vorbis"
Without any good reason, I suspect webm is the container to use. I guess that means ffmpeg/VS-with-DG or Nvencc/VS-with-DG to encode to h.265 (did I read somewhere DG liaising with Nvencc's author ?) and then something (ffmpeg?) to mux to webm.

Anyway, for hdr -> sdr/1080i, for me it'd seem to be
(i) ffmpeg/vs-with-DG->mp4mux most likely, or
(ii) Nvencc/vs-with-DG->mp4mux, to a .mp4
... unless you have other thoughts :)
I really do like it here.
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

All I can say is start with a small clip and see which way works best for your needs
DAE avatar
jpsdr
Posts: 214
Joined: Tue Sep 21, 2010 4:16 am

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by jpsdr »

I've asked this question on a well know forum, but i thought i may ask also here :

From what i've understood, UHD BR can be HDR, but it's not mandatory. 4k/UHD doesn't always mean content is HDR, these are two different things.
So my question is (even if UHD BR not HDR may be very unlikey), i bought an UHD BR, i manage to rip it, is there a way i can chek it the content is SDR or HDR ?
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

With Mediainfo.
Look for something like this
Color primaries : BT.2020
Transfer characteristics : PQ
Matrix coefficients : BT.2020 non-constant
Mastering display color primaries : R: x=0.680000 y=0.320000, G: x=0.265000 y=0.690000, B: x=0.150000 y=0.060000, White point: x=0.312700 y=0.329000
Mastering display luminance : min: 0.0000 cd/m2, max: 1000.0000 cd/m2
Or
if you have a hdr capable tv and player try it
4k/UHD doesn't always mean content is HDR, these are two different things.
You can resize UHD with HDR to 1080p with HDR, so yes, UHD and HDR aren't bound to each other
User avatar
hydra3333
Posts: 394
Joined: Wed Oct 06, 2010 3:34 am
Contact:

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by hydra3333 »

Also you may be aware that sometimes manufacturers use HDR as a marketing word.

I tested a samsung S8+ mobile phone video recording which has a "HDR" mode ... which doesn't mean it creates 10bit HDR10 or anything like that ... it always produces 8bit h.264 ... always ... apparently "it has HDR" in that marketing context may mean something like the device enhances colours within the 8bit range somehow.

There's a pdf linked in this post viewtopic.php?f=8&t=522&p=7643#p7643 if you're interested. They also produce .mp4 files with variable framerate h.264 ... which almost no editing software seems to handle properly. :facepalm: I'm nearly sorry I bought the S8 now, as HDR and videos were a factor in the buying decision and the internet had almost zero to say about these things :shock:
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 »

Maybe your files are "VFR in name only". Let's see a sample.
User avatar
hydra3333
Posts: 394
Joined: Wed Oct 06, 2010 3:34 am
Contact:

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by hydra3333 »

Sure, a few smallish samples to download from here https://drive.google.com/open?id=1CHdnC ... p6WWnZdynN

Don't mind the mess, it's a warm week in Aus at the moment and who wants to tidy up when there's video and a new phone to play with. Clip 01 seems to have a issues playing on a chromecast ultra, not sure why.

I know VFR is a bit off-track and not about HDR-SDR tone mapping (since the Samsung S8 phones don't "really" create 10-bit HDR).
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 »

Thanks, will check them out today.
DAE avatar
Guest

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by Guest »

hydra3333
Until they are checked by a more knowledgeable person, try De-interlacing and check for repeat frames
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

For the UHD HDR file, the timecodes show that the frame rate varies only insignificantly around 29.97. That is, "VFR in name only".

Most likely you can treat it as CFR, i.e., just demux audio and video and remux them as CFR. Or process with Avisynth/Vapoursynth as if it is CFR. Test it on a longer stream watching audio sync throughout.

I seriously doubt a phone would create true VFR. VFR is used to combine segments with different frame rates, like film (23.976) and video (29.97), i.e., for hybrid video. This video is obviously not hybrid.

Here are the timecodes with the differences to the previous ones in [ ]. Apart from the very first, the codes vary only a little around 29.97 fps. FPS 29.97 would give a difference of ~33.4.

0 [0]
44.4 [44.4]
77.7222222222222 [33.7222222222222]
111.033333333333 [34.0333333333333]
144.322222222222 [33.3222222222222]
177.611111111111 [33.6111111111111]
210.922222222222 [33.9222222222222]
244.2 [34.2]
277.5 [33.5]
310.811111111111 [33.8111111111111]
344.111111111111 [34.1111111111111]
377.422222222222 [33.4222222222222]
410.722222222222 [33.7222222222222]
444.044444444444 [34.0444444444445]
477.344444444444 [33.3444444444444]
510.644444444444 [33.6444444444444]
543.955555555556 [33.9555555555555]
577.266666666667 [34.2666666666667]
610.566666666667 [33.5666666666667]
643.877777777778 [33.8777777777777]
677.177777777778 [34.1777777777778]
710.488888888889 [33.4888888888888]
743.8 [33.8000000000001]
777.1 [34.1]
810.422222222222 [33.4222222222222]
843.711111111111 [33.7111111111111]
877.022222222222 [34.0222222222222]
910.311111111111 [33.311111111111]
943.611111111111 [33.6111111111111]
976.922222222222 [33.9222222222222]
1010.23333333333 [34.2333333333333]
1043.54444444444 [33.5444444444445]
1076.85555555556 [33.8555555555554]
1110.15555555556 [34.1555555555556]
1143.46666666667 [33.4666666666667]
1176.77777777778 [33.7777777777776]
1210.07777777778 [34.0777777777778]
1243.37777777778 [33.3777777777777]
1276.68888888889 [33.6888888888891]
1310.02222222222 [34.0222222222221]
1343.31111111111 [33.3111111111111]
1376.63333333333 [33.6333333333334]
1409.92222222222 [33.9222222222222]
1443.22222222222 [34.2222222222222]
1476.53333333333 [33.5333333333333]
1509.84444444444 [33.8444444444444]
1543.14444444444 [34.1444444444444]
1576.44444444444 [33.4444444444446]
1609.75555555556 [33.7555555555557]
1643.06666666667 [34.0666666666666]
1676.37777777778 [33.3777777777777]
1709.68888888889 [33.6888888888889]
1743 [34]
1776.28888888889 [33.2888888888888]
1809.6 [33.6000000000001]
1842.91111111111 [33.9111111111113]
1876.21111111111 [34.211111111111]
1909.52222222222 [33.5222222222221]
1942.83333333333 [33.8333333333335]
1976.12222222222 [34.122222222222]
2009.43333333333 [33.4333333333334]
2042.75555555556 [33.7555555555555]
2076.06666666667 [34.0666666666666]
2109.35555555556 [33.3555555555558]
2142.66666666667 [33.6666666666665]
2175.96666666667 [33.9666666666667]
2209.27777777778 [34.2777777777778]
2242.58888888889 [33.588888888889]
2275.87777777778 [33.8777777777777]
2309.2 [34.2000000000003]
2342.5 [33.5]
2375.81111111111 [33.8111111111111]
2409.12222222222 [34.1222222222223]
2442.43333333333 [33.4333333333334]
2475.73333333333 [33.7333333333331]
2509.04444444444 [34.0444444444447]
2542.33333333333 [33.333333333333]
2575.66666666667 [33.666666666667]
2608.96666666667 [33.9666666666667]
2642.25555555556 [34.2555555555555]
2675.55555555556 [33.5555555555557]
2708.88888888889 [33.8888888888887]
2742.17777777778 [34.1777777777775]
2775.47777777778 [33.4777777777776]
2808.8 [33.8000000000002]
2842.08888888889 [34.088888888889]
2875.4 [33.4000000000001]
2908.72222222222 [33.7222222222226]
2942.02222222222 [34.0222222222219]
2975.33333333333 [33.3333333333335]
3008.62222222222 [33.6222222222223]
3041.94444444444 [33.9444444444443]
3075.23333333333 [34.2333333333331]
3108.55555555556 [33.5555555555557]
3141.85555555556 [33.8555555555554]
3175.15555555556 [34.1555555555556]
3208.47777777778 [33.4777777777781]
3241.78888888889 [33.7888888888888]
3275.07777777778 [34.0777777777776]
3308.37777777778 [33.3777777777777]
3341.73333333333 [33.7333333333336]
3375.06666666667 [34.0666666666666]
3408.3 [33.3000000000002]
3441.64444444444 [33.6444444444446]
3474.93333333333 [33.9333333333334]
3508.24444444444 [34.2444444444441]
3541.53333333333 [33.5333333333333]
3574.84444444444 [33.8444444444444]
3608.15555555556 [34.1555555555551]
3641.44444444444 [33.4444444444443]
3674.75555555556 [33.7555555555555]
3708.06666666667 [34.0666666666671]
3741.36666666667 [33.3666666666663]
3774.67777777778 [33.6777777777779]
3807.98888888889 [33.9888888888891]
3841.3 [34.2999999999997]
3874.58888888889 [33.588888888889]
3907.9 [33.9000000000001]
3941.21111111111 [34.2111111111112]
3974.53333333333 [33.5333333333333]
4007.83333333333 [33.833333333333]
4041.15555555556 [34.1555555555551]
4074.43333333333 [33.4333333333334]
4107.74444444444 [33.7444444444445]
4141.05555555556 [34.0555555555557]
4174.36666666667 [33.3666666666668]
4207.65555555556 [33.6555555555551]
4240.97777777778 [33.9777777777781]
4274.27777777778 [34.2777777777783]
4307.58888888889 [33.5888888888885]
4340.88888888889 [33.8888888888896]
4374.22222222222 [34.2222222222226]
4407.53333333333 [33.5333333333328]
4440.83333333333 [33.833333333333]
4474.14444444445 [34.1444444444451]
4507.44444444444 [33.4444444444443]
4540.76666666667 [33.7666666666664]
4574.07777777778 [34.0777777777785]
4607.37777777778 [33.3777777777777]
4640.67777777778 [33.677777777777]
4673.98888888889 [33.9888888888891]
4707.28888888889 [34.2888888888892]
4740.6 [33.5999999999995]
4773.9 [33.9000000000005]
4807.21111111111 [34.2111111111108]
4840.51111111111 [33.5111111111109]
4873.83333333333 [33.8333333333339]
4907.12222222222 [34.1222222222223]
4940.43333333333 [33.4333333333334]
4973.75555555556 [33.7555555555555]
5007.05555555556 [34.0555555555557]
5040.35555555555 [33.3555555555549]
5073.66666666667 [33.666666666667]
5107.02222222222 [34.0222222222228]
5140.26666666667 [33.2666666666664]
5173.57777777778 [33.5777777777785]
5206.92222222222 [33.9222222222224]
5240.18888888889 [34.1888888888889]
5273.5 [33.5]
5306.81111111111 [33.8111111111111]
5340.11111111111 [34.1111111111104]
5373.42222222222 [33.4222222222224]
5406.73333333333 [33.7333333333336]
5440.03333333333 [34.0333333333328]
5473.34444444444 [33.3444444444449]
5506.66666666667 [33.666666666667]
5539.94444444444 [33.9444444444443]
5573.25555555556 [34.2555555555555]
5606.58888888889 [33.5888888888894]
5639.86666666667 [33.8666666666668]
5673.17777777778 [34.1777777777779]
5706.54444444444 [33.5444444444447]
5739.78888888889 [33.7888888888883]
5773.11111111111 [34.1111111111113]
5806.41111111111 [33.4111111111115]
5839.72222222222 [33.7222222222217]
5873.02222222222 [34.0222222222228]
5906.34444444444 [33.3444444444449]
5939.63333333333 [33.6333333333332]
5972.93333333333 [33.9333333333334]
6006.23333333333 [34.2333333333336]
6039.56666666667 [33.5666666666666]
6072.85555555556 [33.8555555555558]
6106.17777777778 [34.1777777777779]
6139.46666666667 [33.4666666666662]
6172.78888888889 [33.7888888888892]
6206.08888888889 [34.0888888888894]
6239.43333333333 [33.4333333333334]
6272.72222222222 [33.7222222222217]
6306.02222222222 [34.0222222222228]
6339.31111111111 [33.3111111111111]
6372.61111111111 [33.6111111111113]
6405.93333333333 [33.9333333333334]
6439.23333333333 [34.2333333333336]
6472.53333333333 [33.5333333333338]
6505.85555555556 [33.8555555555558]
6539.14444444444 [34.1444444444442]
6572.45555555556 [33.4555555555562]
6605.76666666667 [33.7666666666664]
6639.06666666667 [34.0666666666666]
6672.37777777778 [33.3777777777777]
6705.7 [33.6999999999998]
6739.01111111111 [34.0111111111109]
6772.28888888889 [33.2888888888892]
6805.61111111111 [33.6111111111113]
6838.92222222222 [33.9222222222224]
User avatar
hydra3333
Posts: 394
Joined: Wed Oct 06, 2010 3:34 am
Contact:

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by hydra3333 »

OK, thanks, I'll try that.

I uploaded another clip "05" where the minimum VFR frame rate is reportedly down to 16.
Would that "assume CFR" approach still be doable with clips like that ?

Code: Select all

Bit rate                                 : 17007029
Bit rate                                 : 17.0 Mb/s
Width                                    : 1920
Width                                    : 1 920 pixels
Height                                   : 1080
Height                                   : 1 080 pixels
Stored_Height                            : 1088
Sampled_Width                            : 1920
Sampled_Height                           : 1080
Pixel aspect ratio                       : 1.000
Display aspect ratio                     : 1.778
Display aspect ratio                     : 16:9
Rotation                                 : 90.000
Rotation                                 : 90°
Frame rate mode                          : VFR
Frame rate mode                          : Variable
Frame rate                               : 30.000
Frame rate                               : 30.000 FPS
Minimum frame rate                       : 16.876
Minimum frame rate                       : 16.876 FPS
Maximum frame rate                       : 30.141
Maximum frame rate                       : 30.141 FPS
Frame count                              : 1118
Source frame count                       : 1119
I suppose ffmpeg -vsync 2 or even better -vsync drop would be OK using to convert to CFR.
-vsync parameter
Video sync method. For compatibility reasons old values can be specified as numbers. Newly added values will have to be specified as strings always.
0, passthrough
Each frame is passed with its timestamp from the demuxer to the muxer.
1, cfr
Frames will be duplicated and dropped to achieve exactly the requested constant frame rate.
2, vfr
Frames are passed through with their timestamp or dropped so as to prevent 2 frames from having the same timestamp.
drop
As passthrough but destroys all timestamps, making the muxer generate fresh timestamps based on frame-rate.
-1, auto
Chooses between 1 and 2 depending on muxer capabilities. This is the default method.
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 »

hydra3333 wrote:
Thu Mar 08, 2018 7:17 pm
I uploaded another clip "05" where the minimum VFR frame rate is reportedly down to 16.
I don't see this at the link you gave earlier.
Post Reply