本人刚刚接触Directshow不久,现在遇到了问题。在遍历完设备后,尝试用setformat改变视频格式,将formattype中的VIDEOINFOHEADER改为VIDEOINFOHEADER2,来进行逐行隔行的识别。现在提示hr=pISC->setformat(pmt)为EFAIL,不知道到底哪里有问题,恳请各位大牛指点。以下是相关的代码:
// locate the video capture pin and QI for stream control
CComPtr pISC = NULL;
hr = CDSUtils::FindPinInterface(m_pVideoCapture, &MEDIATYPE_Video, PINDIR_OUTPUT, IID_IAMStreamConfig, reinterpret_cast(&pISC));
if (SUCCEEDED(hr))
{
// loop through all the capabilities (video formats) and populate the control
int count, size;
hr = pISC->GetNumberOfCapabilities(&count, &size);//media type counts, the space of the typedef need.
if (SUCCEEDED(hr))
{
if (sizeof(VIDEO_STREAM_CONFIG_CAPS) == size)
{
AM_MEDIA_TYPE* pmt = NULL;
hr = pISC->GetFormat(&pmt);
if (FAILED(hr))
{
return FALSE;
}
if(SUCCEEDED(hr))
{
VIDEO_STREAM_CONFIG_CAPS vscc;
VIDEOINFOHEADER2* pvih = NULL;
for (int index=0; index<count; ++index)
{
hr = pISC->GetStreamCaps(index, &pmt, reinterpret_cast<BYTE*>(&vscc));
if (SUCCEEDED(hr))
{
TCHAR buffer[128];
float frameRate;
char* pixelFormatString;
ZeroMemory(buffer, sizeof(buffer));
if((pmt->formattype==FORMAT_VideoInfo)&&(pmt->cbFormat>=sizeof(VIDEOINFOHEADER))&&(pmt->pbFormat!=NULL))
{
pmt->formattype = FORMAT_VideoInfo2;
hr = pISC->SetFormat(pmt);
}
if(FAILED(hr))
{
FreeMediaType(*pmt);
}
if(SUCCEEDED(hr))
{
//成功后继续相关操作
}
...
}