HDR -> SDR conversion

These CUDA filters are packaged into DGDecodeNV, which is part of DGDecNV.
Post Reply
User avatar
gonca
Curly Approved/Moose Approved
Posts: 970
Joined: Sun Apr 08, 2012 6:12 pm

HDR -> SDR conversion

Post by gonca »

I'll be setting up my new 4K system this weekend.
If it is of any help I can run test scripts right afterward and report back
Or if I can of some help beforehand please let me know
User avatar
admin
Site Admin
Posts: 4450
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

All help will be welcome. Thanks!

What do you mean by a "4K system"?
User avatar
gonca
Curly Approved/Moose Approved
Posts: 970
Joined: Sun Apr 08, 2012 6:12 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by gonca »

GTX 1080Ti hooked up to a receiver which goes to a 65" 4K TV
All HDR10 and Dolby Vision capable
User avatar
admin
Site Admin
Posts: 4450
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

:bow:
User avatar
gonca
Curly Approved/Moose Approved
Posts: 970
Joined: Sun Apr 08, 2012 6:12 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by gonca »

Hopefully I'll be able to do a comparison of HDR to HDR>SDR to a native SDR clip
P.S.
Santa was good to me... until he stuck me with the bill for this stuff
User avatar
hydra3333
Moose Approved
Posts: 231
Joined: Wed Oct 06, 2010 3:34 am
Contact:

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by hydra3333 »

my goodness gonca, envious of the equipment if not the bill.

A query ...

I have (a) an old PC with a 750Ti nvidia card and another with a low-cost 1050Ti (b) a low cost samsung telly which claims to do 4k and hdr ... but no media player which does 4k or hdr.
I do have a chromecast ultra attached to that telly though.
In your view, would this be reasonable to test and compare with ?
1. for HDR
save native HDR file -> on a chromecast server filesystem (on a raspberry pi3) -> use a tablet to cast the HDR file from the Pi3 to the chromecast ultra
2. for SDR:
convert HDR file -> h.264.avc.SDR.mp4 using NVENC to a chromecast server filesystem (on a raspberry pi3) -> use a tablet to cast the SDR file from the Pi3 to the chromecast ultra

PS IIRC the 750Ti won't encode h.265 nor HDR using NVENC in ffmpeg, but does a 1050Ti do either/both ?
User avatar
gonca
Curly Approved/Moose Approved
Posts: 970
Joined: Sun Apr 08, 2012 6:12 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by gonca »

You need to make all your devices are HDMI 2.0 capable.
Make your HDMI cables are rated, Amazon basics cables are good enough (18Gbps)
The 1050Ti can decode and encode HEVC, don't think the 750 can do hardware decoding of HEVC
CPU decoding of 4K HEVC would be a massive load
If everything is decrypted HDCP is not an issue

1050Ti > TV (4K+HDR) with proper cables sounds good enough
NVEnc does not retain the HDR metadata, (it does use the parameters) meaning you have to turn on HDR manually on the TV
or
Use nvhsp to apply the metadata back into the HEVC stream
Its quite easy to use
User avatar
admin
Site Admin
Posts: 4450
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

Link for nvhsp?
User avatar
gonca
Curly Approved/Moose Approved
Posts: 970
Joined: Sun Apr 08, 2012 6:12 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by gonca »

https://github.com/SK-Hardwired/nv_hevc ... /nvhsp.zip

my template command line
"C:\Program Files (Portable)\HDRpatcher\nvhsp.exe" -full_range tv -colorprim bt2020 -colormatrix bt2020nc -transfer smpte-st-2084 -chromaloc 2 -maxcll 1000,300 -masterdisplay "G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,0)" "T:\IMPORTS\.hevc" "I:\.hevc"
This is good for P65? I believe, change maxcll and L values as required
MediaInfo 17.10 still gives the actual numbers
G, B, R, and WP are the numbers reported by MediaInfo x 50000

Edit
P65 should actually read DCI-P3 D65
User avatar
admin
Site Admin
Posts: 4450
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

Thanks!
User avatar
gonca
Curly Approved/Moose Approved
Posts: 970
Joined: Sun Apr 08, 2012 6:12 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by gonca »

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
Moose Approved
Posts: 231
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 ?
User avatar
gonca
Curly Approved/Moose Approved
Posts: 970
Joined: Sun Apr 08, 2012 6:12 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by gonca »

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
Moose Approved
Posts: 231
Joined: Wed Oct 06, 2010 3:34 am
Contact:

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by hydra3333 »

thank you
User avatar
admin
Site Admin
Posts: 4450
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?
User avatar
gonca
Curly Approved/Moose Approved
Posts: 970
Joined: Sun Apr 08, 2012 6:12 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by gonca »

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
Site Admin
Posts: 4450
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?
User avatar
gonca
Curly Approved/Moose Approved
Posts: 970
Joined: Sun Apr 08, 2012 6:12 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by gonca »

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
Site Admin
Posts: 4450
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.
User avatar
gonca
Curly Approved/Moose Approved
Posts: 970
Joined: Sun Apr 08, 2012 6:12 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by gonca »

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
Site Admin
Posts: 4450
Joined: Thu Sep 09, 2010 3:08 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by admin »

Sounds reasonable.
User avatar
admin
Site Admin
Posts: 4450
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?
User avatar
gonca
Curly Approved/Moose Approved
Posts: 970
Joined: Sun Apr 08, 2012 6:12 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by gonca »

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
Moose Approved
Posts: 231
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 :)
User avatar
gonca
Curly Approved/Moose Approved
Posts: 970
Joined: Sun Apr 08, 2012 6:12 pm

Re: HDR -> SDR tonemapping for DGDecodeNV

Post by gonca »

All I can say is start with a small clip and see which way works best for your needs
Post Reply