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?

halfelf
  • 9,737
  • 13
  • 54
  • 63
Peter
  • 1,155
  • 8
  • 20
  • +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. – Stu Thompson Nov 13 '09 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 Nov 13 '09 at 20:55

2 Answers2

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?

Stu Thompson
  • 38,370
  • 19
  • 110
  • 156
  • 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 Nov 13 '09 at 09: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.

Peter
  • 1,155
  • 8
  • 20