将相同的过滤器多次添加到 DirectShow Graph

发布于 2024-11-04 08:40:45 字数 1629 浏览 3 评论 0原文

如果不首先解释我要做什么,我遇到的问题有点难以解释,所以我将从这个开始。我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感性不性感 2024-11-11 08:40:45

是的,您可以创建示例采集器和渲染器的许多实例并将其插入到图表中。只是不要忘记单独创建它们(为每个实例调用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文