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

查看:34
本文介绍了提取 .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.

提前致谢.通克

推荐答案

这是不可能的,除非您对输入的 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 中,大多数没有).

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天全站免登陆