Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting frames of a .avi file [closed]

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?

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.

Thanks in advance. Tunc

like image 364
talkanat Avatar asked Jul 24 '13 05:07

talkanat


People also ask

How do I extract still frames from a video?

Take a screenshot when the video is playing simply by pressing the Snapshot icon or pressing CTRL+ALT+S. You can use the Left or Right arrow button on the keyboard to playback the video frame by frame and save the frame in image format.

How do I extract frames from a video in Windows 10?

Open the video that you want to extract frames from in the Movies & TV app. Go to the part that you want to extract an image of. Click the edit button at the bottom. From the menu that opens, select Save photo from video.


1 Answers

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.

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

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

like image 150
Nikita B Avatar answered Oct 19 '22 20:10

Nikita B