Extract Images From a Video With FFMPEG

From Squirrel's Lair
Revision as of 22:55, 2022 January 18 by Hal (talk | contribs) (Using FFmpeg to extract frames from a source video)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


  • Cargo:


  • Categories:
  • Default form


There are a lot of tools out there to process video or convert a series of images to video, but there don't seem to be many that will do the opposite.

FFmpeg is a very flexible tool that can do this (and many other) tasks very easily. Looking at the documentation can be a bit daunting because of the breadth of features it has, but if you want to quickly extract images from a video, you can use the following command:

ffmpeg -i input_file.mpg -ss 00:05 -to 01:25 -vf scale=1920:1080 output_file%d.bmp

Here's what these particular options do:

-i input_file.mpg - sets the input file to input_file.mpg

-ss 00:05 - start extracting images from the 5 second point in the video

-to 01:25 - extract images up until the 1 minute, 25 second point in the video

-vf scale=1920:1080 - sets the dimensions of the output files to 1920x1080.

output_file%d.bmp - name the created image files output_file#.bmp, where # is an incrementing number.

The number of images you will get with these options depends on the frame rate of the video. For example, if ffmpeg is extracting from 00:05 to 01:25, that'll be 1:20 (or 80 seconds) worth of video. If the frame rate of the video is 24FPS, you'll get (80s)x(24F/s), which works out to 1920 images written to disk, each representing one frame.

If you don't use the -ss tt:tt and -to tt:tt options, ffmpeg will convert the entire input file to a series of images. Depending on the video and output options, this can take up a lot of disk space very quickly!

if you don't use the -vf scale=x:y option, ffmpeg will produce output images that are the same dimensions as the input file.

The highest-quality (but largest file size) extracted images will be those in formats with no compression, like .bmp. A format that uses compression like .jpg will give you smaller file sizes but with reduced quality.

This is barely a scratch on the surface of the things that FFmpeg can do, but it's a handy tool to remember. Check out the FFmpeg Documentation Pages for more information on what FFmpeg can do!