Aleksoid1978 / VideoRenderer

Внешний видео-рендерер
GNU General Public License v3.0
1.03k stars 115 forks source link

MPC-BE auto change launch in FS does not work when rendering HDR video with MPC-VR #68

Closed Fr0stX76 closed 6 months ago

Fr0stX76 commented 1 year ago

Specs: Windows 10 22H2 Nvidia 3090 Driver 526.98 MPC-BE 1.6.5.3 x64 MPC-VR 0.6.3.1956 x64

The issue I have is that when I open an HDR video (see image attached) rendered by MPC-VR (default options, see attached image) , the auto change display in MPC-BE does not work if the option "launch in Fullscreen" is selected (see attached image). If I remove this option, start the video (in windowed mode), then go to Fullscreen manually, the display switches as expected.

Opening an SDR video (x265 BT709) with the same setup and option work perfectly without having to go to windowed first, it only affect HRD video.

Also using the same setup and options with MPC-BE and Madvr (which I'm trying to move away from...) will work with both HDR and SDR video, so it seems to be pointing at MPC-VR.

Is this expected? Or maybe there is something I did not setup properly in MPC-BE and/or in MPC-VR?

MPC-BE Change modejpg

MPC VR settingsjpg

HDR Video

Aleksoid1978 commented 1 year ago

Devs don't have HDR TV and can't test it.

If there is interest, you can help the developers in purchasing such a TV :).

Aleksoid1978 commented 1 year ago

Try set Auto Display HDR On/Off to used for fullscreen.

Fr0stX76 commented 1 year ago

Try set Auto Display HDR On/Off to used for fullscreen.

No luck either, launching in FS with used for fullscreen option did not work.

The only thing that seems to work is to have this option at "always used", launch the video windowed and double click to go to FS. It seems like something goes wrong in the chain when switching from 120hz to 23.976hz + going fullscreen in the player at the same time as the renderer switching HDR to “on”.

Leaving the display at 120hz (so basically not using the "autochange fullscreen monitor mode") does work but the stutters make it unwatchable,

clsid2 commented 1 year ago

It does two switches in this situation, one for the fullscreen mode and one for turning on HDR mode. Looks like the HDR switch is attempted while the fullscreen mode switch is still in progress, hence it fails. Maybe the error code that it returns indicates this situation, and isn't a generic fail. If so, perhaps that could be used to retry after a short pause.

Aleksoid1978 commented 1 year ago

Check. mpc-be64.exe.zip

Fr0stX76 commented 1 year ago

Check. mpc-be64.exe.zip

Tried this version. With the launch in FS option on, the display now swithes to HDR mode, but does not apply the "autochange fullscreen monitor mode" profile (so the display now stays at 120hz instead of going to 23.976hz).

This behaviour is exactly the same as with the older version when I turned off "autochange fullscreen monitor mode"

Aleksoid1978 commented 1 year ago

Well then, it remains to be hoped that the developers may someday have HDR TV. Unfortunately, there are no sponsors :)

Aleksoid1978 commented 1 year ago

I checked - I have the auto change launch in FS in the player and Auto Display HDR On/Off to used for fullscreen in MPC VR working fine.

Aleksoid1978 commented 1 year ago

I also checked Use Exclusive fullscreen. My MPC VR settings: MPCVR

Fr0stX76 commented 1 year ago

Well for me it does not pass the metadata to the display if I auto change launch in FS MPC-BE. HDR is off in statistics. The only way I can get the metadata to the display is to start minimised and go fullscreen manually.

Triggering "convert to HDR" does work,, but this is not what I want to do.

Not a big deal, I'm used to it by now, but I tought I would report it.

Appart from this minor issue, MPC-VR has been great for me, thanks!

Aleksoid1978 commented 1 year ago

Try this latest git version, maybe help. MpcVideoRenderer-0.6.4.1994_git2023.02.02-1167b3b.zip

Fr0stX76 commented 11 months ago

Update on this. Even the newer versions are still behaving the same

I recently found out that Alt-Enter vs Ctrl-Enter have 2 different functions in MPC-BE. Seems like launch in FS is acting more like Alt-Enter (FS same res) than Ctrl-Enter (FS) and seem to ignore the autochange FS resolution of the monitor options. At least that is true when using passthroug HDR metadata to the display in MPC-VR .

So the solution I came up with is to use an autohotkey script that is triggered by the detection of MPC-BE.exe process, which is sendinput (Ctrl-Enter) with a slight delay off 100ms after detection.

Not the most elegant fix, but it works perfectly. I now have FS with the desired resolution + refresh rate change along the HDR metadata.

I'm putting it here in case it can be helpfull either in troubleshooting the issue or for other users

Thanks

JTGaming commented 6 months ago

