DirectShow采集到的视频无法播放
DirectShow采集到的视频无法播放
关键看视频开始采集的代码就OK了。
//采集相关的变量 IGraphBuilder *pGraph; ICaptureGraphBuilder2 *pBuild; //视频采集过滤器图表IMediaControl *m_pMediaControl; //视频采集设备的源Filter IBaseFilter* pSrc;//---------------------------------//HRESULT hr; //创建IGraphBuilder CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void **)&pGraph); //创建ICaptureGraphBuilder2 hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void**)&pBuild); // 过滤器图表添加到管理器中 pBuild->SetFiltergraph(pGraph); //--------------------------------------------////以下代码为查找设备 ICreateDevEnum *pDevEnum=NULL; IEnumMoniker *pClsEnum=NULL; //创建设备枚举COM对象 CoCreateInstance(CLSID_SystemDeviceEnum,NULL,CLSCTX_INPROC,IID_ICreateDevEnum,(void **)&pDevEnum); //创建视频采集设备枚举COM对象 pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,&pClsEnum,0); if(pClsEnum == NULL) { MessageBox(_T("Sorry, you have no video capture hardware.\r\n\r\nVideo capture will not function properly.")); //如果没有设备,返回 return ; } IMoniker *pMoniker = NULL; //如果先前的createclassenumerator调用成功了,可以用ienummoniker::next得到设备 if(pClsEnum->Next(1,&pMoniker,NULL)==S_OK) { //调用imoniker::bindtoobject建立一个和选择的device联合的filter pMoniker->BindToObject(0,0,IID_IBaseFilter,(void **)&pSrc); pMoniker->Release(); } //将设备添加到管理器graph hr = pGraph->AddFilter(pSrc, L"Video Capture");//---------------------------------------//视频开始采集----------------------------//IFileSinkFilter* fsFilter=NULL; IBaseFilter* vedioWriter=NULL; //设置保存文件并初始化vedioWriter hr=pBuild->SetOutputFileName(&MEDIASUBTYPE_Avi,L"D:\\A.avi",&vedioWriter,&fsFilter); //保存文件 hr=pBuild->RenderStream(&PIN_CATEGORY_CAPTURE,&MEDIATYPE_Video,pSrc,NULL,vedioWriter); IMediaControl *pMC = NULL; hr=pGraph->QueryInterface(IID_IMediaControl, (void **)&pMC); hr=pMC->Run(); //运行Filter Graph if(FAILED(hr)) { MessageBox(_T("加载运行失败!")); return ; }