4

I have some video that I would like to convert to images of frames every 2 sec.

E.g. If the video is 7 seconds long at 15 fps I would like to get frames 1, 31, 61, 91.

The command:

ffmpeg -i foo.mp4 -r 0.5  -f image2 -vcodec mjpeg foo%d.jpg

appears to do what I want, but which frame does it get? 1, 31, 61, 91 or 30, 60, 90 or 13, 43, 73, 103?

2
  • +1 for posting what worked for you! Can I ask why you need such precision with this? I did not get that out of the question initially. Commented Nov 13, 2009 at 15:10
  • I'm a biologist and I was trying to capture the state of an experiment every two sec. to match up w/ other data. One or two frames off probably wouldn't have been a problem, but it I could get it exactly right, why not?
    – Peter
    Commented Nov 13, 2009 at 20:55

2 Answers 2

1

The first image will be from the very first frame.

Note that you very well may get an image or two more that you expect. I believe this is because of rounding and/or that ffmpeg creates a final images. E.g.: Is your video really 7s long? Or is it 7.63s long?

1
  • 1
    In tests of ffmpeg, using it to make movies out of numbered images, it is consistent after the first few frames (e.g. grabbing every 60th), but for the first two second the grabbed frames were not evenly spaced...
    – Peter
    Commented Nov 13, 2009 at 9:04
1

I ended up doing the following largely borrowed from the ffmpeg tutorial:

ffmpeg -v 3 -vsync 0 -sameq -i movie.mpr  -f image2 "images-%03d.jpeg"

This gives me each frame of the movie as a JPEG numbered 1 to the end of the movie. I then filtered these files using a scripting language, knowing the frame rate was 30fps, to grab every 60th frame.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.