Kodi Community Forum

Full Version: My attempt to bring HDR pass through to Kodi for Nvidia cards
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
(2019-06-24, 10:24)HomeTheatreGuru Wrote: [ -> ]Hi mate, how'd your exams go?

Everything went fine but I'm moving to a new city for some internship. 

I plan to start working on it again hopefully next week but this will depend on a lot of stuff. 


By the way, is the code for android versions of kodi the same on github?
It doesn't seem so or I'm kind of blind. 
I would like to take a look at the source of kodi for the nvidia shield so I could check where the function calling for HDR is.
Yes, it's only one master code for all kinds of operational systems.
I'd like to give this a shot.  Can anyone shed some light on where/how to use the additional files?  I was thinking that Eventghost could run a script through a python command action.  Triggered by player on play event with "HDR"variable.  I remember doing something similar with 3D, command line to switch 3D. 

thx
(2019-07-01, 03:52)fuqit Wrote: [ -> ]I'd like to give this a shot.  Can anyone shed some light on where/how to use the additional files?  I was thinking that Eventghost could run a script through a python command action.  Triggered by player on play event with "HDR"variable.  I remember doing something similar with 3D, command line to switch 3D. 

thx

Please do.
I had little to no time for my own real world stuff. I don't think I'll be able to work on this so soon.

If anyone wants to try to implement the HDR switch externally this might be possible.

If anyone wants to try to add the code to kodi itself, I can help with the knowledge I got so far.

Sorry to give you guys hope on this but my intership is 10+ hours per day and it will last for the next 4 months.
damn dude,  hope you're at least getting paid! prob not though..   the "switch" isn't a .bat so I can't open it with notepad to see what's in it.  can you at least post the code?
(2019-07-03, 19:37)fuqit Wrote: [ -> ]damn dude,  hope you're at least getting paid! prob not though..   the "switch" isn't a .bat so I can't open it with notepad to see what's in it.  can you at least post the code?

Yeah full story is I'm getting my degree as a veterinarian.
So I have to work as an internship for 4 months and present my final graduation work.
Right now I'm working at a veterinary hospital.

And sure I can give you the source code.
This is the original HDR switcher that will compile with visual basic 2017 (the same as kodi)

https://github.com/worleydl/hdr-switcher

I fixed it to be able to compile with visual basic 2019 and forked it:
https://github.com/fandangos/hdr-switcher

I have compiled it as an exe here:
https://mega.nz/#!yM8ECYID!0Qv6VtX6437Mo...Rt-5ifyUqQ

Ready to use.

The latest version of kodi on my github will compile but for some odd reason it will switch HDR on only while exiting Kodi.
To me the only thing missing is finding the correct spot to place the function calling HDR On.

You can find it here.
https://github.com/fandangos/xbmc

I really wish I could have pulled this through.
When I have time if no solution is found I'll get back to it.
Where I'm staying I don't have access to a 4K screen and no one even knows what HDR means, still if someone with a 4k hdr screen could test this workaround for now:

1. edit advancedsettings.XML into C:\Users\YOUR USER NAME HERE\AppData\Roaming\Kodi\userdata
With the following:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<advancedsettings>    
    <try10bitoutput>true</try10bitoutput>    
</advancedsettings>

2. Get the switcher from here: 
https://mega.nz/#!yM8ECYID!0Qv6VtX6437Mo...Rt-5ifyUqQ

3. Create a visual basic script with this:
Set WshShell = CreateObject("WScript.Shell" ) 
WshShell.Run chr(34) & "C:\ THE PLACE WHERE THE FILE YOU DOWNLOADED IS\Switcher.exe" & Chr(34), 0 
Set WshShell = Nothing 

To create this script just open a notepad, copy and paste the above, edit for the place where you saved the Switcher and save as .VBS

3. Get kodi Add-on Kodi Call Back
it's in the service addons section. 

4. Go into the Kodi CallBack addon settings
Change Task 1 to script.
Set Max number of times this task runs to 1 instead of -1.
Switch off requires shell and wait for script to complete.

5. Go into Events tab
Change to On Playback started
and select task 1.

Please, tell me that it works. 

Explaining: this vbs script opens the switcher.exe without a command window, this should in theory trigger HDR and don't loose focus during the playback.

