Extracting still images from video using ffmpeg

Several interested parties contacted me about getting ffmpeg to spit out a series of stills from a video file. I spent a few minutes googling, and wasn't getting anywhere, so I put together this quick walkthrough.

ffmpeg can do it, but it's always been a bit akward for me to make it to do *exactly* what I want it to do. But not altogether difficult.

Try this:

ffmpeg -i inputfile.mov -ss 1.000 -r 1 -vframes 10 -an -s 320x240 -f image2 frame%d.jpg

Ok, so the breakdown is as follows:

  • inputfile.mov is obviously your video, which can be pretty much any file format
  • ss - the seek point, where you want to start from, in seconds
  • r - the frame rate -- I set it to 1, so it exports a single frame each second. Otherwise it's a clusterfuck and you get 30fps of jpeg stills. You can even set it to a decimal, like .5 to get 1 frame every 2 seconds.
  • vframes - the number of frames to export. You can set it to a higher number than the number of frames in the video -- ffmpeg won't blow up or throw exceptions. Of course, if you already know how long the video is, you could have a script that dynamically tells ffmpeg how many frames to use.
  • an - drops the audio processing, probably unnessary, but might spare a few cpu cycles.
  • s - size in pixels, WxH
  • f - file format. image2 works, so I use it. There's lots of options if you feel inclined to experiment, just type ffmpeg -formats
  • frame%d.jpg - "frame" is just an arbitrary name, you can call it anything, just use double quotes if there are spaces in the name. %d tells ffmpeg where to put the incremental numbers. No idea if there is a way to force leading zeros, that would be nice.

Bug: the first two frames ffmpeg exports are always the same. I don't know any way to avoid this, other than to have your calling script toss the first file out. Or just live with it.

Posted In

Post new comment

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Images can be added to this post.

More information about formatting options

Captcha
This question is used to make sure you are a human visitor and to prevent spam submissions.
Copy the characters (respecting upper/lower case) from the image.

Flickr Photos

Get Firefox

Random Quote

Our lives begin to end the day we become silent about things that matter.

— Dr. Martin Luther King Jr.