Aleksoid1978 / VideoRenderer

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

Stutter before starting playing? #43

Closed nestflow closed 2 years ago

nestflow commented 2 years ago

Between opening video and before playing, there's a stutter like one second long. In this period the display stops updating (and also the pointer), which is a bit annoying.

It seems somehow related to the Intel + Nvidia GPU setting on laptop, because when I run MPC-BE with VR on dedicated GPU, the stutter is gone. Also, the stutter doesn't happen with MPC-BE & inbuilt EVR renderer.

It should not a problem of specific system, as I had exactly the same problem on my previous laptop. However I couldn't find any solutions and discussions on Internet :(

My MPC-BE version is 1.6.0.6767, and I tested with both VR 0.5.6.1807 and 0.5.7.1812.

clsid2 commented 2 years ago

Test if disabling "Use Direct3D 11" solves it.

Which Intel and Nvidia GPU models?

nestflow commented 2 years ago

No, it exists in both D3D9 and D3D11 mode.

I use a I9-11900H and RTX3060 model.

Aleksoid1978 commented 2 years ago

Record video from desktop with stutter, enable statistics(Ctrl+J) in MPC VR.

nestflow commented 2 years ago

I know it's weird, but if I run my OBS (even NOT start recording), the stutter magically disappears.

But I can give a screenshot of shutter (with no recording software running) here: https://imgur.com/a/AV55boj

nestflow commented 2 years ago

Actually, I find that the stutter is gone as long as there's any application using dedicated (Nvidia) GPU at the same time, like OBS or games.

It also works if I just completely disable Nvidia GPU in utility of my laptop. Related to GPU initialization I guess?

clsid2 commented 2 years ago

You can set Nvidia (or Intel) as preferred GPU for MPC-BE in the Windows 10 settings. Settings > Display > Advanced

nestflow commented 2 years ago

