0

我用 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();
4

0 回答 0