directshow烦人问题

xbingle 2009-11-10 09:48:52
我是新手,上网找了很多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;
}

我上网查了好久,没想明白,请大家帮帮忙
...全文
91 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
kyouya 2009-11-10
  • 打赏
  • 举报
回复
我用sample grabber是一个一个连得,没用renderstream,但是run()失败了,坐等高手

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