Yes I can (and that's how I did in the first post), but it won't solve the stutter if Intel GPU is set as preferred. But for a laptop, I really don't want to use power-consuming Nvidia GPU just for video playing...

clsid2 commented 2 years ago

Does it also happen with MPC-HC? I ask because the Nvidia driver has an application profile for MPC-HC, which defaults to the integrated GPU. I don't know if this overrules the Windows setting.

If it works better with MPC-HC, then you can add the BE exe names to its profile with Nvidia Profile Inspector.

nestflow commented 2 years ago

Does it also happen with MPC-HC? I ask because the Nvidia driver has an application profile for MPC-HC, which defaults to the integrated GPU. I don't know if this overrules the Windows setting.

If it works better with MPC-HC, then you can add the BE exe names to its profile with Nvidia Profile Inspector.

I did a quick test and unfortunately MPC-HC situation is basically the same. (with your fork of MPC-HC 1.9.18)

Aleksoid1978 commented 2 years ago

Developers don't have such hardware and can't debug/test.

Aleksoid1978 commented 2 years ago

It looks like the system or video driver, when starting playback, does some initialization when using Intel. And it takes a long time. There is no such code in the renderer.

nestflow commented 2 years ago

It looks like the system or video driver, when starting playback, does some initialization when using Intel. And it takes a long time. There is no such code in the renderer.

I agree. But EVR (and I remember madVR on my previous system) doesn't have this issue. I'll go back to EVR for now and maybe try to locate the problem afterwards. Thanks for your suggestions!

clsid2 commented 2 years ago

EVR uses D3D9. It also does not use the DXVA2 video processor for scaling. So test if disabling the video processor in MPCVR makes any difference. Open the Intel graphics control panel. In the video section, find the option "Contrast Enhancement" and disable that. This feature is useless, and known to cause a whole lot of problems.

@Aleksoid1978 A debug build plus DebugView tool could maybe show which part of the code has the delay?

clsid2 commented 2 years ago

Are you using D3D11 hardware acceleration in the video decoder? Test with DXVA2 decoding.

There was a fix in LAV Filters today that solves a startup delay with D3D11 decoding.

nestflow commented 2 years ago

Enable/Disable DXVA2 options makes no difference. Also want to note that when using D3D9, there's a similar stutter when resizing videos in addition to startup, where D3D11 doesn't have. Here is a comparison by randomly resizing:

a c b
nestflow commented 2 years ago

Are you using D3D11 hardware acceleration in the video decoder? Test with DXVA2 decoding.

There was a fix in LAV Filters today that solves a startup delay with D3D11 decoding.

I'm using MPC video decoder with MPC-BE, and all decoders (DXVA2, D3D11 and D3D11CB) has this problem, but NVDEC doesn't. I'll test the Intel driver and LAV filters later.

nestflow commented 2 years ago

Ok I tried with latest LAV filter build (0.75.1.45-git) and its decoders. Result is similar: Only Nvidia CUVID decoder has no stutter, and even "None" (software decoder I guess) is problematic.

Turning on/off Contrast Enhancement and other various options in Intel control panel also doesn't make any differences.

Aleksoid1978 commented 2 years ago

As i see on screenshots, there is no issue when using D3D11 Native in decoder and D3D11 in VR.

nestflow commented 2 years ago

As i see on screenshots, there is no issue when using D3D11 Native in decoder and D3D11 in VR.

Yes, if I use D3D11, there's no issue in resizing, only in starting playing. It's hard to be shown in a screenshot, since it happens before rendering videos and statistics.

But the situations are pretty similar to resizing issues in D3D9. Just wandering if the causes are related and help debugging.

nestflow commented 2 years ago

https://user-images.githubusercontent.com/20128868/149972941-c2c7c937-9de6-494d-a392-d587cec062ac.mp4

Ok I use my phone to record the issue. You can see that before first start playing, the window of MPC-BE and the mouse (actually the whole screen) freezes for a while. It also happens when loading.

Aleksoid1978 commented 2 years ago

Hmm, normal opening.

nestflow commented 2 years ago

Hmm, normal opening.

Well I forget to note that I'm moving my mouse all the time in the recording. It's not quite normal that when opening videos, the screen freezes and the cursor stops moving. And it's not happened when using EVR.

Could you provide some debug/log ways like @clsid2 suggests? I think it's hard to locate the problem by screenshots or recordings.

Aleksoid1978 commented 2 years ago

Here is debug version + dbgview - https://disk.yandex.ru/d/0cFtmsMD81QQdA Register this version or replace over you's. Run dbgview, then open video in MPC-BE. Close MPC-BE and save log in dbgview. Then upload here, better in .zip format.

Aleksoid1978 commented 2 years ago

If mouse cursor stop moving - it's something with you system, it's freeze. Software can't prevent mouse cursor from moving.

nestflow commented 2 years ago

Here's the log: mpc.zip - but as you said, it seems not a problem of software.

After searching around the Internet, I found several posts about this "micro stutter" problem. The stutter is caused by dedicated GPU switching, especially when dGPU is awaked. I confimed it by installing an older Nvidia driver which keeps dGPU awaken more aggresively.

However, it's strange that neither the LAV decoder and MPCVR actually uses dGPU in this situation - they all run on Intel GPU and dGPU is just awaken at start and went back to sleep for a while, without any workloads. If the GPU goes back to sleep, the stutter comes back if a new video starts playing (and wake up dGPU again, which cause the stutter).

So, if the switching stutter is problem of driver (or system), I wonder if it's possible to avoid waking up the dGPU in MPCVR when the workloads are on Intel GPU? Or maybe an option to do that compulsively?

Aleksoid1978 commented 2 years ago

If it's drivers fault - close issue. I think bug in driver - when application want access to some functional(or something similar) in D3D9/D3D11, driver wake up dGPU, although it shouldn't.

nestflow commented 2 years ago

Yes I think it's driver - but EVR seems to find a way to avoid it and doesn't wake up dGPU. I'll close this issue but hope there's some future improvement on it.