Get all supported FPS values of a camera in Microsoft Media Foundation

痴心易碎 提交于 2019-11-30 22:24:00

The frame rates and other attributes can be retrieved with code similar to the following (error checking omitted for brevity):

Microsoft::WRL::ComPtr<IMFSourceReader> reader = nullptr;
/* reader code omitted */

IMFMediaType* mediaType = nullptr;
GUID          subtype { 0 };

UINT32 frameRate = 0;
UINT32 frameRateMin = 0;
UINT32 frameRateMax = 0;
UINT32 denominator = 0;
DWORD32 width, height;
DWORD index = 0;

HRESULT hr = S_OK;
while (hr == S_OK)
{
    hr = reader->GetNativeMediaType((DWORD) MF_SOURCE_READER_FIRST_VIDEO_STREAM, index, &mediaType);
    if (hr == MF_E_NO_MORE_TYPES)
        break;

    hr = mediaType->GetGUID(MF_MT_SUBTYPE, &subtype);
    hr = MFGetAttributeSize(mediaType, MF_MT_FRAME_SIZE, &width, &height);
    hr = MFGetAttributeRatio(mediaType, MF_MT_FRAME_RATE, &frameRate, &denominator);
    hr = MFGetAttributeRatio(mediaType, MF_MT_FRAME_RATE_RANGE_MIN, &frameRateMin, &denominator);
    hr = MFGetAttributeRatio(mediaType, MF_MT_FRAME_RATE_RANGE_MAX, &frameRateMax, &denominator);
    ++index;
}

The frame rate is expressed as a ratio. The upper 32 bits of the attribute value contain the numerator and the lower 32 bits contain the denominator. For example, if the frame rate is 30 frames per second (fps), the ratio is 30/1. If the frame rate is 29.97 fps, the ratio is 30,000/1001.

Generally, denominator will be 1 (I have not seen it be anything else). And with the various webcams I have tested, frameRate, frameRateMin, and frameRateMax are the same number. The results will look nearly identical to what you listed above.

Edit:

For example, the following is the output of the code above (minus the printf) to a console output of the native formats that are supported for a Logitech Webcam Pro 9000:

This older webcam has 46 native formats, whereas newer webcams have many more (the C930e has 216). Here are the first 81 native formats of the C930e:

Sometimes a webcam will have very high numbers, which generally means that frames will not be throttled, and are delivered as quickly as possible, which is dependent on shutter speed, resolution, etc (I max this number to 99 for readability).

I think you are getting hung up on the following quote:

The device might support other frame rates within this range

However that is if the min and max do not equal the frame rate, and I have not seen webcams which vary in these numbers. Keep in mind that this can be used with any capture device. A 4 lane PCIe capture card has the bandwidth to keep up with almost whatever you want, so they would choose to write the driver accordingly (few formats with a large variance between min and max).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!