Oct 28
How to extract frames with avconv, the right way
Capturing frames from a video with avconv or ffmpeg... I keep looking this up in search engines over and over again, yet I end up getting the wrong commands every time! - so here it is: extracting frames with avconv / ffmpeg and keeping quality high.
("Keeping quality up"?, you ask? Well, yes, that's what most command-examples you'll find elsewhere forget about. Omitting the qscale / quality option means you'll get blocky stills - I haven't completely investigated if this is from avconv dropping quality or from avconv setting the jpeg encoder to a low value - it seems to be the latter)
$ avconv -i video.mp4 -ss 00:15 -t 12 -an -q:v 1 -r 25 -f image2 /tmp/video_%05d.jpg
Explanation:
This command uses video.mp4 as input (-i), and seeks to the 15 sec mark (-ss) to extract frames for 12 seconds (-t), setting switch -an means audio is dropped, and -q:v is short for -qscale 1 (quality scale) with 1 meaning "best" - it's what many people think the deprecated -same_q switch would do - more or less. Rate (-r) is set to match the frame-rate as we'd like to extract every frame. If you would like to extract one frame every second you obviously set this to 1. Output is still images, encoded by the image2 encoder to jpeg files. The %05d means "add an incrementing number with 5 leading zeros".