AForge.NET

Testimonials
Features
Samples
Tools
Documentation
License
Downloads
Sources
Discussions
Partners
Projects
Members
Donate

AForge.NET Framework
2.2.5 version is available!

Reading/writing AVI files

AForge.NET framework provides simple API to read and write AVI video files through Video 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( );