def countFrame1(path):# 系统自带的统计方法
video = cv2.VideoCapture(path)
total = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
print(total)
def countFrame2(path):# 手动统计(特别慢)
video = cv2.VideoCapture(path)
total = 0
while True:
(current, frame) = video.read()
if not current:
break
total += 1
print(total)
print(total)
if __name__ == '__main__':
countFrame1("video.mp4") # 快方法
countFrame2("video.mp4") # 慢方法
opencv版本3及以上版本才可以用快方法