Is there anyone who'd be interested in testing out a fix? I don't really use this combination of features myself, so would be good to get someone who is affected by this bug. I just want to see how well it works for other people, if it crashes, etc.

clsid2 commented 6 months ago

There already is a delay option in the fullscreen settings page that can be used to solve the problem.

JTGaming commented 6 months ago

I've tried it out just now and sadly that does not seem to be the case. It's labelled pretty poorly, it does not 'delay' the auto-change, but just pauses playback on launch for x seconds which does nothing. As I said before, if anyone has an HDR screen and would like to be a beta tester, write a comment.

Aleksoid1978 commented 6 months ago

I have HDR monitor. My HDR TV don't plugged to PC and a can't test/debug.

JTGaming commented 6 months ago

Well if you decide to give it a go, here it is: MpcVideoRenderer.zip Obviously it works for me, but the whole HDR thing on windows is so janky, I wanna know if it even functions for other people.

Fr0stX76 commented 6 months ago

Well since this was my issue, I will test the built posted above and report back

And no, adding the delay does not fix it, as JTGAming wrote, the auto-change, just pauses playback on launch for x seconds which does nothing.

Fr0stX76 commented 6 months ago

@JTGaming, it works. It does take a bit longer for the image to apprear, around 3 seconds, but it fixes the issue. Its a keeper for me.

NBruderman commented 6 months ago

@JTGaming can you make the PR for the fix?

JTGaming commented 6 months ago

Yeah, this had me stumped for a good few days since there doesn't seem to be any documentation on these kinds of features from Microsoft. Took some trial and error to just get it to not crash instantly. I'll clean up the code and open a pr later tonight.

Fr0stX76 commented 6 months ago

@JTGaming

I just found a case were the renderer will not initiate.

If I use RTX video HDR, sometimes the renderer fails to initiate, when this happen I get a blackscreen.

This actually is 100% reproduceable if I use a 4K SDR video with RTX HDR. On a 1080p SDR video (also with RTX HDR), it will fail the same way maybe once out of 4, not all the time.

I know this is a very specific scenario, but I tought I would report it.

JTGaming commented 6 months ago

What option is your "windows hdr" setting on - is it "allow turn on", or "allow turn on and off"?

Also, just to get this right: Your screen is in HDR mode, and when you play a 4K SDR video with RTX Video HDR on, it crashes on launch?

JTGaming commented 6 months ago

Also, could you give this one a try? MpcVideoRenderer_no-fix.zip I've disabled my code, but it's the latest build of source. It won't do anything for this bug, but I just want to see if it still crashes on your system - that way I can tell if it's my code that's causing issues, or if it's just RTX Video HDR being wonky. Just use the same settings as you did for the above build that caused blackscreen. I'm out of the country at the moment, so don't have an nvidia system to test on until next week.

Fr0stX76 commented 6 months ago

Ok did some more testing.

Windows display HDR setting on Using "allow turn on"

You are right, using the no-fix built, I get the same result with the 4K SDR video.

With that said, with both built, disabling "launch in fullscreen" will lauch the video as expected (with RTX HDR), and double clicking to fullscreen will works as intended.

JTGaming commented 6 months ago

Are you using MPC-HC, by any chance?

Fr0stX76 commented 6 months ago

Note: My 100ms script to Ctrl-Enter has the same result, but changing the delay to 250ms seems to fix it.

And no, I use MPC-BE

JTGaming commented 6 months ago

Okay, I'll try to look into it when I'm back home in a day or two. Sounds more like an RTX Video HDR implementation issue then, if it still happens on the no-fix version.

Could you try turning on 16bit and use dithering in mpcvr? That used to fix some crashing for me, but it does have a performance impact.

Fr0stX76 commented 6 months ago

Turning 16bit float point + dithering fixes the issue with both builds you posted

JTGaming commented 6 months ago

That's good to hear. That's what i use myself since mpc-hc likes to crash with HDR content often. As long as you're not dropping frames and stuttering wildly (like my slow laptop for example), I'd recommend keeping 16bit+dither on for now. I'll update this thread if i manage to reproduce and debug this crashing.

But just to reiterate, the fix for display refresh rate not updating works fine as long as rtx video hdr is not involved, yes?

Fr0stX76 commented 6 months ago

Correct, the build you posted fixes the original issue.

Aleksoid1978 commented 6 months ago

I checked it on my monitor (it allows you to choose 30 or 60 Hz) - everything switches correctly, switching modes in the MPC-BE works + HDR mode is turned on in the system in MPC VR. In MPC-BE "launch in Fullscreen" is selected.

JTGaming commented 6 months ago

Do you mean it works correctly with the build i provided, or that you do not have this issue on your system with original source code build?

Aleksoid1978 commented 6 months ago

I don't have issue with original code.

