mmozeiko / wcap

Simple and efficient screen recording utility for Windows 10 and 11
The Unlicense
795 stars 31 forks source link

recording fps drops when recording games #16

Closed chenjie4255 closed 2 years ago

chenjie4255 commented 2 years ago

Hi, thanks for this terrific work.

I encountered a problem when I use wcap.exe to record games such as HORIZON 5 or Microsoft Flight Simulator, the FPS in result file may drop to 10 or even less especial when the camera moves (the FPS in games didn't fluctuate). I have tried lots of combination settings(including FPS, hardware/software encoding, resolutions, etc...), but none of them helps.

I tried to modify some codes but am unfamiliar with Windows Media Foundation and d3d program. I saw some error logs but I don't know if they were relative to this issue. It happens when the code runs into IMFSinkWriter_SetInputMediaType

2022-09-02 19:58:22.875     1B48 [AMFH264AsyncEncoderMF]   Error: ..\..\..\..\..\runtime\src\mft\vceencoder\H264AsyncEncoderMFT.cpp(179):OnCheckInputType(1): Output type must be set first.
2022-09-02 19:58:22.875     1B48 [AMFAsyncMFTBase]   Error: ..\..\..\..\..\runtime\src\mft\mft-framework\AsyncMFTBase.cpp(709):AsyncMFTBase(1)::OnCheckInputType(StreamID=0) - failed with HRESULT(0xC00D6D60)
2022-09-02 19:58:22.875     1B48 [AMFH264AsyncEncoderMF]   Error: ..\..\..\..\..\runtime\src\mft\vceencoder\H264AsyncEncoderMFT.cpp(514):OnSetOutputType(1): failed to set MF_MT_FRAME_RATE set to 60/1, HRESULT(0x80070057)

BTW, I am using the RX 6900 with the latest Driver, and the System version is windows 11. Do you have any idea about how to improve the recording performance when recording games?

I tried to use the native game recording App by Windows system and obs-studio with WCG used, but neither of them has this problem.

mmozeiko commented 2 years ago

Low performance is probably because wcap failed to use hardware encoder, so it is falling back to software encoding on CPU. And software h264 encoding from MS does not have best performance - it works fine for mostly static content, like recording webcam or desktop, but for fast moving content like games it will be bad.

You can confirm what encoder wcap used if you open final mp4 file in some hex editor, and if you see Microsoft H.264 Encoder somewhere at beginning (usually in first 200 bytes), then that means CPU software encoder was used.

I have not done much testing with AMD gpu's so maybe there's something extra that is needed to work properly. Don't really have AMD gpu here.

Those messages come from internal SinkWriter implementation, so it's hard to know if they mean actual error or are just part of normal setup (where it tries one thing, and then something else). Though one strange thing is not being able to set 60Hz frame rate. I would think that should be possible in any situation. Maybe you're recording very high resolution (4k) and GPU encoding does not support 60Hz on such high res? Try to set max 1080p @ 60Hz, it may help. But not sure.

Another way to debug would be if you record full MFT trace, that may give me hints on what could be happening there. If you want to do that, then run cmd.exe with admin privileges, and then start wcap like this:

"C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\mftrace.exe" -k all -l 5-o log.txt path\to\wcap.exe

(the version number in might be different depending on which Windows SDK version you have installed). Now start recording in wcap and stop it (no need to run it for more than a second). Then close wcap. It should create large log.txt file with bunch of info what it is doing inside MFT.

chenjie4255 commented 2 years ago

Hi, @mmozeiko thanks for your reply.

After a week of testing, I cannot reproduce this problem anymore. Basically, I made the following change to my computer.

I am not quite sure if the 3rd one may help. I tried to revert this change but I didn't see a distinct change.

I guess I can close this issue. Thanks for your support.

mmozeiko commented 2 years ago

My bet is on driver reinstall. These hw video encode/decode capabilities often break in strange ways on different driver versions. Browsers typically have many blacklisted gpu driver versions because of this.