November 30, 2005

Using FFmpeg to Extract PNG Files

I've been playing with FFmpeg over the last year to encode video files for Flash. I've mainly experimented with my golf swing and created a little app to compare each frame of my swing to a pro's. This helps me identify all my many flaws and easily visualize what I'm doing wrong. I'll post more on the video encoding process later, but wanted to focus on extracting frames from video files.

I'm still struggling with all the many parameters FFmpeg has to offer. Right now there are easily over 100 and using them in the right combination can be tricky. I recently figured out how to pull the first frame from a video file, resize it, and save it to PNG. Not too exciting but I'm really hoping to get JPG extraction working with the ability to extract a frame at any point in time. I know FFmpeg supports it....just need to find out the right combo to make it work. The problem with PNG is that filesizes can get rather large for photos. Take the following photo for example:

this size comes out to about 186kB at 320x240. The command to make this magic happen is:

ffmpeg -i swing.avi -vcodec png -vframes 1 -an -f rawvideo -s 320x240 swing1.png

I won't go into detail about the parameters listed above and if you want more details then click here. Needless to say, if this were a JPG file we'd be looking at less than 30kB at 80% compression, which would look just as good. Overall I've been highly impressed with FFmpeg and what it does for video encoding, especially FLV. I'll post more on my video ventures in the future.

Posted by dennis baldwin at November 30, 2005 12:48 AM
Comments