Extract the frame (in image format) at exactly every minute (or second) from a video (by ffmpeg)

ffmpegframeframeratescreenshotvideo editing

Motivation: I would like to seek the frame, then take high quality and exact time screenshots (images) from a video.

The video is length is 00:48:43.71 and 23.98 fps (we can think it is 24 fps, isn't it?).


With reference from this webpage: Create a thumbnail image every X seconds of the video

I wrote some commands that grab a frame every hour, every minute, and every second.

After exterminating the images, the screenshots are in fact taken from the half hour, half minute, and half second. You will understand shortly.

For example, the command to grab a frame every minute, it is in fact extracting the frame at the half minute, which means the 00:00:30 , 00:01:30 , 00:02:30 , and so on. That is why I name to filename as follow:

ffmpeg -i "video.mp4" -start_number 0 -vf fps=1/60 "B 00-%02d-30.000.png"

(adding the "B" prefix is to prevent overwriting by different commands.)

For example, to grab a frame every second from 00:03:00 to 00:04:00, the commend is:

ffmpeg -i "video.mp4" -start_number 0 -vf fps=1 -ss 00:03:00 -to 00:04:00 "C 00-03-%02d.500.png"

To verify them, we can extract all the frames from 00:03:29 to 00:03:31 :

ffmpeg -copyts -ss 00:03:29 -i "video.mp4" -start_number 0 -to 00:03:31 "D 00-03-29.%03d.png"

We may check the following image files are identical:

D 00:03:29.012.png is identical to C 00:03:29.500.png.

D 00:03:29.024.png is identical to B 00:03:30.000.png.

D 00:03:29.036.png is identical to C 00:03:30.500.png.


Those are my findings from trials and errors this morning. Here comes my question:

Let's take "extract a frame at exactly every minute" as an example, how can we get / what is the command to get the frames 00:00:00.000 , 00:00:01.000, 00:00:02.000 , and so on?

I have just heard of ffmpeg this morning. I still do not know what -copyts means (after reading the docs) and when I need to put -ss position before -i and when to put it at the output part. So please do correct me if I am using the wrong commands.

Best Answer

The fps filter is designed to smartly drop/duplicate frames to match the output fps based on the input fps. If you ask it to output one frame every minute, it's going to select one frame at the center of the 00:00-01:00 window and drop all the others, thus why you get frames at 00:30, 01:30, etc..

Have you considered making a bat/bash script that does this ?

for i in 0..50
   ffmpeg -ss %i:oo -i input.mp4 -vframes 1 out-%i.png

You can also do the following if you wish to get screenshots at 01:00, 02:00 [..] instead of 00:30, 01:30 [..] :

ffmpeg -ss 00:30 -i input.mp4 -start_number 0 -vf fps=1/60 "B 00-%02d-00.000.png"
Related Question