If the above script does not work, please try a to create a .bat file with the following:
START /MIN CMD.EXE /C "C:\Where the Switcher is\Switcher.exe"

Save as .bat and change task 1 to use the bat file instead of the vbs script. 

Let's see if we can get this rolling. I'll only be able to see my 4k TV in 2 months from now so beta testers are more than welcome.
Sorry, doesn't work at all.  Switcher.exe errors with a bunch of missing dll's.  Also, your instructions should include to enter a location for the script in Kodi CallBack addon settings.  Without a location for a script to run, the addon isn't going to do anything.
(2019-07-15, 17:42)brazen1 Wrote: [ -> ]Sorry, doesn't work at all.  Switcher.exe errors with a bunch of missing dll's.  Also, your instructions should include to enter a location for the script in Kodi CallBack addon settings.  Without a location for a script to run, the addon isn't going to do anything.

The dlls are in the first post, sorry for not pointing those a second time, totally forgot about those.

The script used in Kodi CallBack is the one you create, it can be the vbs file or the bat file.
The vbs is the one I posted on step 3.
The bat is at the end of the previews post.
I understand about the two different scripts.  It's your instructions that are unclear.  There is more input needed when using Kodi Callback such as the location of the script it's supposed to handle.  Not just what you have instructed in your post for testers.  In Callback, you must navigate to where you have the script located and save that input.  'Script executable file - browse'.  You should add that to your instructions since not all of us are savvy especially me.  There's actually two entries for that info which I found odd unless running more than one script at a time perhaps.  At this point, I assume that has to be done too.  Still it doesn't work for me.

Anyway, that said, I grabbed the dll's.  Still does not function.  However, I can manually execute either the .bat or the .vbs which in turn calls switcher.exe with no errors now since I have the dll's.  Switcher then does indeed engage Windows HDR.  Best of all, at display level.  The problem is, Kodi Callback is not doing anything at the start of an HDR title or any other title even though it is pointed to the script and is set with the parameters you provided.  Something is not correct here?  Having never used it before, I'm unfamiliar but looking it over, it's pretty straight forward.  The dependencies were installed along with it but perhaps other KODI settings prevent it from working?  Most likely it my user error though.  What that is... I've no idea?  I've tried fullscreen and windowed.  Gave up after that having bigger problems I'll explain below.

For years I've used other external players for HDR playback too such as MPC-BE with madVR handling the HDR duties.  It relies on the nVidia private API to do the switching for my GTX 960.  It looks and works perfectly.  I also use DVDFab Media Player for HDR duties as well.  It too looks and works perfectly.  v.3 of it uses the private API to switch as well.  v.5 of it uses Windows API to engage Windows HDR switch.  I use all of them to this day plus a few others.  PotPlayer, VideoPlayer, MPC-HC and PowerDVD too.  In other words, I have a pretty good idea about calibrating everything to work harmoniously with no need to adjust anything after initial setups.  Display HDR mode is display HDR mode no matter how you engage it. 

VideoPlayer (KODI) I've used for HDR to SDR with pretty good results although it isn't passing through and isn't up to full potential.  This is why I've had high hopes for your work and I'm testing with you.  To introduce true HDR to the KODI internal VideoPlayer and make quite a few users happy.  I haven't looked your code over but perhaps it can be modded at some point for AMD and Intel as well.  In the mean time, this is a great start.  Now for the meat and potatoes:

I mentioned DVDFAB v.5 player above because it uses Windows API.  I know what to expect from a player using it.  I know I don't have to calibrate any differently whether using the Windows API or nVidia.  Each looks perfect.  However, VideoPlayer using Windows HDR looks far from perfect.  It is waaaay too bright and washed out.  This has always been the case.  HDR to SDR looks much better in my environment.  Perhaps others have better results using HDR titles, the KODI player, and Windows HDR switched on with an nVidia GPU passing it through.  I've simply never had decent results.  Feedback would be nice.  KODI calibration settings are pretty much default.  I toggled many of them trying to calm the picture down such as Render Methods, Scalers, Reinhart, player brightness and contrast, etc.  I have no desire to try to calibrate my display for KODI since it's already harmonious with my 6 other players but figured I'd try just for testing.  I also don't want to screw up KODI calibrations because it will affect my other non-HDR titles.  You wrote that this is for nVidia.  I expected it's API to do the switching.  I don't understand why Windows engages its HDR switch?  Could it be your compiled switcher is activating nVidia HDR and Windows HDR at the same time which would account for the blown out picture I see?

