0
 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 );

I am capturing from my webcam. I putted some texts to captured video and at the end, I want to save it to a file. how can I do that? My project is built on DxText sample. If I use samplegrabber, I cannot use capturegraph and vice versa. Can anyone help me?

dovid
  • 6,354
  • 3
  • 33
  • 73
Vahid K.
  • 440
  • 4
  • 14

1 Answers1

0

If you want to use a SampleGrabber to grab the frames and then write to an avi file, you need a codec and a library to write avi files. You will probably have to search a library or sdk yourself.

However I would recommend not to use a SampleGrabber, but use a Tee filter instead. To the second output of the tee connect an encoder, and avi file writer.

wimh
  • 15,072
  • 6
  • 47
  • 98
  • Thanks, You mean I capture video from my webcam, and then put some texts on it, and afterwards, I use an encoder and avi file writer? Am I right? – Vahid K. Jan 13 '14 at 19:18
  • I did not understand you wanted to put some text on it. But yes, that is possible too, then you have to keep the SampleGrabber and put the Tee after it. See also the DXLogo sample. – wimh Jan 13 '14 at 21:12