Page 1 of 24

HDR -> SDR conversion

Posted: Tue Jan 23, 2018 11:39 am
by Guest
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

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Tue Jan 23, 2018 12:25 pm
by admin
All help will be welcome. Thanks!

What do you mean by a "4K system"?

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Tue Jan 23, 2018 4:29 pm
by Guest
GTX 1080Ti hooked up to a receiver which goes to a 65" 4K TV
All HDR10 and Dolby Vision capable

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Tue Jan 23, 2018 5:33 pm
by admin
:bow:

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Tue Jan 23, 2018 5:55 pm
by Guest
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

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Fri Jan 26, 2018 12:54 am
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 ?

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Fri Jan 26, 2018 3:31 pm
by Guest
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

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Fri Jan 26, 2018 4:27 pm
by admin
Link for nvhsp?

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Fri Jan 26, 2018 5:15 pm
by Guest
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

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Fri Jan 26, 2018 5:37 pm
by admin
Thanks!

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Fri Jan 26, 2018 7:03 pm
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: )

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Sat Jan 27, 2018 8:27 pm
by hydra3333
would you be able to share an example commandline ?

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Sat Jan 27, 2018 8:35 pm
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

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Sat Jan 27, 2018 8:49 pm
by hydra3333
thank you

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Fri Feb 02, 2018 8:02 pm
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?

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Sat Feb 03, 2018 5:52 am
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

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Sat Feb 03, 2018 7:57 am
by admin
Thanks for the info, gonca.

What set did you get?

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Sat Feb 03, 2018 10:23 am
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?

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Sat Feb 03, 2018 11:36 am
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.

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Sat Feb 03, 2018 9:12 pm
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.

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Sun Feb 04, 2018 10:28 am
by admin
Sounds reasonable.

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Mon Feb 05, 2018 10:54 am
by admin
Hey gonca, if I read you correctly you are converting your UHD disks to MKV. How are you ripping these disks?

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Mon Feb 05, 2018 3:09 pm
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

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Wed Feb 07, 2018 8:10 pm
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 :)

Re: HDR -> SDR tonemapping for DGDecodeNV

Posted: Thu Feb 08, 2018 5:09 am
by Guest
All I can say is start with a small clip and see which way works best for your needs