FFMPEG- Convert video to images

You can use the select filter for a set of custom ranges:

ffmpeg -i in.mp4 -vf select='between(t,2,6)+between(t,15,24)' -vsync 0 out%d.png

Official ffmpeg documentation on this: Create a thumbnail image every X seconds of the video

Output one image every second:

ffmpeg -i input.mp4 -vf fps=1 out%d.png

Output one image every minute:

ffmpeg -i test.mp4 -vf fps=1/60 thumb%04d.png

Output one image every 10 minutes:

ffmpeg -i test.mp4 -vf fps=1/600 thumb%04d.png

In addition to the select filter in Gyan's answer (which I use with eq rather than between), I came across another filter in the manual: thumbnail

Select the most representative frame in a given sequence of consecutive frames.

The filter accepts the following options:

  • n: Set the frames batch size to analyze; in a set of n frames, the filter will pick one of them, and then handle the next batch of n frames until the end. Default is 100.

Since the filter keeps track of the whole frames sequence, a bigger n value will result in a higher memory usage, so a high value is not recommended.

Examples

  • Extract one picture each 50 frames:

    thumbnail=50
    
  • Complete example of a thumbnail creation with ffmpeg:

    ffmpeg -i in.avi -vf thumbnail,scale=300:200 -frames:v 1 out.png
    

Another way is to use ffmpeg library for python, particularly useful if you don't want to add ffmpeg to your pc environment. Start by installing ffmpeg on conda with:conda install ffmpeg Then you can write a script as bellow:

import ffmpeg
input_file_name = 'input_video.mp4'
(ffmpeg
 .input(input_file_name )
 .filter('fps', fps=10, round = 'up')
 .output("%s-%%04d.jpg"%(input_file_name[:-4]), **{'qscale:v': 3})
 .run())

Tags:

Ffmpeg