如果我使用智能三通过滤器,如何将网络摄像头的视频流渲染到文件?所以我添加了 SmartTee 过滤器并得到类似的东西:
Capture filter
|
SmartTee filter
| |
capture preview
| |
Mux filter GrabFilter
| |
FileWriter VideoRenderer
这就是连接捕获过滤器和智能三通:
// Get capture filter
srcFilter = FindCaptureDevice();
// Add Capture filter to our graph.
graph.AddFilter(srcFilter, "Video Capture");
//Add smartTee filter to graph
smartTeeFilter = (IBaseFilter)new SmartTee();
graph.AddFilter(smartTeeFilter, "Smart Tee");
IPin outPin = GetPin(PinDirection.Output, srcFilter);
IPin inPin = GetPin(PinDirection.Input, smartTeeFilter);
graph.Connect(outPin, inPin);
这与抓取器和渲染有关(以防万一):
sampGrabber = new SampleGrabber() as ISampleGrabber;
baseGrabFilter = sampGrabber as IBaseFilter;
graph.AddFilter(baseGrabFilter, "Grabber");
IPin sourcePin, grabPin;
sourcePin = GetPin(PinDirection.Output, smartTeeFilter);
grabPin = GetPin(PinDirection.Input, baseGrabFilter);
graph.Connect(sourcePin, grabPin);
graph.Render(GetPin(PinDirection.Output, baseGrabFilter));
这就是我保存文件部分的全部内容:
IBaseFilter mux;
IFileSinkFilter sink;
capture.SetOutputFileName(
MediaSubType.Avi, // Specifies AVI for the target file.
path, // File name.
out mux, // Receives a pointer to the mux.
out sink); // (Optional) Receives a pointer to the file sink.
sink.SetFileName(path, null);
IPin outPin = DsFindPin.ByDirection(smartTeeFilter, PinDirection.Output, 1);
IPin inPin = GetPin(PinDirection.Input, mux);
graph.Connect(outPin, inPin);
control.Run();
它没有抛出异常。只需创建大小为 64Kb 的文件。我保存到文件代码有什么问题?
添加。我查看了 CapWMV 示例,其中保存是这样的:
IFileSinkFilter sink = null;
IBaseFilter fileWriterFilter = null;
capture = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
capture.SetFiltergraph(graph);
int hr = capture.SetOutputFileName(MediaSubType.Avi, path, out fileWriterFilter, out sink);
DsError.ThrowExceptionForHR(hr);
hr = capture.RenderStream(null, null, smartTeeFilter, null, fileWriterFilter);
DsError.ThrowExceptionForHR(hr);
hr = control.Run();
DsError.ThrowExceptionForHR(hr);
我再次得到 64 Kb 文件,没有别的。我的错在哪里?