I'm enamored with the movie capabilities of my Canon Digital Elph.  While I love taking pictures, sometimes I don't just want stills from an event, but would prefer to capture the whole thing in the form of a movie.  As a result, I take short movies with it all the time.

Recently, I wanted to extract some frames from one of these .avi movies.  Sure, there are a plethora of tools I could download that would do this for me, but what fun is that when I could write one myself? :)

So, I wrote a small app called ExtractFrames that extracts all the frames from a video into individual .jpg files, and I've made the source available for download (standard disclaimers apply). To use the tool, simply drag-and-drop the video(s) you want to process onto the app in Explorer, or from the command line specify the video(s) you want processed as separate arguments.

The Main method of ExtractFrames is a short wrapper around a class I wrote called VideoFrameReader:

using (VideoFrameReader reader = new VideoFrameReader(path))
    Console.WriteLine("Processing " + path + "...");

    // Create a directory to store the frames
    string dirPath = path + "_frames\\";

    // Read each frame and save it into the directory
    for (int frameNumber = 0; frameNumber < reader.NumberOfFrames; frameNumber++)
        using (Bitmap frame = reader.GetFrame(frameNumber))
            const long quality = 100;
            Console.WriteLine("\tSaving frame {0}/{1}", frameNumber, reader.NumberOfFrames);
            ImageUtilities.SaveImage(frame, dirPath + frameNumber + ".jpg", quality);

VideoFrameReader is, in turn, a wrapper around the MediaDet COM object, accessed through COM interop (if you want to use VideoFrameReader in your own apps, make sure to add a COM reference to the Dexter 1.0 type library, or just use the existing Interop.DexterLib.dll included in the download).

MediaDet works with most .avi and .wmv files, and I believe some .mpg files, which means VideoFrameReader will do the same. Unfortunately, it doesn't currently work with .dvr-ms files, so this class can't be used to extract stills from recorded television unless you first transcode the .dvr-ms to another supported format.