提取.avi文件的框架 [英] Extracting frames of a .avi file

查看:79
本文介绍了提取.avi文件的框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

注意:最终版本必须在所有系统上都可以使用,无论安装的编解码器或系统体系结构如何。它一定不需要机器上存在其他程序(例如MATLAB)。

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.

在此先感谢您。
Tunc

Thanks in advance. Tunc

推荐答案

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

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 any avi file. You can, however, support the most popular (or common in your context) codecs.

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

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 AForge wrapper in the past and really liked it, because of how simple it is to work with. Here is an example from its docs:

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

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

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

这篇关于提取.avi文件的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