sampGrabber = new SampleGrabber() as ISampleGrabber;
capGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out capFilter);
DsError.ThrowExceptionForHR(hr);
// Hopefully this will be the video pin
IPin iPinOutSource = DsFindPin.ByDirection(capFilter, PinDirection.Output, 0);
IBaseFilter baseGrabFlt = sampGrabber as IBaseFilter;
ConfigureSampleGrabber(sampGrabber);
iPinInFilter = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Input, 0);
iPinOutFilter = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Output, 0);
// Add the frame grabber to the graph
hr = m_FilterGraph.AddFilter( baseGrabFlt, "Ds.NET Grabber" );
DsError.ThrowExceptionForHR( hr );
hr = m_FilterGraph.Connect(iPinOutSource, iPinInFilter);
DsError.ThrowExceptionForHR( hr );
// Get the default video renderer
ibfRenderer = (IBaseFilter) new VideoRendererDefault();
// Add it to the graph
hr = m_FilterGraph.AddFilter( ibfRenderer, "Ds.NET VideoRendererDefault" );
DsError.ThrowExceptionForHR( hr );
iPinInDest = DsFindPin.ByDirection(ibfRenderer, PinDirection.Input, 0);
// Connect the graph. Many other filters automatically get added here
hr = m_FilterGraph.Connect(iPinOutFilter, iPinInDest);
DsError.ThrowExceptionForHR( hr );
SaveSizeInfo(sampGrabber);
// Set the output window
IVideoWindow videoWindow = m_FilterGraph as IVideoWindow;
hr = videoWindow.put_Owner( hWin.Handle );
DsError.ThrowExceptionForHR( hr );
hr = videoWindow.put_WindowStyle( WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings );
DsError.ThrowExceptionForHR( hr );
hr = videoWindow.put_Visible( OABool.True );
DsError.ThrowExceptionForHR( hr );
Rectangle rc = hWin.ClientRectangle;
hr = videoWindow.SetWindowPosition( 0, 0, rc.Right, rc.Bottom );
DsError.ThrowExceptionForHR( hr );
我正在从我的网络摄像头捕捉。我把一些文本放到捕获的视频中,最后,我想把它保存到文件中。我怎样才能做到这一点? 我的项目是基于DxText示例构建的。 如果我使用samplegrabber,我不能使用capturegraph,反之亦然。任何人都可以帮助我吗?
答案 0 :(得分:0)
如果您想使用SampleGrabber来抓取帧然后写入avi文件,则需要编解码器和库来编写avi文件。您可能需要自己搜索一个库或sdk。
但是我建议不要使用SampleGrabber,而是使用Tee过滤器。到三通的第二个输出连接编码器和avi文件写入器。