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

前端 未结 1 1933
逝去的感伤
逝去的感伤 2021-01-06 09:20

I want to get a list of all FPS values that my webcam supports.

In How to Set the Video Capture Frame Rate msdn article it says that I can query the system for maxim

1条回答
  •  没有蜡笔的小新
    2021-01-06 09:58

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

    Microsoft::WRL::ComPtr reader = nullptr;
    /* reader code omitted */
    
    IMFMediaType* mediaType = nullptr;
    GUID          subtype { 0 };
    
    UINT32 frameRate    = 0u;
    UINT32 frameRateMin = 0u;
    UINT32 frameRateMax = 0u;
    UINT32 denominator  = 0u;
    
    DWORD index         = 0u;
    DWORD width         = 0u;
    DWORD height        = 0u;
    
    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;
    
        // Error checking omitted for brevity
        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:

    enter image description here

    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:

    enter image description here

    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).

    0 讨论(0)
提交回复
热议问题