windows+mobile++摄像头捕捉+例子+directshow

//创建graph图表
 IGraphBuilder *pFilterGraph;
    ICaptureGraphBuilder2  *pCaptureGraphBuilder;
    HRESULT hr = CoCreateInstance(CLSID_FilterGraph,0,CLSCTX_INPROC,IID_IGraphBuilder,(void**)&pFilterGraph);
 hr = CoCreateInstance(CLSID_CaptureGraphBuilder,0,CLSCTX_INPROC,IID_ICaptureGraphBuilder2,(void**)&pCaptureGraphBuilder);
 pCaptureGraphBuilder->SetFiltergraph(pFilterGraph);

 //创建捕捉filter
 IBaseFilter *pVideoCaptureFilter;
 hr = CoCreateInstance(CLSID_VideoCapture,0,CLSCTX_INPROC,IID_IBaseFilter,(void**)&pVideoCaptureFilter);
 IPersistPropertyBag *pPropertyBag;
 pVideoCaptureFilter->QueryInterface(&pPropertyBag);
 DEVMGR_DEVICE_INFORMATION devInfo;
    CComVariant CamName;
 IPropertyBag  *propbag;    //这里 别人说是 CPropertyBag 去实现IPropertyBag
 GUID guidCamera = {};    //这里是camera 注册在系统里的GUID值
    devInfo.dwSize = sizeof(devInfo);
 //查找camera device
 FindFirstDevice(DeviceSearchByGuid,&guidCamera,&devInfo);
 CamName = devInfo.szLegacyName;
 propbag->Write(L"VcapName",&CamName);
 pPropertyBag->Load(propbag,NULL);
 //添加捕捉filter
 pFilterGraph->AddFilter(pVideoCaptureFilter,L"MyCapture");

    pPropertyBag->Release();
    propbag->Release();
   
    //创建解码filter
 IBaseFilter *pVideoEncode;
 IDMOWrapperFilter *pWrapperFilter;      //接口 
 hr = CoCreateInstance(CLSID_DMOWrapperFilter,0,CLSCTX_INPROC,IID_IBaseFilter,(void**)&pVideoEncode);
 pVideoEncode->QueryInterface(&pWrapperFilter);
 pWrapperFilter->Init(CLSID_CWMV9EncMediaObject,DMOCATEGORY_VIDEO_ENCODER);
    //添加解码filter
 pFilterGraph->AddFilter(pVideoEncode,L"video encode");

 //建立asf流生成filter和file write filter
 IBaseFilter *pAsfMultiplexer;
 IFileSinkFilter *pFileSinkFilter;  //接口
 pCaptureGraphBuilder->SetOutputFileName(&MEDIASUBTYPE_Asf,L"C:\\test.asf",&pAsfMultiplexer,&pFileSinkFilter);

    //连接所有的filter
 pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_CAPTURE,&MEDIATYPE_Video,pVideoCaptureFilter,pVideoEncode,pAsfMultiplexer);

 //启动Graph
 IMediaControl *pMC;
 pFilterGraph->QueryInterface(IID_IMediaControl,(void**)&pMC);
 pMC->Run();

 

 

MSDN

ICaptureGraphBuilder2::RenderStream         

HRESULT RenderStream(  const GUID*  pCategory,  const GUID*  pType,  IUnknown*    pSource,  IBaseFilter* pIntermediate,  IBaseFilter* pSink);

pCategory

[in] A pointer to a pin category from the AMPROPERTY_PIN_CATEGORY property set (seePin Property Set). Use NULL to match any category. The following list shows typical categories.

  •               PIN_CATEGORY_CAPTURE     //捕捉
  •               PIN_CATEGORY_PREVIEW     //预览
  •               PIN_CATEGORY_CC
pType

[in] Pointer to a major-type GUID that specifies the media type of the output pin; or NULL to use any pin, regardless of media type. For a list of possible values, seeMedia Types and Sub Types.

pSource

[in] Specifies a pointer to the starting filter for the connection, or to an output pin.

pIntermediate

[in] Pointer to the IBaseFilter Interface of an intermediate filter, such as a compression filter. Can be NULL.

pSink

[in] Pointer to the IBaseFilter interface of a sink filter, such asa renderer or mux filter. If the value is NULL, the method uses a default renderer (see Remarks).

 

想预览的话自己加个videoRender filter  使用Preview Pin 预览画面

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老猿的春天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值