参考http://www.aforgenet.com/framework/features/avi_files.html
Reading/writing AVI files
AForge.NET framework provides simple API to read and write AVI video files throughVideo for Windows interface. Although the interface is quite old and marked as obsolete by Microsoft, it is still supported and gives fairly simple API for accessing AVI video files.
AVIReader class
The class provides access to AVI video files and allows getting each video frame individually, as well as navigate through a video file specifying index of the next frame to receive:
// instantiate AVI reader
AVIReader reader = new AVIReader( );
// open video file
reader.Open( "test.avi" );
// read the video file
while ( reader.Position - reader.Start < reader.Length )
{
// get next frame
Bitmap image = reader.GetNextFrame( );
// .. process the frame somehow or display it
}
reader.Close( );
AVIWriter class
The class provides simple API for writing AVI video files. All you need to do is to specify codec to use, video size and frame rate and then start adding frames:
// instantiate AVI writer, use WMV3 codec
AVIWriter writer = new AVIWriter( "wmv3" );
// create new AVI file and open it
writer.Open( "test.avi", 320, 240 );
// create frame image
Bitmap image = new Bitmap( 320, 240 );
for ( int i = 0; i < 240; i++ )
{
// update image
image.SetPixel( i, i, Color.Red );
// add the image as a new frame of video file
writer.AddFrame( image );
}
writer.Close( );
使用writer.Open( "test.avi", 320, 240 );的时候,抛出异常Failed creating compressed stream
原因是:(1)wmv3编码不能在64bit下运行(2)windows7没有相应的codec
解决方法:(1)将所有的项目,改为x86 (2)安装wmv9VCMsetup (下载地址:http://www.microsoft.com/en-us/download/details.aspx?id=6191) 本人由于是32位的win7系统,只安装了Winndows Media Video 9 VCM就解决了问题。
感谢 Aforge开发摄像头监控的一些情况说明 http://www.cnblogs.com/ddlzq/archive/2010/10/21/1857385.html
本文介绍如何使用AForge.NET框架中的AVIReader和AVIWriter类进行AVI视频文件的读取与写入操作。通过示例代码展示了打开、读取及关闭AVI文件的过程,并提供了创建AVI文件并添加帧的具体步骤。
8154

被折叠的 条评论
为什么被折叠?



