How To Extract Images from a Video with avconv on Linux

How To Extract Images from a Video with avconv on Linux

Suppose you’ve got an awesome video that nobody is watching and you want to create animated GIFs from excerpts of it so that people are forced to see your genius in action. But how do you extract images from a video? You’re in luck! Using the super-powerful avconv on Linux, you can quickly and easily break a video down frame by frame. If you follow our tutorial How To Create Animated GIFs from a PNG Sequence with ImageMagick and the Command Line, you can quickly and easily convert your PNG image sequence to an animated GIF.

I’m going to use this video as our example. It’s episode 4, “ls or List Directory Contents”, of our series, Superusers: The Legendary GNU/Linux Show. At 2:03 there’s a close-up of a jittery gremlin and some acorns that I think will make a great GIF.

If you don’t already have it, install avconv:

From the command line, navigate to the directory containing your video. The run the following command:

Let’s break this down, no pun intended.

First, we pass avconv our input file, ‘my_awesome_video.mp4’. Then, using the -r, or rate, switch, we specify that we want to extract 30 frames per second. Why? Because the standard frame-rate for video is 29.97 frames per second. But 30 is close enough. The -f option specifies that we want our output to be an image. And lastly: %04d.png applies a numerical sequence to the frames using four digits starting with 0001. Thus, our output will be a sequence of images titled ‘0002.png’, ‘0003.png’, ‘0004.png’, and so on.

If you’re working with a very long video and you only want to extract a short clip, use the seek option, -ss, and the duration option, -t, to specify the start point and the length of the clip, using this format: hh:mm:ss, where hh is hours, mm is minutes, and ss is seconds.

For example, to extract the 4 seconds I want to convert to a GIF I run the following command:

This returns a much more manageable image sequence and takes much less time to complete. Lastly, if you want to scale your image sequence up or down, you can use the -s option and pass it the WxH parameters. I’ll let you figure that one out. If you need help, Read The Fantastic Manual!

Follow the directions in our tutorial How To Create Animated GIFs from a PNG Sequence with ImageMagick and the Command Line to compile your extracted video frames into a miniature masterpiece, like this:

Gremlin GIF

Learn With Us

We want to take you on a journey through the other side of the creative process: making a living. Explore the necessary evils of business as we develop a creative media studio using free and open source software. Sign up for our New Moon newsletter delivered on, you guessed it, every New Moon.

Become a GNU/Linux Superuser!

Master the commands and structure of the fastest-growing computer operating system, Linux. Join super friends Adelie the penguin and Aramis the gnu on surreal adventures in the file tree. Learn the essential commands you need to take greater control of your computer in Superusers: The Legendary GNU/Linux Show.

Get It Now!
About the Author

How To Extract Images from a Video with avconv on Linux was posted by on . Jared is one half of the creative force behind Dototot. In addition to writing scripts and tutorials, he draws and animates both the digital and the analog.

Discuss this article in the Comments below, or and it with your friends. Learn more about our creative process by subscribing to the New Moon Newsletter .

Recommended for you
Join the discussion
  • Mercury

    There’s also a tool called Anyframe that lets you capture still frames from videos. Looks like Vimeo support is coming, too. http://www.anyframe.net

  • Dipanjan

    How to exract the I-frames from a video (I-frames in I-P-B video) ?

    I guess we have to use “select” statement.

  • Hello, how can I specify the folder in which the output image will be stored? Thx

Subscribe to our New Moon Newsletter

How do you make money doing what you love? Sign up for monthly emails exploring the necessary evils of business as we develop a creative media studio using free and open source software.

The email entered is invalid
×