将相同的过滤器多次添加到 DirectShow Graph
如果不首先解释我要做什么,我遇到的问题有点难以解释,所以我将从这个开始。我正在尝试使用 Directshow 中的 Sample Grabber + Null Renderer 过滤器组合从多个视频流中获取样本。输入源可以是从网络摄像头到视频文件再到 URL 的任何内容。我知道如何对单个输入源执行此操作,获取输入源的 IBaseFilter,然后使用 CoCreateInstance() 获取样本采集器和空渲染器的 IBaseFilter 指针:
HRESULT hr = CoCreateInstance(CLSID_SampleGrabber,
NULL,
CLSCTX_INPROC,
IID_IBaseFilter,
(void **)&sample_grabber_filter);
if(FAILED(hr)) {
printf("(Fatal) Error setting up Sample Grabber.\n");
return hr;
}
hr = CoCreateInstance(CLSID_NullRenderer,
NULL,
CLSCTX_INPROC,
IID_IBaseFilter,
(void **)&null_renderer);
if(FAILED(hr)) {
printf("(Fatal) Error seeting up Null Renderer.\n");
return hr;
}
然后我可以使用 FilterGraph::AddFilter() 函数添加所有 3 个过滤器并使用另一个接口(如 CaptureGraphBuilder2)来渲染流。但是当我想同时从多个源渲染时会发生什么?我可以将所有源过滤器添加到图表中,但是如何使用样本采集器和空渲染器过滤器来完成每个视频流的图表?我可以做这样的事情:
IGraphBuilder *graph_builder;
ICaptureGraphBuilder2 *cap_graph;
IMediaControl *media_control;
// ... set up graph_builder and cap_graph and media_control
cap_graph->AddFilterGraph(graph_builder);
IBaseFilter *new_source;
wchar_t *source_name; // Allocate some memory
while(ScanForSource(&new_source, &source_name)) {
graph_builder->AddFilter(new_source, source_name);
graph_builder->AddFilter(sample_grabber_filter, new_sg_name);
graph_builder->AddFilter(null_renderer, new_nr_name);
cap_graph->RenderStream(&PIN_CATEGORY_PREVIEW,
&MEDIATYPE_Video, new_source, sample_grabber_filter, null_renderer);
}
像上面的实现这样的事情会起作用吗?如果没有,那么还有其他方法可以做到这一点吗?非常感谢任何帮助。谢谢!
the problem I have is a bit difficult to explain without first explaining what I'm trying to do so I will start with that. I'm trying to grab samples from multiple video streams using the Sample Grabber + Null Renderer filter combination in Directshow. The input sources can be anything from a webcam to a video file to a URL. I know how to do this for a single input source, get the IBaseFilter of the input source and then use CoCreateInstance() to get the IBaseFilter pointers for a sample grabber and null renderer :
HRESULT hr = CoCreateInstance(CLSID_SampleGrabber,
NULL,
CLSCTX_INPROC,
IID_IBaseFilter,
(void **)&sample_grabber_filter);
if(FAILED(hr)) {
printf("(Fatal) Error setting up Sample Grabber.\n");
return hr;
}
hr = CoCreateInstance(CLSID_NullRenderer,
NULL,
CLSCTX_INPROC,
IID_IBaseFilter,
(void **)&null_renderer);
if(FAILED(hr)) {
printf("(Fatal) Error seeting up Null Renderer.\n");
return hr;
}
I can then use the FilterGraph::AddFilter() function to add all 3 filters and use another interface like CaptureGraphBuilder2 to render the stream. But what happens when I want to render from multiple sources simultaneously? I can add all the source filters to the graph but what about the Sample Grabber and Null Renderer filters to complete the graph for each video stream? Can I do something like:
IGraphBuilder *graph_builder;
ICaptureGraphBuilder2 *cap_graph;
IMediaControl *media_control;
// ... set up graph_builder and cap_graph and media_control
cap_graph->AddFilterGraph(graph_builder);
IBaseFilter *new_source;
wchar_t *source_name; // Allocate some memory
while(ScanForSource(&new_source, &source_name)) {
graph_builder->AddFilter(new_source, source_name);
graph_builder->AddFilter(sample_grabber_filter, new_sg_name);
graph_builder->AddFilter(null_renderer, new_nr_name);
cap_graph->RenderStream(&PIN_CATEGORY_PREVIEW,
&MEDIATYPE_Video, new_source, sample_grabber_filter, null_renderer);
}
Would something like the above implementation work? If not, then is there some other way to do this? Any help is much appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以创建示例采集器和渲染器的许多实例并将其插入到图表中。只是不要忘记单独创建它们(为每个实例调用 CoCreateInstance),不要尝试多次插入相同的实例。
Yes, you can create and insert into your graph many instances of sample grabber and renderers. Just don't forget to create them separately (call CoCreateInstance for each one), do not try to insert the same instance many times.