c# - 有没有另一种方法可以在 directshow 中保存视频

标签 c# directshow directshow.net

我正在使用 DirectShow.Net,我正在从网络摄像头捕获视频并将其保存为 AVI 文件。 AVI 文件可能会变大,我想以不同的格式保存它。我正在使用 ICaptureGraphBuilder2::SetOutputFileName(MediaSubType.type, name, out, out)。 ICaptureGraphBuilder 将只允许我使用 .AVI 或 .ASF 的 MediaSubType 来保存文件。如果我尝试更改它尝试另存为的类型,它将崩溃:

            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);

        //Create the file writer part of the graph. SetOutputFileName does this for us, and returns the mux and sink
        IBaseFilter mux;
        IFileSinkFilter sink;
        hr = captureGraphBuilder.SetOutputFileName(MediaSubType.MPEG1Video, textBox1.Text, out mux, out sink);
        captureGraphBuilder.SetOutputFileName

        DsError.ThrowExceptionForHR(hr);


        //Render any preview pin of the device
        hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theDevice, null, null);
        DsError.ThrowExceptionForHR(hr);

有没有一种方法可以轻松地保存为 AVI 或 ASF 以外的任何格式?

最佳答案

问题很可能不是 AVI 容器格式,而是您用来压缩视频的编解码器。

您将需要添加一个不同的视频压缩过滤器(可能是 MPEG4 或 AVC),无论您得到什么,都可能还会提供您可以而且应该使用的 MP4 多路复用器,而不是您现在使用的 avi 多路复用器。

关于c# - 有没有另一种方法可以在 directshow 中保存视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6051491/

相关文章:

c# - 查找 BigInteger 的最高有效位

c# - 将 GraphQL 查询映射到 Select() linq 到 sql

c# - 如何对列表/数组/可枚举内的记录执行 "change"操作?

c# - 媒体样本长时间保存在图形中(累积效果)

video - C++ DirectShow W32 直接在框架上绘图

c# - QueryInterface 在 C# 上因 E_NOINTERFACE 而失败

ffmpeg - 如何通过 ffmpeg 或 DirectShow.net 压缩未压缩的 avi

当我失去互联网时,C# MySQL 连接失败

c# - 如何找到上传的 mp4 或 f4v 视频的持续时间?

c# - 关于在 C# 中设置 FIle Writer 的问题