How to know total number of Frame in a file with cv2 in python

Niraj picture Niraj · Aug 18, 2014 · Viewed 78.7k times · Source

How to know total number of Frame in a file ( .avi) through Python using open cv module.

If possible what all the information (resolution, fps,duration,etc) we can get of a video file through this.

Answer

phev8 picture phev8 · May 24, 2016

With a newer OpenCV version (I use 3.1.0) it works like this:

import cv2

cap = cv2.VideoCapture("video.mp4")
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
print( length )

And similar for other video properties cv2.CAP_PROP_*