2

I'm trying to extract the frames from the following video (Disclosure: I'm not the owner of the video, the video is taken from a public dataset). To get the number of video frames I do:

cap = cv2.VideoCapture(video_path)
cap.get(cv2.CAP_PROP_FRAME_COUNT) # This returns 32

To extract the frames I have this method:

def obtain_frames(video_path: str):
    cap = cv2.VideoCapture(video_path)
    frames = []
    while True:
        success, image = cap.read()
        if not success:
            break
        frames.append(image)
    return frames

Finally, I count the number of extracted video frames with:

frames = obtain_frames(video_path)
len(frames) # This returns 17

and I get an inconsistent number compared to cv2.CAP_PROP_FRAME_COUNT.

I'm also aware of this SO question but still, when I display the video I can go all through the end and yet I can't read all the frames.

Any pointers/directions are welcome.

gorjan
  • 5,405
  • 2
  • 20
  • 40
  • 1
    https://stackoverflow.com/questions/33311153/python-extracting-and-saving-video-frames does this help in any way? – ombk Dec 06 '20 at 16:21
  • Thanks but not really. I think that I managed to find the reason for the inconsistency, you can read it here: https://stackoverflow.com/questions/31472155/python-opencv-cv2-cv-cv-cap-prop-frame-count-get-wrong-numbers – gorjan Dec 06 '20 at 16:32
  • 1
    use ffprobe on the command line to inspect your video file. `ffprobe yourvideo.file -show_format -show_streams -show_frames` or something along those lines – Christoph Rackwitz Dec 06 '20 at 18:03

0 Answers0