DirectShow中怎样修改捕获视频的格式
2011-03-16 20:27
330 查看
项目用到DirectShow来捕获一帧一帧的画像用来做后续的处理,譬如画像认识等。
其中想获取不同格式和不同大小的图像作处理,下面就说说在DirectShow中怎样修改捕获的视频格式。
在DirectSDK的下面目录里 DXSDK/Samples/C++/DirectShow/Capture/AMCap找到这样一段代码:
//可以设置输出视频的格式
IAMStreamConfig *pSC;
hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Interleaved, gcap.pVCap,
IID_IAMStreamConfig, (void **)&pSC);
if(hr != NOERROR)
hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video, gcap.pVCap,
IID_IAMStreamConfig, (void **)&pSC);
ISpecifyPropertyPages *pSpec;
CAUUID cauuid;
hr = pSC->QueryInterface(IID_ISpecifyPropertyPages,(void **)&pSpec);
if(hr == S_OK)
{
hr = pSpec->GetPages(&cauuid);
hr = OleCreatePropertyFrame(ghwndApp, 30, 30, NULL, 1,
(IUnknown **)&pSC, cauuid.cElems,
(GUID *)cauuid.pElems, 0, 0, NULL);
// !!! What if changing output formats couldn't reconnect
// and the graph is broken? Shouldn't be possible...
if(gcap.pVSC)
{
AM_MEDIA_TYPE *pmt;
// get format being used NOW
hr = gcap.pVSC->GetFormat(&pmt);
// DV capture does not use a VIDEOINFOHEADER
if(hr == NOERROR)
{
if(pmt->formattype == FORMAT_VideoInfo)
{
// resize our window to the new capture size
DeleteMediaType(pmt);
}
}
CoTaskMemFree(cauuid.pElems);
pSpec->Release();
}
pSC->Release();
上面的代码先把IBaseFilter的输出IPin的信息和IAMStreamConfig关联起来,然后通过OleCreatePropertyFrame来生成输出IPin的属性页,通过修改这些属性,从而达到修改捕获的视频格式。
需要注意的是在执行上述代码之前,要确保所有的Filter没有连接,并且Filter没有加入到IGraphBuilder中,否则在属性页中会告诉你不支持之类的信息。
在DirectX的文档中还提到的另外一种方法来修改:
首先把IBaseFilter的属性读到IAMStreamConfig中。
IAMStreamConfig *pConfig = NULL;
hr = pBuild->FindInterface(
&PIN_CATEGORY_PREVIEW, // Preview pin.
0, // Any media type.
pCap, // Pointer to the capture filter.
IID_IAMStreamConfig, (void**)&pConfig);
遍历输出IPin中的所有AM_MEDIA_TYPE类型。
int iCount = 0, iSize = 0;
hr = pConfig->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;
AM_MEDIA_TYPE *pmtConfig;
hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc);
if (SUCCEEDED(hr))
{
/* Examine the format, and possibly use it. */
// Delete the media type when you are done.
DeleteMediaType(pmtConfig);
}
}
在众多支持的AM_MEDIA_TYPE中挑选一种合适的,设置。
if ((pmtConfig.majortype == MEDIATYPE_Video) &
(pmtConfig.subtype == MEDIASUBTYPE_RGB24) &
(pmtConfig.formattype == FORMAT_VideoInfo) &
(pmtConfig.cbFormat >= sizeof (VIDEOINFOHEADER)) &
(pmtConfig.pbFormat != NULL))
{
VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig.pbFormat;
// pVih contains the detailed format information.
LONG lWidth = pVih->bmiHeader.biWidth;
LONG lHeight = pVih->bmiHeader.biHeight;
}
在第二种方法中同样需要注意前面方法中所提到的需要注意的地方。
希望对大家有用。
其中想获取不同格式和不同大小的图像作处理,下面就说说在DirectShow中怎样修改捕获的视频格式。
在DirectSDK的下面目录里 DXSDK/Samples/C++/DirectShow/Capture/AMCap找到这样一段代码:
//可以设置输出视频的格式
IAMStreamConfig *pSC;
hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Interleaved, gcap.pVCap,
IID_IAMStreamConfig, (void **)&pSC);
if(hr != NOERROR)
hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video, gcap.pVCap,
IID_IAMStreamConfig, (void **)&pSC);
ISpecifyPropertyPages *pSpec;
CAUUID cauuid;
hr = pSC->QueryInterface(IID_ISpecifyPropertyPages,(void **)&pSpec);
if(hr == S_OK)
{
hr = pSpec->GetPages(&cauuid);
hr = OleCreatePropertyFrame(ghwndApp, 30, 30, NULL, 1,
(IUnknown **)&pSC, cauuid.cElems,
(GUID *)cauuid.pElems, 0, 0, NULL);
// !!! What if changing output formats couldn't reconnect
// and the graph is broken? Shouldn't be possible...
if(gcap.pVSC)
{
AM_MEDIA_TYPE *pmt;
// get format being used NOW
hr = gcap.pVSC->GetFormat(&pmt);
// DV capture does not use a VIDEOINFOHEADER
if(hr == NOERROR)
{
if(pmt->formattype == FORMAT_VideoInfo)
{
// resize our window to the new capture size
DeleteMediaType(pmt);
}
}
CoTaskMemFree(cauuid.pElems);
pSpec->Release();
}
pSC->Release();
上面的代码先把IBaseFilter的输出IPin的信息和IAMStreamConfig关联起来,然后通过OleCreatePropertyFrame来生成输出IPin的属性页,通过修改这些属性,从而达到修改捕获的视频格式。
需要注意的是在执行上述代码之前,要确保所有的Filter没有连接,并且Filter没有加入到IGraphBuilder中,否则在属性页中会告诉你不支持之类的信息。
在DirectX的文档中还提到的另外一种方法来修改:
首先把IBaseFilter的属性读到IAMStreamConfig中。
IAMStreamConfig *pConfig = NULL;
hr = pBuild->FindInterface(
&PIN_CATEGORY_PREVIEW, // Preview pin.
0, // Any media type.
pCap, // Pointer to the capture filter.
IID_IAMStreamConfig, (void**)&pConfig);
遍历输出IPin中的所有AM_MEDIA_TYPE类型。
int iCount = 0, iSize = 0;
hr = pConfig->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;
AM_MEDIA_TYPE *pmtConfig;
hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc);
if (SUCCEEDED(hr))
{
/* Examine the format, and possibly use it. */
// Delete the media type when you are done.
DeleteMediaType(pmtConfig);
}
}
在众多支持的AM_MEDIA_TYPE中挑选一种合适的,设置。
if ((pmtConfig.majortype == MEDIATYPE_Video) &
(pmtConfig.subtype == MEDIASUBTYPE_RGB24) &
(pmtConfig.formattype == FORMAT_VideoInfo) &
(pmtConfig.cbFormat >= sizeof (VIDEOINFOHEADER)) &
(pmtConfig.pbFormat != NULL))
{
VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig.pbFormat;
// pVih contains the detailed format information.
LONG lWidth = pVih->bmiHeader.biWidth;
LONG lHeight = pVih->bmiHeader.biHeight;
}
在第二种方法中同样需要注意前面方法中所提到的需要注意的地方。
希望对大家有用。
相关文章推荐
- DirectShow中怎样修改捕获视频的格式
- DirectShow中怎样修改捕获视…
- directshow 自带的视频捕获的例子
- 基于Directshow的USB视频捕获Delphi篇(一)
- Mac OS使用技巧之四:修改打开不同格式视频的默认播放器
- Directshow(SDK)学习笔记九_视频捕获
- 基于DirectShow视频及图片捕获软件的开发
- word2010中怎样快速修改同级标题格式
- 与众不同 windows phone (22) - Device(设备)之摄像头(硬件快门, 自动对焦, 实时修改捕获视频)
- PDF格式文件怎样编辑修改
- 完整的DirectShow捕获音视频的demo(源码)
- 在ubuntu怎样修改默认的编码格式
- asp.net中gridview导出excel方法以及怎样修改导出的日期格式
- CCapture directshow 视频捕获类
- 基于Directshow的USB视频捕获Delphi篇(二)
- 修改捕获图像的大小 directshow
- DM368学习--捕获视频图像分辨率修改
- C#使用DirectShow捕获视频
- 完整的DirectShow捕获音视频的demo(源码)
- 怎样改变DirectShow中采集的视频大小.