Any suggestions for a decent picture and automated switching via KODI Callback would be appreciated.  Since you said all is working on your end, it's got to be something on mine.  Keep up the good work when you have time.  It's beginning to roll imo.
(2019-07-16, 01:59)brazen1 Wrote: [ -> ]I understand about the two different scripts.  It's your instructions that are unclear.  There is more input needed when using Kodi Callback such as the location of the script it's supposed to handle.  Not just what you have instructed in your post for testers.  In Callback, you must navigate to where you have the script located and save that input.  'Script executable file - browse'.  You should add that to your instructions since not all of us are savvy especially me.  There's actually two entries for that info which I found odd unless running more than one script at a time perhaps.  At this point, I assume that has to be done too.  Still it doesn't work for me.

I can't specify exactly where the scripts can be because each person can save it anywhere he/she wants. The location is not important for this to work. But I get what you are saying. 
I also noticed the two entries and I don't get it either. 
 
(2019-07-16, 01:59)brazen1 Wrote: [ -> ]Anyway, that said, I grabbed the dll's.  Still does not function.  However, I can manually execute either the .bat or the .vbs which in turn calls switcher.exe with no errors now since I have the dll's.  Switcher then does indeed engage Windows HDR.  Best of all, at display level.  The problem is, Kodi Callback is not doing anything at the start of an HDR title or any other title even though it is pointed to the script and is set with the parameters you provided.  Something is not correct here?  Having never used it before, I'm unfamiliar but looking it over, it's pretty straight forward.  The dependencies were installed along with it but perhaps other KODI settings prevent it from working?  Most likely it my user error though.  What that is... I've no idea?  I've tried fullscreen and windowed.  Gave up after that having bigger problems I'll explain below.

yes, the switcher do work, this was the reason why I started this whole quest to learn C so I could implement the switcher in Kodi. 
The swither code compiles with Visual Basic 2017 just like Kodi. My fixed version for VB 2019 is not even needed for this. 

As I've said, I don't know if this Kodi CallBack would work, I don't have access to a 4k HDR tv here, this is just an idea of how this could work. 
I have a 1080p tv here and I can see the screen flash and if I alt+tab I can see a minimized cmd with the switcher running when I start a movie. 
This gave me some hopes that this could work. 

The thing is, the switcher opens up a dialogue box when triggering HDR this means it breaks the fullscreen from Kodi and when you revert back to kodi, it will  kill the HDR set by the switcher. 
That's why what I'm trying to do here is open it in the background. 
I don't have the means to compile anything here either, or else I could just comment the lines of the switcher.exe code to remove the dialogue box. 
So for 2 months what I did, is all we have. 
(2019-07-16, 01:59)brazen1 Wrote: [ -> ]For years I've used other external players for HDR playback too such as MPC-BE with madVR handling the HDR duties.  It relies on the nVidia private API to do the switching for my GTX 960.  It looks and works perfectly.  I also use DVDFab Media Player for HDR duties as well.  It too looks and works perfectly.  v.3 of it uses the private API to switch as well.  v.5 of it uses Windows API to engage Windows HDR switch.  I use all of them to this day plus a few others.  PotPlayer, VideoPlayer, MPC-HC and PowerDVD too.  In other words, I have a pretty good idea about calibrating everything to work harmoniously with no need to adjust anything after initial setups.  Display HDR mode is display HDR mode no matter how you engage it. 

VideoPlayer (KODI) I've used for HDR to SDR with pretty good results although it isn't passing through and isn't up to full potential.  This is why I've had high hopes for your work and I'm testing with you.  To introduce true HDR to the KODI internal VideoPlayer and make quite a few users happy.  I haven't looked your code over but perhaps it can be modded at some point for AMD and Intel as well.  In the mean time, this is a great start.  Now for the meat and potatoes:
Ok, I understand what you are saying but let me stop you here and explain, the code provided here is for Nvidia only. 
Unless someone decides to write some little tool for AMD or Intel and provide the source I don't have anywhere near the experience needed to pull this off. 

