I have seen the other questions but somehow its not working out for me. Environment: Windows 10 MediaFoundation/SourceReader in async mode., Logitech C922 webcam 1080p pro.
Issue:
I am trying to read webcam using media foundation in async mode using sourcereader. I am getting
::OnReadSample()
called at 60-65msecs frequency instead of expected 33.33msecs for 30fps.Verified by
hr = m_pReader->GetCurrentMediaType(
(DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM,
&pType
);
and printing attributes for pType that MF_MT_FRAME_RATE
is 30 x 1. Both MIN
and MAX RANGE
are also 30 x 1.
- Verified in
::OnReadSample()
callback as well that Mediatype is same. The streamflags are not set forMF_SOURCE_READERF_CURRENTMEDIATYPECHANGED
bit. So currentmediatype hasn't changed internally.
hr = m_pReader->GetCurrentMediaType(
(DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM,
&pt
);
- I had set the fps even using
https://learn.microsoft.com/en-us/windows/win32/medfound/how-to-set-the-video-capture-frame-rate the exact function on above page but still its getting called every 64msecs or so.
Below is snapshot of the
pType
that is being used.
MF_MT_FRAME_SIZE 640 x 480
MF_MT_AVG_BITRATE 147456000
MF_MT_YUV_MATRIX 2
MF_MT_MAJOR_TYPE MFMediaType_Video
MF_MT_VIDEO_LIGHTING 3
MF_MT_DEFAULT_STRIDE 1280
MF_MT_VIDEO_CHROMA_SITING 6
MF_MT_AM_FORMAT_TYPE {F72A76A0-EB0A-11D0-ACE4-0000C0CC16BA}
MF_MT_FIXED_SIZE_SAMPLES 1
MF_MT_VIDEO_NOMINAL_RANGE 2
MF_MT_FRAME_RATE 30 x 1
MF_MT_PIXEL_ASPECT_RATIO 1 x 1
MF_MT_ALL_SAMPLES_INDEPENDENT 1
MF_MT_FRAME_RATE_RANGE_MIN 30 x 1
MF_MT_SAMPLE_SIZE 614400
MF_MT_VIDEO_PRIMARIES 2
MF_MT_INTERLACE_MODE 2
MF_MT_FRAME_RATE_RANGE_MAX 30 x 1
MF_MT_SUBTYPE MFVideoFormat_YUY2
Please suggest what might be missing in such case. I am sort of getting 15fps instead of 30fps that is being requested. I have enumerated media types of the device and it supports 30fps.
Thanks in advance.
It's likely to be because you are setting the adjusted media type on the
IMFSourceReader
instead of the handler for theIMFMediaSource
.A snippet from a full working example is shown below. Note the tailored media type is being set on
pSourceMediaTypeHandler
and notpVideoReader
. See the example source code for the variable declarations etc.I used that example to confirm I was able to set the frame rate on my Logitech C920 to 5fps and the get the correct sampling rate in the source reader loop.