0

How to get the current resolution of SamleGrabber in DirectShow?

I tried the below code, it doesn't work. The value you get is always 1920x1080, while the source resolution changed from 1920x1080 to 1680x1050.

void GetCurrentResolution(ISampleGrabber* pGrabber, int* pWidth, int* pHeight) 
{
    AM_MEDIA_TYPE pmt = {0};
    hr = pGrabber->GetConnectedMediaType(&pmt);
    if (SUCCEEDED(hr)) 
    {
        if(pmt.formattype == FORMAT_VideoInfo) 
        {
            VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmt.pbFormat;
            *pWidth = pVih->bmiHeader.biWidth;
            *pHeight = pVih->bmiHeader.biHeight;
        }
        FreeMediaType(pmt);
    }
}
4

2 回答 2

4

您提供的代码片段是正确的。它是不准确的,因为它假设事情不必发生,但在大多数情况下它会起作用。

您的错误假设是分辨率可能会在运行图上发生变化。不,它不会发生:Sample Grabber 在引脚上的媒体类型一旦连接就不会改变。如果需要重新同意解决方案,您需要从重新连接引脚开始,通常从上游引脚开始。

于 2013-05-24T09:31:04.723 回答
0

尝试这个:

当分辨率改变时:调用 pGraph->Stop(); 然后重新获取并调用 pGraph->Run()

于 2013-05-24T07:48:26.563 回答