我是新手,上网找了很多directshow资料及源码,目的是为了实现对免驱摄像头的视频图片捕捉,现在遇到问题如下: 在我设置完摄像头的视频格式及分辨率那些东西之后,renderstream,在我的机器上没有丝毫问题,但是程序发部到别人的机器上后,会出错,用AMGetErrorText获取错误,为“参数或多个参数不正确”代码如下,请大家看看:
HRESULT CCaptureTestDlg::Init(int iDeviceID, HWND hWnd)
{
CString sWidth,sHeigth;
int flag=0;
HRESULT hr;
GUID subType;
bPreviewFlag=TRUE; hr = InitCaptureGraphBuilder(); if (FAILED(hr))
{
AfxMessageBox("Failed to get video interfaces!");
return hr;
}
// Bind Device Filter. We know the device because the id was passed in
if(!BindFilter(iDeviceID, &m_pBF))
return S_FALSE; hr = m_pGB->AddFilter(m_pBF, L"Capture Filter"); if( FAILED( hr ) )
{
AfxMessageBox("Fail to AddFilter!");
return hr;
}
// hr = m_pCapture->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, m_pBF, NULL, NULL);
// create a sample grabber hr = m_pGrabber.CoCreateInstance( CLSID_SampleGrabber );
if( !m_pGrabber )
{
AfxMessageBox("Fail to create SampleGrabber, maybe qedit.dll is not registered?");
return hr;
} CComQIPtr < IBaseFilter, &IID_IBaseFilter > pGrabBase( m_pGrabber ); //设置视频格式 AM_MEDIA_TYPE *mt; IAMStreamConfig *m_pVSC = NULL;
m_pCapture->FindInterface(&PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video, m_pBF,
IID_IAMStreamConfig, (void **)&m_pVSC);
m_pVSC->GetFormat(&mt);
int iCount = 0, iSize = 0;
VIDEOINFOHEADER *pVih ;
hr = m_pVSC->GetNumberOfCapabilities(&iCount, &iSize); // Check the size to make sure we pass in the correct structure. if (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS))
{
// Use the video capabilities structure.
for (int iFormat = 0; iFormat < iCount; iFormat++)
{
VIDEO_STREAM_CONFIG_CAPS scc; hr = m_pVSC->GetStreamCaps(iFormat, &mt, (BYTE*)&scc);
if (SUCCEEDED(hr))
{
// /* Examine the format, and possibly use it. */
// Delete the media type when you are done.
if ((mt->majortype == MEDIATYPE_Video) &&
(mt->subtype == MEDIASUBTYPE_RGB24) &&
(mt->formattype == FORMAT_VideoInfo) &&
(mt->cbFormat >= sizeof (VIDEOINFOHEADER)) &&
(mt->pbFormat != NULL))
{
pVih = (VIDEOINFOHEADER*)mt->pbFormat;
flag++;
// pVih contains the detailed format information.
pVih->bmiHeader.biWidth=m_iWidth;
pVih->bmiHeader.biHeight=m_iHength;
pVih->bmiHeader.biSizeImage = DIBSIZE(pVih->bmiHeader);
} hr = m_pVSC->SetFormat(mt);//重新设置视频格式 }
}
}
m_pVSC->Release(); if( FAILED( hr ) )
{
AfxMessageBox("Fail to set media type!");
return hr;
}
hr = m_pGB->AddFilter( pGrabBase, L"Grabber" );
if( FAILED( hr ) )
{
AfxMessageBox("Fail to put sample grabber in graph");
return hr;
}
//m_pCapture->RemoveFilter();
// try to render preview/capture pin
hr = m_pCapture->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,m_pBF,pGrabBase,NULL);
if( FAILED( hr ) )
hr = m_pCapture->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,m_pBF,pGrabBase,NULL); if( FAILED( hr ) )
{
CString err;
char buf[256]={0}; //DWORD ERR;
err.Format("%x",hr);
//ERR=GetLastError();
//err.Format("%x",ERR); AMGetErrorText(hr,buf,256);
AfxMessageBox("Failed to RenderStream\r\nerror code:"+err+"\r\n"+buf);
//AfxMessageBox(buf);
return hr;
} hr = m_pGrabber->GetConnectedMediaType( mt );
if ( FAILED( hr) )
{
AfxMessageBox("Failed to read the connected media type");
return hr;
} FreeMediaType(*mt);
mCB.lHeight=m_iHength;
mCB.lWidth=m_iWidth; hr = m_pGrabber->SetBufferSamples( FALSE );
hr = m_pGrabber->SetOneShot( FALSE );
hr = m_pGrabber->SetCallback( &mCB, 1 );
//设置视频捕捉窗口
m_hWnd = hWnd ;
SetupVideoWindow(); hr = m_pMC->Run();//开始视频捕捉 m_pMC->Release(); if(FAILED(hr))
{
AfxMessageBox("Couldn’t run the graph!");
return hr;
}
return S_OK;
} 我上网查了好久,没想明白,请大家帮帮忙
HRESULT CCaptureTestDlg::Init(int iDeviceID, HWND hWnd)
{
CString sWidth,sHeigth;
int flag=0;
HRESULT hr;
GUID subType;
bPreviewFlag=TRUE; hr = InitCaptureGraphBuilder(); if (FAILED(hr))
{
AfxMessageBox("Failed to get video interfaces!");
return hr;
}
// Bind Device Filter. We know the device because the id was passed in
if(!BindFilter(iDeviceID, &m_pBF))
return S_FALSE; hr = m_pGB->AddFilter(m_pBF, L"Capture Filter"); if( FAILED( hr ) )
{
AfxMessageBox("Fail to AddFilter!");
return hr;
}
// hr = m_pCapture->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, m_pBF, NULL, NULL);
// create a sample grabber hr = m_pGrabber.CoCreateInstance( CLSID_SampleGrabber );
if( !m_pGrabber )
{
AfxMessageBox("Fail to create SampleGrabber, maybe qedit.dll is not registered?");
return hr;
} CComQIPtr < IBaseFilter, &IID_IBaseFilter > pGrabBase( m_pGrabber ); //设置视频格式 AM_MEDIA_TYPE *mt; IAMStreamConfig *m_pVSC = NULL;
m_pCapture->FindInterface(&PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video, m_pBF,
IID_IAMStreamConfig, (void **)&m_pVSC);
m_pVSC->GetFormat(&mt);
int iCount = 0, iSize = 0;
VIDEOINFOHEADER *pVih ;
hr = m_pVSC->GetNumberOfCapabilities(&iCount, &iSize); // Check the size to make sure we pass in the correct structure. if (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS))
{
// Use the video capabilities structure.
for (int iFormat = 0; iFormat < iCount; iFormat++)
{
VIDEO_STREAM_CONFIG_CAPS scc; hr = m_pVSC->GetStreamCaps(iFormat, &mt, (BYTE*)&scc);
if (SUCCEEDED(hr))
{
// /* Examine the format, and possibly use it. */
// Delete the media type when you are done.
if ((mt->majortype == MEDIATYPE_Video) &&
(mt->subtype == MEDIASUBTYPE_RGB24) &&
(mt->formattype == FORMAT_VideoInfo) &&
(mt->cbFormat >= sizeof (VIDEOINFOHEADER)) &&
(mt->pbFormat != NULL))
{
pVih = (VIDEOINFOHEADER*)mt->pbFormat;
flag++;
// pVih contains the detailed format information.
pVih->bmiHeader.biWidth=m_iWidth;
pVih->bmiHeader.biHeight=m_iHength;
pVih->bmiHeader.biSizeImage = DIBSIZE(pVih->bmiHeader);
} hr = m_pVSC->SetFormat(mt);//重新设置视频格式 }
}
}
m_pVSC->Release(); if( FAILED( hr ) )
{
AfxMessageBox("Fail to set media type!");
return hr;
}
hr = m_pGB->AddFilter( pGrabBase, L"Grabber" );
if( FAILED( hr ) )
{
AfxMessageBox("Fail to put sample grabber in graph");
return hr;
}
//m_pCapture->RemoveFilter();
// try to render preview/capture pin
hr = m_pCapture->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,m_pBF,pGrabBase,NULL);
if( FAILED( hr ) )
hr = m_pCapture->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,m_pBF,pGrabBase,NULL); if( FAILED( hr ) )
{
CString err;
char buf[256]={0}; //DWORD ERR;
err.Format("%x",hr);
//ERR=GetLastError();
//err.Format("%x",ERR); AMGetErrorText(hr,buf,256);
AfxMessageBox("Failed to RenderStream\r\nerror code:"+err+"\r\n"+buf);
//AfxMessageBox(buf);
return hr;
} hr = m_pGrabber->GetConnectedMediaType( mt );
if ( FAILED( hr) )
{
AfxMessageBox("Failed to read the connected media type");
return hr;
} FreeMediaType(*mt);
mCB.lHeight=m_iHength;
mCB.lWidth=m_iWidth; hr = m_pGrabber->SetBufferSamples( FALSE );
hr = m_pGrabber->SetOneShot( FALSE );
hr = m_pGrabber->SetCallback( &mCB, 1 );
//设置视频捕捉窗口
m_hWnd = hWnd ;
SetupVideoWindow(); hr = m_pMC->Run();//开始视频捕捉 m_pMC->Release(); if(FAILED(hr))
{
AfxMessageBox("Couldn’t run the graph!");
return hr;
}
return S_OK;
} 我上网查了好久,没想明白,请大家帮帮忙
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货