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.
In OpenCV 3 the name of the frame count property is cv2. CAP_PROP_FRAME_COUNT while in OpenCV 2.4 the property is named cv2. cv. CV_CAP_PROP_FRAME_COUNT .
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_*
import cv2 cap = cv2.VideoCapture(fn) if not cap.isOpened(): print("could not open :",fn) return length = int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT)) width = int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)) height = int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)) fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)
see here for more info.
also, all of it with a grain of salt, not all those props are mandatory, some might not be available with your capture / video codec
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With