I'm using FFmpeg to extract images from video, 1 frame every 6 seconds:

Normal command on Dos ( Windows 8 OS) >  ffmpeg -i in.mkv -r 1/6 %4d.png

Takes too much time as speed is very low, around 15-20.

So I used skip_frame nokey

ffmpeg -skip_frame nokey -i "in.mkv" -vsync 0 -frame_pts true -r 1/6 %4d.png

This extracts at higher speed, around 200 (ten times faster).
But the problem is it skips many images, and throws error:

application provided invalid, non monotonically increasing dts to muxer in stream

So I used this command:

ffmpeg -i in.mkv -vf "select='if(not(floor(mod(t,6)))*lt(ld(1),1),st(1,1)+st(2,n)+st(3,t));if(eq(ld(1),1)*lt(n,ld(2)+1),1,if(trunc(t-ld(3)),st(1,0)))'" -vsync 0 %4d.png

(Provided here - How to capture first X frames every X seconds into a PNG with FFmpeg?)

This gives me speed of 25-30.

Is there anyway I can achieve higher speed with -skip_frame?

  • Can FFMPEG extract images from a video with timestamps?
    – user1038202
    Commented Sep 25, 2019 at 17:35
  • Edited a bit, last command removed, not working properly.
    – Cool
    Commented Sep 25, 2019 at 17:35
  • 1
    @ankii, no. just edited my origional post. The link you've given is about timestamp. I'm just insterested in extracting images from video fastest way possible. Thank you.
    – Cool
    Commented Sep 25, 2019 at 17:38
  • @ankii, loop ?? run what ? command ?
    – Cool
    Commented Sep 25, 2019 at 17:40
  • You want the speed advantage of using -skip_frame, but you don't want it to "skip many images"? That's what you're telling it to do: skip all frames that are not key frames. On top of that you're applying -r 1/6 which modifies the frame rate.
    – llogan
    Commented Sep 25, 2019 at 17:41

1 Answer 1


Ok the code I posted above in the original post is the only solution I've found so far for faster image extraction. Sometimes gives me speed upto 50.

ffmpeg -i in.mkv -vf "select='if(not(floor(mod(t,6)))*lt(ld(1),1),st(1,1)+st(2,n)+st(3,t));if(eq(ld(1),1)*lt(n,ld(2)+1),1,if(trunc(t-ld(3)),st(1,0)))'" -vsync 0 %4d.png

If you are interested in random image extraction (based on keyframe) to get higher speed, use -skip_frame nokey.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .