1

I wish to use python to open a video file (avi, wmv, mp4), determine the total number of frames contained within the video, and save an arbitrary frame from within the video as an image file.

I have looked at pyffmpeg, but I do not know how to obtain the total number of frames contained in the video without iterating over each (which is incredibly slow). My code to obtain the number of frames in a video is given below:

import pyffmpeg
stream = pyffmpeg.VideoStream()
stream.open('video.avi')
frame_no = 0
# Very inefficient code:
while (stream.GetFramNo(frame_no)):
    frame_no=frame_no+1

Is there a way in which I can do this efficiently? If not, please suggest an alternative extension or approach; code fragments would be a nice bonus.

Josh
  • 1,357
  • 2
  • 23
  • 45
  • Duplicate: http://stackoverflow.com/questions/2017843/fetch-frame-count-with-ffmpeg – Tom Zych Aug 27 '11 at 12:32
  • No, the question you linked to relates directly to ffmpeg. I am trying to determine the number of frames programmatically using pyffmpeg. – Josh Aug 27 '11 at 12:52
  • Whoops, my bad. It looks liky pyffmpeg is a wrapper for ffmpeg? If so, the other post will probably tell you what to do. – Tom Zych Aug 27 '11 at 12:56

0 Answers0