MCPcopy Create free account
hub / github.com/PyImageSearch/imutils / count_frames

Function count_frames

imutils/video/count_frames.py:5–40  ·  view source on GitHub ↗
(path, override=False)

Source from the content-addressed store, hash-verified

3import cv2
4
5def count_frames(path, override=False):
6 # grab a pointer to the video file and initialize the total
7 # number of frames read
8 video = cv2.VideoCapture(path)
9 total = 0
10
11 # if the override flag is passed in, revert to the manual
12 # method of counting frames
13 if override:
14 total = count_frames_manual(video)
15
16 # otherwise, let's try the fast way first
17 else:
18 # lets try to determine the number of frames in a video
19 # via video properties; this method can be very buggy
20 # and might throw an error based on your OpenCV version
21 # or may fail entirely based on your which video codecs
22 # you have installed
23 try:
24 # check if we are using OpenCV 3
25 if is_cv3():
26 total = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
27
28 # otherwise, we are using OpenCV 2.4
29 else:
30 total = int(video.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))
31
32 # uh-oh, we got an error -- revert to counting manually
33 except:
34 total = count_frames_manual(video)
35
36 # release the video file pointer
37 video.release()
38
39 # return the total number of frames in the video
40 return total
41
42def count_frames_manual(video):
43 # initialize the total number of frames read

Callers

nothing calls this directly

Calls 2

count_frames_manualFunction · 0.85
is_cv3Function · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…