如果我使用智能T恤过滤器,如何将视频流从网络摄像头渲染到文件? 所以我添加SmartTee过滤器并获得类似的东西:
Capture filter
|
SmartTee filter
| |
capture preview
| |
Mux filter GrabFilter
| |
FileWriter VideoRenderer
这样的连接捕获过滤器和智能T恤:
// 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文件而没有别的。哪里是我的错?
答案 0 :(得分:1)
顶部的拓扑结构是正确的。
但您的代码与之不符:您连接多路复用器输入,然后连接Run
。没有代码存在或显示连接多路复用器输出,这是必需的。
接下来是您的实际拓扑结构可能与预期不同,因为智能连接会自动提供过滤器,您还需要通过枚举过滤器或publishing to ROT and viewing with external tool来查看此内容。
如果您有机会查看真正的拓扑,您可能会立即解决问题:
IPin sourcePin, grabPin;
sourcePin = GetPin(PinDirection.Output, smartTeeFilter);
grabPin = GetPin(PinDirection.Input, baseGrabFilter);
graph.Connect(sourcePin, grabPin);
您正在将第一个抓取的输出引脚连接到Sample Grabber并预览视频渲染器。但是,index zero output pin is Capture:
捕获引脚是输出引脚0,预览引脚是输出引脚1.
因此,您正在将预览(永恒)媒体样本写入文件,它无法正常工作,因此您需要正确连接T形输出引脚 - 以便tee的捕获输出连接到多路复用/写入器支路。