使用samplegrabber和smarttee时出错

时间:2014-01-14 19:12:39

标签: c# directshow

graphBuilder = (IGraphBuilder)new FilterGraph();
//Create the Capture Graph Builder
ICaptureGraphBuilder2 captureGraphBuilder = null;
captureGraphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();

//Create the media control for controlling the graph
mediaControl = (IMediaControl)this.graphBuilder;

// Attach the filter graph to the capture graph
int hr = captureGraphBuilder.SetFiltergraph(this.graphBuilder);
DsError.ThrowExceptionForHR(hr);

//Add the Video input device to the graph
hr = graphBuilder.AddFilter(theDevice, "source filter");
DsError.ThrowExceptionForHR(hr);


//Add the Video compressor filter to the graph
hr = graphBuilder.AddFilter(theCompressor, "compressor filter");
DsError.ThrowExceptionForHR(hr);


//////////// Smart Tee
IBaseFilter smartTeeFilter = (IBaseFilter)new SmartTee();
graphBuilder.AddFilter(smartTeeFilter, "Smart Tee");

IPin outPin = DsFindPin.ByDirection(theDevice, PinDirection.Output, 0);
IPin inPin = DsFindPin.ByDirection(smartTeeFilter, PinDirection.Input, 0);
graphBuilder.Connect(outPin, inPin);



/////
ISampleGrabber sampGrabber = new SampleGrabber() as ISampleGrabber;
IBaseFilter baseGrabFilter = sampGrabber as IBaseFilter;
graphBuilder.AddFilter(baseGrabFilter, "Grabber");


IPin sourcePin, grabPin;
sourcePin = DsFindPin.ByDirection(theDevice, PinDirection.Output, 0);
grabPin = DsFindPin.ByDirection(baseGrabFilter, PinDirection.Input, 0);
graphBuilder.Connect(sourcePin, grabPin);

graphBuilder.Render(DsFindPin.ByDirection(baseGrabFilter, PinDirection.Output, 0));
ConfigureSampleGrabber(sampGrabber);

hr = graphBuilder.AddFilter(baseGrabFilter, "Ds.NET Grabber");
DsError.ThrowExceptionForHR(hr);
        ////

SaveSizeInfo(sampGrabber);

在这里,我收到一个标题为“由于引脚未连接而无法执行操作”的错误。我的问题在哪里?!我正在尝试为捕获的视频添加叠加文本,然后保存它。 任何建议将不胜感激。

hr = captureGraphBuilder.RenderStream(null, null, smartTeeFilter, null, null);
DsError.ThrowExceptionForHR(hr);

2 个答案:

答案 0 :(得分:1)

您的sourcePinoutPin变量具有完全相同的引脚。所以你试图连接一个已连接的引脚。

答案 1 :(得分:0)

像这样连接引脚:

FilterGraphTools.ConnectFilters(graphBuilder, inPin, outPin);