Search code examples
c++ms-media-foundationdxgidesktop-duplication

Desktop Duplication - Limiting the Framerate


Using the Windows Desktop Duplication API, I want to limit the capture of the monitor to no more than 60fps. I know the AcquireNextFrame() has a 'wait' parameter, so maybe this can be used to limit the framerate although I am unsure how. I also noticed that at least when I have an additional monitor connected, that monitor's framerate will go up to the framerate of my main monitor. For example, my external 60hz monitor is reportedly pulling 200fps from desktop duplication.

I do not see any other questions on this site that give an answer on how to achieve the FPS limitation on this API, so any help would be appreciated.

I tried specifying 16ms in as the wait parameter as well as sleeping between AcquireNextFrame. The issue with the later is the fact that sleeping will cause it to miss frame updates.


Solution

  • The API does not offer you frame rate limitations. You can just throttle your polling and sleep between AcquireNextFrame having desktop updates collected on background before you actually get them with your next request.

    The issue with the later is the fact that sleeping will cause it to miss frame updates.

    You can request higher precision timer service (see timeBeginPeriod and friends) and/or use Real-Time Work Queue API (which Microsoft Media Foundation API is built on) to get finer grained execution time slices to request your next frame.