C# 提取 .avi 文件的帧

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17825677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 10:35:28  来源:igfitidea点击:

Extracting frames of a .avi file

c#videovideo-processing

提问by talkanat

I am trying to write a c# code to extract each frame of a .avi file and save it into a provided directory. Do you know any suitable library to use for such purpose?

我正在尝试编写 ac# 代码来提取 .avi 文件的每一帧并将其保存到提供的目录中。您知道用于此类目的的任何合适的库吗?

Note: The final release must work on all systems regardless of installed codec, or system architecture. It must not require the presence of another program (like MATLAB) on the machine.

注意:无论安装的编解码器或系统架构如何,最终版本都必须适用于所有系统。它不能要求机器上存在另一个程序(如 MATLAB)。

Thanks in advance. Tunc

提前致谢。通克

采纳答案by Nikita B

This is not possible, unless you add some restrictions to your input avi files or have control over encoder used to create them. To get an image you will have to decode it first, and for that you will need an appropriate codec installed or deployed with your app. And i doubt its possible to account for every codec out there or install/deploy them all. So no, you won't be able to open just anyavi file. You can, however, support the most popular (or common in your context) codecs.

这是不可能的,除非您对输入的 avi 文件添加一些限制或控制用于创建它们的编码器。要获取图像,您必须先对其进行解码,为此您需要安装或部署适当的编解码器与您的应用程序一起使用。而且我怀疑是否有可能考虑到那里的每个编解码器或安装/部署它们。所以不,您将无法打开任何avi 文件。但是,您可以支持最流行(或在您的上下文中最常见)的编解码器。

The easiest way to do it is indeed using an FFMPEG, since its alredy includes some of the most common codecs (if you dont mind extra 30+Mb added to your app). As for wrappers, i used AForgewrapper in the past and really liked it, because of how simple it is to work with. Here is an example from its docs:

最简单的方法确实是使用 FFMPEG,因为它已经包含一些最常见的编解码器(如果您不介意将额外的 30+Mb 添加到您的应用程序中)。至于包装器,我过去使用过AForge包装器并且非常喜欢它,因为它使用起来非常简单。这是其文档中的一个示例:

// create instance of video reader
 VideoFileReader reader = new VideoFileReader( );
// open video file
reader.Open( "test.avi" );
// read 100 video frames out of it
for ( int i = 0; i < 100; i++ )
{
    Bitmap videoFrame = reader.ReadVideoFrame( );

    videoFrame.Save(i + ".bmp")

    // dispose the frame when it is no longer required
    videoFrame.Dispose( );
}
reader.Close( );

There is also a VfW (which is included in Windows by default) wrapper in AForge, if you want to keep it simple without involving external libraries. You will still need VfW compatible codecs installed tho (some of them are included in Windows by default, most are not).

如果您想在不涉及外部库的情况下保持简单,AForge 中还有一个 VfW(默认情况下包含在 Windows 中)包装器。您仍然需要安装 VfW 兼容编解码器(其中一些默认包含在 Windows 中,大多数没有)。

回答by Mark Redman

You could have a look at FFmpeg: http://www.ffmpeg.org/

你可以看看 FFmpeg:http: //www.ffmpeg.org/

Some C# related info: Using FFmpeg in .net?

一些 C# 相关信息:在 .net 中使用 FFmpeg?

or: http://www.ffmpeg-csharp.com/

或:http: //www.ffmpeg-csharp.com/