防止在DirectShow中捕获视频的丢帧

时间:2013-09-01 09:08:32

标签: c# directshow video-capture directshow.net

我在C#(和DirectShow.net)中编写了一个相对简单的代码,以便将摄像机中的视频捕获到文件中。我的问题是图表在录制时丢失了太多帧。我不认为这个问题与硬件有关,因为它不是一个非常苛刻的视频(640x480,25fps),而且我有一台相当强大的电脑。 有关防止帧丢弃的最佳做法的任何想法?

修改

这是我的代码:

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

0 个答案:

没有答案
相关问题