还有其他方法可以在 directshow 中保存视频吗

发布于 2024-11-08 03:57:27 字数 1751 浏览 0 评论 0原文

我正在使用 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 以外的任何内容?

I am using DirectShow.Net and I am capturing video from a webcam and saving it to an AVI file. AVI files can get large and I would like to save it in a different format. I am using ICaptureGraphBuilder2::SetOutputFileName( MediaSubType.type, name, out, out). ICaptureGraphBuilder will only let me use a MediaSubType of .AVI or .ASF to save a file. If i try to change the type it tries to save as, it will crash:

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

Is there a way to save to anything other then AVI or ASF without too much hassle?

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

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

发布评论

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

评论(2

冰火雁神 2024-11-15 03:57:27

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

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

The problem is most likely not the AVI container format but the codec that you are using to compress the video.

You will need to add a different video compression filter (probably MPEG4 or AVC) and wherever you get that will probably also supply an MP4 mux that you can and should use instead of the avi mux that you are using now.

不必了 2024-11-15 03:57:27

您是否看过 EmguCV(www.emgu.com,它是开放式简历的 .net 包装器。这有很多其中可能有帮助的课程。

Have you looked at EmguCV (www.emgu.com which is a .net wrapper for open cv. This has a number of classes in it that may help.

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