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);
}
}