I've written a relatively straightforward code in C# (and DirectShow.net) in order to capture video from a camera into a file. My problem is that the graph is dropping too many frames while recording. I don't think that the problem is hardware related, as it is not a very demanding video (640x480 at 25fps), and I have a fairly strong computer. Any thoughts on best practices to prevent frame drops?
EDIT:
Here is my code:
Graph = (IGraphBuilder)new FilterGraph();
Source = CreateFilter(FilterCategory.VideoInputDevice, SelectedDevice);
hr = Graph.AddFilter(Source, "Source");
TestForError("Error while adding source filter", hr);
Builder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
hr = Builder.SetFiltergraph(Graph);
TestForError("Error setting preview graph", hr);
Guid guid = DirectShowLib.MediaSubType.Avi;
hr = Builder.SetOutputFileName(guid, filename, out AVIMux, out FileWriter);
TestForError("Error setting capture graph", hr);
// Set VMR
VMR = (IBaseFilter)new VideoMixingRenderer9();
hr = Graph.AddFilter(VMR, "Renderer");
TestForError("Error creating preview subgraph", hr);
ConfigureWindowlessMode();
// Render Capture & Preview streams
hr = Builder.RenderStream(PinCategory.Preview, MediaType.Video, Source, null, VMR);
TestForError("Preview stream rendering error", hr);
hr = Builder.RenderStream(PinCategory.Capture, MediaType.Video, Source, null, AVIMux);
TestForError("Capture stream rendering error", hr);
//
Control = (IMediaControl)Graph;
mediaEventEx = (IMediaEventEx)Graph;
hr = mediaEventEx.SetNotifyWindow(Handle, WM_GRAPHNOTIFY, IntPtr.Zero);
TestForError("Error setting notifications", hr);
Control.Run();