FFMPEG- Convert video to images

123,937

Solution 1

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

Solution 2

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

Solution 3

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())
Share:
123,937
hack
Author by

hack

Updated on July 05, 2022

Comments

  • hack
    hack almost 2 years

    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?

  • hack
    hack over 7 years
    Thanks. Can we specify duration for which we need images? Like i need images between 2-6 seconds and 13-17 seconds of a 60 sec video, through a single command.
  • Vitaliy Fedorchenko
    Vitaliy Fedorchenko over 7 years
    it is possible to seek input video to some starting position, but I'm not sure that ffmpeg has a filter that can accept ranges. Maybe you'll need to make 2 ffmpeg calls (for 2-6 range and 13-17 range).
  • hack
    hack over 7 years
    Hi. How can i specify the frame rate by which it should extract images? example, i want to extrate 5 frames/second between 2 to 6.
  • Gyan
    Gyan over 7 years
    Use -vf fps=5,select='between(t,2,6)+between(t,15,24)'
  • hack
    hack over 7 years
    Thanks for quick response! This will extract images 'between' mentioned time (2-6). How can i get images 'From' 2-6?
  • hack
    hack over 7 years
    Also, can i mention multiple duration set with 'ss' filter? ffmpeg -ss 10 -i video.mp4 -to 12 -copyts -vf fps=1 v2f/out%d.png this would create images from 10 seconds to 12 seconds. Can i give multiple duration set here?
  • Gyan
    Gyan over 7 years
    I don't understand what you mean by from. Only one ss can be applied.
  • hack
    hack over 7 years
    Is it like between(t,2,6) will extract images between time interval 2-6 (2 and 6 excluding)?
  • hack
    hack over 7 years
    I just tested. It is inclusive of 2 and 6 :). One final doubt, will the input file be decoded till it reaches the mentioned time position?Or will it be parsed ,just like in specifying ss before input
  • Gyan
    Gyan over 7 years
    Nope, decoded till it reaches first qualifying timecode.
  • Matt Kleinsmith
    Matt Kleinsmith over 6 years
    Why -vsrync 0? I read the docs but still don't understand: ffmpeg.org/ffmpeg.html -- It seems the 0 option prevents any frames being dropped due to timestamp issues.
  • Gyan
    Gyan over 6 years
    The image2 muxer, which is used to output image sequences, defaults to CFR. So, when given frames with timestamp differences greater than 1/fps, ffmpeg will duplicate frames to keep CFR. Will happen here between selection of t=6 frame and t=15 frame vsync 0 prevents that.
  • P.O.W.
    P.O.W. about 3 years
    Output numbers with fixed length : out_%04d.jpg (change "4")