Fr0stX76 commented 6 months ago

Here are 2 screenshots:

I used the same settings for both screenshots, I only changed the renderer version between the latest nightly and JT's.

JT's code clearly does something my display likes better with MPC-BE option.

Nightly 1

JT's 2

My settings: 3

Aleksoid1978 commented 6 months ago

I can say that I use the same settings. Perhaps it depends on the output device and how long it takes them to switch modes/frequencies and activate the HDR mode.

Aleksoid1978 commented 6 months ago

I double-checked it again by setting the options in MPC-BE and MPC VR 1:1 as in the screenshots above - everything switches perfectly.

So I don’t even know how to help in this situation. Even if someone provides code that “fixes” the situation, I will not be able to check it.

JTGaming commented 6 months ago

Could you record a short screen capture of you opening a video with the debug overlay open? I'm interested to see if i could notice a reason for why you are not able to reproduce this bug.

Maybe OBS would work - i would just like to see the mpcvr debug menu as it goes from the stages of "opening file" to "final output".

Aleksoid1978 commented 6 months ago

https://disk.yandex.ru/i/0s9nc5DBG3blLw

As you can see, both the HDR mode and the screen frequency of 30Hz are activated, at the end of the video the MPC VR settings and auto change display settings are exactly at the frequency of 30Hz, the operating frequency is of course 60Hz.

JTGaming commented 6 months ago

Since you have the code, could you breakpoint right before HandleHDRToggle() runs and show screenshots of the debug screen? One before the HandleHDRToggle() runs, and one after the video starts playing.

Aleksoid1978 commented 6 months ago

1 2

Right before call DisplayConfigSetDeviceInfo() for set HDR mode. As you can see - 30Hz SDR mode.

JTGaming commented 6 months ago

Okay, I'll be honest - I'm a bit stumped as to why it is not happening on your system. For me, toggling hdr on via DisplayConfigSetDeviceInfo() just resets the refresh rate to the maximum my display can handle and doesn't keep it to the same one as it was on SDR. Maybe it's a Samsung thing...

One last test I can think of: Set your monitor to SDR 60Hz, and press Win+Alt+B to turn on HDR. Is your display in 60Hz or 30Hz? Then, set your display to SDR 30Hz, and press Win+Alt+B to turn on HDR. What about now?

Aleksoid1978 commented 6 months ago

Always 60, HDR or SDR :)

Aleksoid1978 commented 6 months ago

Okay, I'll be honest - I'm a bit stumped as to why it is not happening on your system. For me, toggling hdr on via DisplayConfigSetDeviceInfo() just resets the refresh rate to the maximum my display can handle and doesn't keep it to the same one as it was on SDR.

Ha - and you're right, it is. But - then my screen blinks again and the mode becomes correct, with the required frequency :) 1

I don't know why it's happened.

Aleksoid1978 commented 6 months ago

So - if there is a solution that does not reset the mode/frequency when HDR mode is activated, I can check it myself.

JTGaming commented 6 months ago

Yeah, I'm not sure if it's a Windows issue, an MPC issue, or a VR issue anymore. If i turn off "restore resolution on program exit' in MPC so that ChangeDisplaySettingsExW() gets called without the CDS_FULLSCREEN flag on, it works sometimes and i get correct refresh rate with hdr (but it likes to crash often too).

I've never gotten it to work with "restore resolution on program exit" turned on (which is default). I wonder if it's your display turning the refresh rate back to 30Hz? Cause I am using the same nightly builds as you, so there shouldn't be any difference in code.

I guess the main issue here is that your setup fixes itself (SDR 60Hz -> SDR 30Hz from MPC -> HDR 60Hz from MPCVR -> HDR 30Hz from ???), but it doesn't do that for other people (for us it's only SDR 60Hz -> SDR 30Hz from MPC -> HDR 60Hz from MPCVR, thus the bug).

Aleksoid1978 commented 6 months ago

It turns out that yes - with the current code in MPC-BE (calling SetDispMode()) to set the screen mode - activating the HDR mode (even if done manually in the system settings) leads to the mode being reset.

Aleksoid1978 commented 6 months ago

Try this build MPC-BE mpc-be64.exe.zip

I changed the ChangeDisplaySettingsExW() call, but now with “restore resolution when exiting the program” enabled, if you “kill” the player process, the mode will not be restored. Otherwise, there seems to be no difference in switching screen modes.

JTGaming commented 6 months ago

That seems to work from the few side-by-side comparisons i've done.

I did notice the 'not restoring refresh rate' thing if i kill the process via task manager, which doesn't happen with the fix i have in mpcvr itself, but your code in mpc-be is probably a more elegant fix for this issue.

Aleksoid1978 commented 6 months ago

Can you show how you fix ?