windows-capture
windows-capture copied to clipboard
[FEATURE ⭐] Optional param to intentionally throttle frame capture
It would be nice to have a feature where I could limit capturing the frame capture so that I'm not analyzing every single frame but rather every nth frame.
This library is great to use for grabbing things from the screen while gaming but I'm noticing that it is affecting my FPS to a fairly noticeable degree (10-20% drop). Being able to throttle the frame capture would help reduce my CPU usage and boost my frame rate in the actual game while still letting me achieve my goals with my script.
There is no way to control the capture frame rate with the existing capture method, because the video frames are called back by the Windows system at the refresh rate.
But if you want to control the capture rate at the application level, you can use a texture that is used as a cache for the output of the capture, and then you can manually fetch the cached frames from the texture yourself by, for example, sleeping at regular intervals.
This is very efficient if you use the Direct3D interface directly, without software copying, because the copying of frames takes place in the GPU.
For example, you can refer to my example: https://github.com/mycrl/hylarana/blob/main/capture/src/win32/screen.rs#L219
But for the situation you describe, where capturing the screen causes the game frame rate to drop, I'm not sure if it's a problem with the library itself or your application layer implementation that's causing it, you might want to need to describe in detail what's going on on your end.
The default usage of this library is not efficient, it will copy the texture from the GPU to CPU memory, which is a relatively high overhead behaviour, and this can also cause the screen's texture to be locked for too long (Direct3D texture for write or copy operations many times also incorporate mutex or read/write locking mechanisms).
Now added from the API.