Search code examples
winapivideovideo-capturems-media-foundation

How to set framerate for IMFSourceReader


I'm using Media Foundation for video capture in the following simplified algorithm:

  1. Call MFCreateDeviceSource to get capture source
  2. Call MFCreateSourceReaderFromMediaSource to create source reader
  3. Enumerate formats of source reader and select desired
  4. SetCurrentMediaType on IMFSourceReader to set desired format.
  5. Call ReadSample on IMFSourceReader synchronously to get samples

Question: How to set framerate so ReadSample will return frames at specified framerate?

I tried to set framerate in 4. with MFSetAttributeRatio( format, MF_MT_FRAME_RATE, num, denom ) with no luck. Seems that some cameras give me samples at 30 fps, some at 15 fps and they dont respect fps set in format. I also checked MF_MT_FRAME_RATE_RANGE_MAX and my fps is valid.

I've got webcam which gave me 30 fps when using DirectShow and format says it supports 30fps. But I can get only 15 from it using Media Foundation.


Solution

  • Found the answer for myself. One can't set framerate on IMFSourceReader.

    One should set desired format on IMFMediaSource and then wrap it with IMFSourceReader.