关于如何将摄像头输入转换为已录制好的AVI视频输入
求各位大侠帮我看看 小妹初学 研究多日而不得法 急求解决之道 感激不尽!!!!
我将原来的摄像头捕获滤波器改为m_pGraph-> AddSourceFilter(L "***.avi ",L "Source Filter ", &m_pFileSource)又添加了 m_pGraph-> AddFilter(m_pAviSplit, L "AVI Splitter ")但是调试时总在连接那段报错
原代码如下:
void CCDAppDoc::ConnectGraph()
{
HRESULT hr;
// get output "capture " pin from the device. We use the capture pin
// since not all devices have a preview pin.
IPin *pCapOut = GetOutPin(m_pSrc, 0);
我将上面这行改为 IPin *pFileOut =GetOutPin(m_pFileSource, 0)
下面几行未做改动,
// query the capture output pin to get the stream config filter
pCapOut-> QueryInterface(IID_IAMStreamConfig,(void**)&m_pStreamConfig);
// create a media type to hold the pin media type
AM_MEDIA_TYPE *MediaType = new AM_MEDIA_TYPE();
// get the current media type
m_pStreamConfig-> GetFormat(&MediaType);
编译可以通过,只是在调试时总在上面这行出错,按步调试发现m_pStreamConfig返回值为0x00000000,但是原来从摄像头输入时m_pStreamConfig并不为空,不知道如何改进
// get the video info for this pin
VIDEOINFOHEADER *pvi = (VIDEOINFOHEADER *)MediaType-> pbFormat;
//If video size is larger than 320x240
if(pvi-> bmiHeader.biWidth > 320)
{
// change the size of the video to 320 x 240
pvi-> bmiHeader.biHeight = 240;
pvi-> bmiHeader.biWidth = 320;
}
//Get the final video dimensions
m_VideoWidth = pvi-> bmiHeader.biWidth;
m_VideoHeight = pvi-> bmiHeader.biHeight;
//Re-size the window to fit the input video
int win_width = (2*pvi-> bmiHeader.biWidth + 20);
int win_height = (pvi-> bmiHeader.biHeight + 80);
AfxGetApp()-> m_pMainWnd-> SetWindowPos(NULL,0,0,win_width,win_height,NULL);
// set the media type with these changes
MediaType-> pbFormat = (unsigned char*)pvi;
// set the format
m_pStreamConfig-> SetFormat(MediaType);
// get the input pin from the infinite tee filter
IPin *pInfiniteIn = GetInPin(m_pInfiniteTeeFilter,0);
hr = m_pGraph-> Connect(pCapOut,pInfiniteIn);
上面两行改为IPin *pAviSplitIn = GetInPin(m_pAviSplit,0);
hr = m_pGraph-> Connect(pFileOut,pAviSplitIn);
IPin *pAviSplitOut =GetOutPin(m_pAviSplit, 0);
IPin *pInfiniteIn = GetInPin(m_pInfiniteTeeFilter,0);
hr = m_pGraph-> Connect(pAviSplitOut,pInfiniteIn);
其余代码未做改动
// get the first output pin from the infinite tee filter
IPin * pInfiniteOut1 = GetOutPin(m_pInfiniteTeeFilter,0);
// get the input pin of the color space converter
IPin *pColorSpaceIn = GetInPin(m_pColorSpaceConverter,0);
// connect the first output pin from the infinite tee filter to the Color space converter
hr = m_pGraph-> Connect(pInfiniteOut1,pColorSpaceIn);
// get the output pin from the color space converter
IPin *pColorSpaceOut = GetOutPin(m_pColorSpaceConverter,0);
// get the Input pin for the Change filter
IPin *pChangeIn = GetInPin(m_pCDFilter,0);
// connect the output pin from the color space converter filter to the Change filter
hr = m_pGraph-> Connect(pColorSpaceOut,pChangeIn);
// get the output pin from the CD filter
IPin *pChangeOut = GetOutPin(m_pCDFilter,0);
// get the input pin from the CD renderer filter
IPin *pChangeRender = GetInPin(m_pCDRenderer,0);
// connect the Change filter to the Change renderer
hr = m_pGraph-> Connect(pChangeOut, pChangeRender);
// get the second output from the infinite tee filter
IPin *pInfiniteOut2 = GetOutPin(m_pInfiniteTeeFilter,1);
// get the input to the live video renderer
IPin * pLiveIn = GetInPin(m_pLiveRenderer,0);
// connect the second output of the infinite tee filter to the live renderer
hr = m_pGraph-> Connect(pInfiniteOut2,pLiveIn);
}
[解决办法]
m_pStreamConfig是摄像头capture filter的capture output pin上的接口。capture filter都被你替换掉了,这个接口当然就为空了。
原来这块代码是设置摄像头输出图像大小,现在既然换成了avi文件,这块代码可以删掉了。
[解决办法]
DirectShow下面有个例子,叫compressView,它原来是做格式转换的,你只需把输出的地方换成Render,就可以实现你的要求了。