如何在 C# 中使用 DirectShowNet 将视频和音频渲染到文件?

发布于 2024-09-30 19:43:31 字数 934 浏览 0 评论 0原文

我已经检测到音频和视频设备并构建了捕获图,但在最后一个过滤器中我无法渲染它们。

            DsDevice dev = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice)[0];
            hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out capFilter);
            Marshal.ThrowExceptionForHR( hr );

            DsDevice audioDv = DsDevice.GetDevicesOfCat(FilterCategory.AudioInputDevice)[0];
            hr = m_FilterGraph.AddSourceFilterForMoniker(audioDv.Mon, null, audioDv.Name, out audioFilter);
            Marshal.ThrowExceptionForHR(hr);

            asfWriter = ConfigAsf(capGraph, szOutputFileName);

            hr = capGraph.RenderStream(null, MediaType.Audio, audioFilter, null, asfWriter);
            Marshal.ThrowExceptionForHR(hr);
            hr = capGraph.RenderStream(null, MediaType.Video, capFilter, null, asfWriter);
            Marshal.ThrowExceptionForHR( hr );

这是我尝试的一段代码,我应该选择其他 MediaType 吗?

I have been detect the audio and video devices and build the Capture Graph, but in the last filter I cannot render both of them.

            DsDevice dev = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice)[0];
            hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out capFilter);
            Marshal.ThrowExceptionForHR( hr );

            DsDevice audioDv = DsDevice.GetDevicesOfCat(FilterCategory.AudioInputDevice)[0];
            hr = m_FilterGraph.AddSourceFilterForMoniker(audioDv.Mon, null, audioDv.Name, out audioFilter);
            Marshal.ThrowExceptionForHR(hr);

            asfWriter = ConfigAsf(capGraph, szOutputFileName);

            hr = capGraph.RenderStream(null, MediaType.Audio, audioFilter, null, asfWriter);
            Marshal.ThrowExceptionForHR(hr);
            hr = capGraph.RenderStream(null, MediaType.Video, capFilter, null, asfWriter);
            Marshal.ThrowExceptionForHR( hr );

This is a piece of code that I try, Should I choose the other MediaType?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

甜宝宝 2024-10-07 19:43:31

我是一名 C++ directshow 开发人员,我不熟悉 DirectShow.net,所以我无法评论您的代码。

但我有很多 DShow 经验...

要将视频和音频媒体流写入文件,您需要一个多路复用器过滤器。

从源过滤器中,视频和音频引脚都应连接到 mux(多路复用器的缩写)过滤器。从那里,多路复用器过滤器的(单针)输出将连接到 文件编写器过滤器

多路复用器过滤器取决于所使用的媒体类型。如果您无法将两个流连接到您的多路复用器过滤器,则表明它不支持其中一种(或两种)媒体类型。

在这种情况下,请进行一些测试 - 例如,仅将视频流渲染到磁盘,然后仅渲染音频磁盘。其中至少有一个不起作用——这就是令人反感的媒体类型。

您可以尝试在谷歌上搜索替代的多路复用器过滤器,编写自己的过滤器,或者更改源流的媒体类型。

希望这至少有一些帮助!

I'm a C++ directshow developer, I'm not familiar with DirectShow.net, so I can't comment on your code.

But I have lots of DShow experience...

To write video and audio media streams to a file, you need a mux filter.

From your source filter(s), both video and audio pins should connect to a mux (short for multiplexer) filter. From there, the (single pin) output of the mux filter will connect to the File Writer filter.

Mux filters are dependent on the media types in use. That you can't connect both streams to your mux filter would suggest that it doesn't support one (or both) of the media types.

In that case, do a couple of tests - e.g. render only the video stream to disk, and then render only audio disk. At least one of them won't work - that's the offending media type.

You could try googling for an alternative mux filter, write your own, or, change the media type of your source stream.

Hope this is of at least some help!

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