directshow实现了视频采集,怎样保存?
directshow实现了视频采集,怎样把采集的视频保存起来?
贴代码,关键看[视频开始采集]的代码就OK了。
[color=#FF0000] //采集相关的变量[/color] IGraphBuilder *pGraph; ICaptureGraphBuilder2 *pBuild; //视频采集过滤器图表 IMediaControl *m_pMediaControl; //视频采集设备的源Filter IBaseFilter* pSrc;[color=#FF0000]//---------------------------------//[/color]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); pGraph->QueryInterface(IID_IVideoWindow, (void **)&m_pVidWin);[color=#FF0000]//--------------------------------------------////以下代码为查找设备[/color] 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");[color=#FF0000]//---------------------------------------//视频开始采集----------------------------//[/color] //连接一个源插口,将Filter添加到过滤器图表中 hr=pBuild->RenderStream(&PIN_CATEGORY_CAPTURE,&MEDIATYPE_Video,pSrc,NULL,NULL); //设定视频窗口为主窗口的一个子窗口 m_pVidWin->put_Owner((OAHWND)m_hWnd); m_pVidWin->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); CRect rc; GetDlgItem(IDC_VW_FRAME)->GetWindowRect(rc); ScreenToClient(rc); //设定视频窗口 m_pVidWin->SetWindowPosition(rc.left, rc.top, rc.Width(), rc.Height()); hr=pGraph->QueryInterface(IID_IMediaControl, (void **)&m_pMediaControl); hr=m_pMediaControl->Run(); //运行Filter Graph if(FAILED(hr)) { MessageBox(_T("加载运行失败!")); return ; }