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 );我把一些文本放到捕获的视频中,最后,我想把它保存到一个文件中。我该怎么做呢?如果我使用samplegrabber,我就不能使用capturegraph,反之亦然。有谁可以帮我?
发布于 2014-01-12 23:51:20
如果您想使用SampleGrabber来抓取帧,然后写入avi文件,则需要一个编解码器和一个库来写入avi文件。您可能需要自己搜索库或sdk。
然而,我建议不要使用SampleGrabber,而是使用T型过滤器。到第二个输出的三通连接编码器,和avi文件的写入器。
https://stackoverflow.com/questions/21073034
复制相似问题