无法从采集卡获取实时视频

时间:2014-01-20 07:11:39

标签: c# directshow

object vdeosource;
DsDevice device1 = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice)[1];
Guid baseIdentifier = typeof(IBaseFilter).GUID;
device1.Mon.BindToObject(null, null, ref baseIdentifier, out vdeosource);
IBaseFilter sourceFilter = vdeosource as IBaseFilter;
graphBuilder.AddFilter(sourceFilter, "Source");

hr = captureGraphBuilder.SetFiltergraph(this.graphBuilder);
DsError.ThrowExceptionForHR(hr);

mpeg2Demux = (IBaseFilter)new MPEG2Demultiplexer();

object cross;
captureGraphBuilder.FindInterface(FindDirection.UpstreamOnly, null, sourceFilter, typeof(IAMCrossbar).GUID, out cross);
IAMCrossbar crossbar2 = cross as IAMCrossbar;
int inputpincount, outputpincount;
crossbar2.get_PinCounts(out outputpincount, out inputpincount);
crossbar2.Route(0, 0);

如果我此时尝试渲染视频,我会从播放的视频中获得约5秒的延迟图片,该视频作为我的采集卡的输入连接。我的采集卡输出是mpeg2。

IBaseFilter demuxFilter = (IBaseFilter)new MPEG2Demultiplexer();
graphBuilder.AddFilter(demuxFilter, "Mpeg-2 Demultiplexor");

IPin sourceFilterOutputPin = DsFindPin.ByDirection(sourceFilter, PinDirection.Output, 0);
IPin demuxFilterPinIn = DsFindPin.ByDirection(demuxFilter, PinDirection.Input, 0);

hr = graphBuilder.Connect(sourceFilterOutputPin, demuxFilterPinIn);
DsError.ThrowExceptionForHR(hr);

IBaseFilter defaultRenderer = (IBaseFilter)new VideoRendererDefault();
hr = graphBuilder.AddFilter(defaultRenderer, "Default Renderer");
DsError.ThrowExceptionForHR(hr);

hr = captureGraphBuilder.RenderStream(null, MediaType.Video, sourceFilter, null, defaultRenderer);
DsError.ThrowExceptionForHR(hr);

此时我收到错误消息,表示没有中间过滤器的组合...... 我想知道的是我是否使用mpeg2 demux是对还是错?

1 个答案:

答案 0 :(得分:1)

在呈现流之前,您不需要将源连接到demux。这可能会使渲染操作混乱。

在渲染操作期间,DirectShow会尝试使用图表中已存在的过滤器,然后再尝试其他已注册的过滤器,这样您就可以将首选过滤器添加到图表中而无需连接它们。

您可能还缺少适当的mpeg2解码或色彩空间转换过滤器。您是否使用图形编辑工具(例如Windows SDK中的Graph Studio Next或GraphEdit)模拟了这些工具?