The story behind why I started doing this is, everyone kept saying no to implement this so I went to Madshi forum's and asked for the documentation of the nvidia private apis. 
Someone gave it to me, I googled the string that triggers the HDR and found the switcher on github. 
That's why I'm trying this out. Nvidia provides code for HDR switching in it's documentation but I don't have the knowledge to take that piece of code and turn into a fully functional .exe or even put that inside a kodi build, I needed someone elses work to do this. 
 
(2019-07-16, 01:59)brazen1 Wrote: [ -> ]I mentioned DVDFAB v.5 player above because it uses Windows API.  I know what to expect from a player using it.  I know I don't have to calibrate any differently whether using the Windows API or nVidia.  Each looks perfect.  However, VideoPlayer using Windows HDR looks far from perfect.  It is waaaay too bright and washed out.  This has always been the case.  HDR to SDR looks much better in my environment.  Perhaps others have better results using HDR titles, the KODI player, and Windows HDR switched on with an nVidia GPU passing it through.  I've simply never had decent results.  Feedback would be nice.  KODI calibration settings are pretty much default.  I toggled many of them trying to calm the picture down such as Render Methods, Scalers, Reinhart, player brightness and contrast, etc.  I have no desire to try to calibrate my display for KODI since it's already harmonious with my 6 other players but figured I'd try just for testing.  I also don't want to screw up KODI calibrations because it will affect my other non-HDR titles.  You wrote that this is for nVidia.  I expected it's API to do the switching.  I don't understand why Windows engages its HDR switch?  Could it be your compiled switcher is activating nVidia HDR and Windows HDR at the same time which would account for the blown out picture I see?
It's not calibration. It's just that Kodi, right now, doesn't support HDR so when you trigger it on windows everything is messed up. 
Maybe even if we get the switcher working with Kodi Callbacks it will look bad, I don't know yet. 
The reason why I think it can be correct is that it has the try10bitoutput option to be enabled so that indicates it will work. 

My swithcer only has the nvidia apis. When using MadVR, I see the same blown out picture you mention if I alt tab into the desktop without stoping a HDR movie. 
I believe this is caused by windows not pushing it's own desktop into the HDR color spectrum but still as we know Madvr is perfect with HDR. 
(2019-07-16, 01:59)brazen1 Wrote: [ -> ]Any suggestions for a decent picture and automated switching via KODI Callback would be appreciated.  Since you said all is working on your end, it's got to be something on mine.  Keep up the good work when you have time.  It's beginning to roll imo.

I did not say all is working on my end. I said I was able to get kodi to compile without errors, which was a big deal for someone without much coding skills. 
I said I could get it to switch to HDR when I close kodi. 
That means the code is working only the placement of the calling function is wrong and I have no idea where to put it. 

When using Kodi Callback I can see the screen flash before the movie starts and I can see the script is running but since I don't have a 4k HDR TV here I have no idea if it's actually working. 
That's why I asked if someone would like to try it out.
Ok, got a friends computer, downloaded the entire kodi github and I'm trying this once again.

Please, someone with a HDR tv try this:

https://mega.nz/#!DRF2FY7D!QGxbr5qdJghOM...x3ltmwpoOY

There are 5 kodi .exe inside. Place one at a time at 
C:\Program Files\Kodi
rename to Kodi.exe
* this is x64 only.

Start it and try to play a movie. 

I've tried to add the SetHdrMonitorMode(true); to VideoPlayerVideo.cpp
and if this doesn't work I've tried use Application.cpp and hijack the if (file.IsVideo() || file.IsGame())
that is used to speed up playback to at the same time, trigger hdr mode. 

Please, report back if nothing happens or if it actually works.
@brazen1 did you have some time to conduct further tests by any chance?

Would pay money to have this work but currently not able to test myself.
(2019-07-22, 02:58)HomeTheatreGuru Wrote: [ -> ]@brazen1 did you have some time to conduct further tests by any chance?

Would pay money to have this work but currently not able to test myself.

Those are outdated. 
I've made a thread for it in the development section:


https://forum.kodi.tv/showthread.php?tid...pid2870445

After finding some blog posts about how HDR works with DirectX I think I understand what actually triggers HDR and the color space change in the swapchain. 
Hopefully this is finally working and implemented but I still need someone with a nvdia video card and hdr display to test this out.
@fandangos

Do you want this thread closed so members comment in the correct thread or do you need it open for other reasons?
Pages: 1 2 3