Kodi Community Forum

Full Version: HDR tone mapping
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hey there,

is there any interest in implementing HDR tone mapping (meaning: converting HDR to SDR) for Kodi?

I'm aware of that Kodi runs on many different devices, some of which aren't particularly powerful. But if you Kodi devs are interested, I'd be willing to "help" you implement a reasonably fast tone mapping solution. I don't have any resources for doing actual Kodi development, though. So my help would be limited to explain how tone mapping works, what needs to be done and how you might be able to make it fast.

(Full disclosure: My motivation for starting this thread is that I've bought a Vero 4K for my personal use, so I'd be interested in having rudimentary support for HDR playback on my (secondary) SDR TV, so I don't have to keep both SDR and HDR versions of the same movie on my server.)
We have this already for OpenGL and Windows.
Oh cool. Sorry, I should have done a search first. Just didn't see the feature in my Vero 4K, so I thought it was generally still missing.

May I ask what the reason is for not having this feature on all platforms? Would it require extra code for each platform? Or is it because the GPUs on non-OpenGL platforms are too slow?

FWIW, many HDR TVs have an extremely simple tone mapping implementation which basically works by using a tweaked RGB gamma ramp. I think there's a chance this method could be used even by slow platforms. They might already have the ability to apply RGB gamma ramps. At least I know this has been a basic feature on all PC GPUs for decades...
@madshi : Are you madVR madshi?  Smile  Vero 4K has tone and gamut mapping from Amlogic, the SoC vendor.

https://github.com/osmc/vero3-linux/blob...dr_curve.h
Yep, that's me.   Laugh

Thank you very much for your reply, that sounds promising! Is it already in 17.6? I wonder how I could miss it!   Sleepy
(2018-04-28, 23:43)madshi Wrote: [ -> ]May I ask what the reason is for not having this feature on all platforms? Would it require extra code for each platform? Or is it because the GPUs on non-OpenGL platforms are too slow?
 I do platform independent code and the reference platform OpenGL. It is up to the platform devs to implement this on other platforms. Windows has alrealy followed. 
In general the GLES platforms are at the lower end of performance and capabilities. Many of those platforms bypass GL rendering and as a result lack the capability of features like tone mapping.
If you want to get tone mapping on the Vero, you need to poke AML. Needs to be implemented in their drivers.
(2018-04-29, 09:31)madshi Wrote: [ -> ]Thank you very much for your reply, that sounds promising! Is it already in 17.6? I wonder how I could miss it!   Sleepy
no, it's only in v18 nightlies since it got added just a couple weeks ago
(2018-04-29, 09:31)madshi Wrote: [ -> ]Yep, that's me.   Laugh

Thank you very much for your reply, that sounds promising! Is it already in 17.6? I wonder how I could miss it!   Sleepy
Cool!
If you are referring to the Vero 4K, I believe it is already present, but there are no GUI selectable options. You have to use commandline options. This discussion on the OSMC forum has some details: https://discourse.osmc.tv/t/4k-hdr-video...v/54220/18

@Sam.Nazarko would be the guy you need to contact for anything Vero 4K.
(2018-04-29, 14:37)FernetMenta Wrote: [ -> ]I do platform independent code and the reference platform OpenGL. It is up to the platform devs to implement this on other platforms. Windows has alrealy followed. 
In general the GLES platforms are at the lower end of performance and capabilities. Many of those platforms bypass GL rendering and as a result lack the capability of features like tone mapping.
If you want to get tone mapping on the Vero, you need to poke AML. Needs to be implemented in their drivers.
Ah ok, thanks. So anything rendering related for the Vero (e.g. also "smooth motion" frame blending) can only be done by AML? What is the best way to contact AML about things like that?
 
(2018-04-29, 18:31)da-anda Wrote: [ -> ]no, it's only in v18 nightlies since it got added just a couple weeks ago 
Ah, that makes sense, thanks!
 
(2018-04-29, 18:51)wesk05 Wrote: [ -> ]If you are referring to the Vero 4K, I believe it is already present, but there are no GUI selectable options. You have to use commandline options. This discussion on the OSMC forum has some details: https://discourse.osmc.tv/t/4k-hdr-video...v/54220/18

@Sam.Nazarko would be the guy you need to contact for anything Vero 4K. 
Thank you!
It's trivial to port the tonemappping shader code to the GLES used by the "non reference platforms".
What is very much less trivial is to get the proper HDR lightning values from the stream for platforms not decoding through ffmpeg, but it can be done by analyzing the frames passed to the codecs for specific SEI metadata.

Anyway, as already said, it will only work for platforms/codecs using GLES to do the final rendering (eg VTB for Apple, MediacodecEGL for Android).
That solution will not work on AML (as is the the Vero4K), where decoding AND rendering are done in hardware, but maybe AML has a SoC solution, indeed.

Edit: It's trivial for GLES once EGL is bumped to 3.0. There is a PR lingering for months: https://github.com/xbmc/xbmc/pull/13457
Thanks Koying. Is there a wiki page anywhere which describes which platforms/boxes are using which rendering path (e.g. OpenGL vs GLES vs hardware specific), and which the limitations of each rendering path are? That sounds like important information to any user who wants to buy a new device for Kodi.
@madshi 
Please do help out the Kodi Team however you can. 
The have implemented a non defeatable and non configurable tone mapping that only works so-so ONLY with Rec.709 (within rec.2020) primaries. You can't even use Kodi's built in 3DLUT since the tone mapping gets applied twice. Obviously a non defeatable tone mapping that isn't even working correctly shouldn't be part of Kodi. 

Kodi needs to duplicate the functionality of madVR:
Option to use a separate 3DLUT for Rec.709/DCI-P3/Rec.2020 primaries. 
Option to use pixel shader math to tone map on the fly.
And an option to passthrough HDR (of course won't work properly until Linux supports HDR metadata...which could take many years)
Kan anyone confirm if the broken and non defeatable tone mapping, which is currently is Leia Alpha, will be removed?
(2018-05-20, 13:35)Soli Wrote: [ -> ]Kan anyone confirm if the broken and non defeatable tone mapping, which is currently is Leia Alpha, will be removed?
 Definitely not.
Why would you want to include something that is broken and destroys picture quality?
Pages: 1 2