59
votes

how can i convert a video to images using ffmpeg? Example am having a video with total duration 60 seconds. I want images between different set of duration like between 2-6 seconds, then between 15-24 seconds and so on. Is that possible using ffmpeg?

3
I'll comment with something relevang to all of the answers. You probably don't want to output in png. Output in jpg. If you want good quality, add -qscale:v 2 parameter.Íhor Mé

3 Answers

63
votes

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
62
votes

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
1
votes

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())