Media Foundation 使用 PROPVARIANT 结构设置视频捕获帧率

Media Foundation set video capture frame rate using PROPVARIANT structure

我正在编写一个媒体基础应用程序,我需要在其中设置视频设备的捕获帧速率。我写的函数是这样的:

bool SetRequestedFrameRate(const size_t requestedFramesPerSecond);

我在这里传递了一个用户定义的整数作为帧速率参数。我正在关注 https://msdn.microsoft.com/en-us/library/windows/desktop/ff485859(v=vs.85).aspx 上的代码片段:

PROPVARIANT var;
if (SUCCEEDED(pType->GetItem(MF_MT_FRAME_RATE_RANGE_MAX, &var)))
{
    hr = pType->SetItem(MF_MT_FRAME_RATE, var);

    PropVariantClear(&var);

    if (FAILED(hr))
    {
        goto done;
    }

    hr = pHandler->SetCurrentMediaType(pType);
}

显然它使用 PROVARIANT 结构来保存帧速率数据。但是如何从我的 "const size_t requestedFramesPerSecond" 参数构造一个 PROVARIANT 结构呢?如果我已经有一个保存帧速率的 PROVARIANT,我如何从中检索实际帧速率整数?另外,COM 是否提供了一种方法来比较表示帧速率的两个 PROVARIANT 结构?

请帮忙,谢谢!

MF_MT_FRAME_RATE attribute是一对32位整数,分别代表分子和分母。 MFSetAttributeRatio 和朋友以友好的方式帮助 set/get 价值观。使用 PROVARIANT 您应该将其作为 64 位 UINT64 值处理。

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.

正如 Roman 指出的那样,您可以避免与 PROPVARIANT structure, by using the utility functions to access the IMFAttributes 商店打交道。然而, 正如 #7 在 page you referenced:

上指出的那样
  1. Query the media type for the MF_MT_FRAME_RATE_RANGE_MAX and MF_MT_FRAME_RATE_RANGE_MIN attributes. This values give the range of supported frame rates. The device might support other frame rates within this range.

枚举捕获设备的本机媒体类型,并简单地select(选择一个)并将媒体类型重用到set the current media type. Otherwise you will be frustrated with failed calls which do not match the capabilities of the capture device. I discuss frame rates a bit and show how to enumerate the native media type 。祝你好运。