forked from q294881866/vtl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
count.py
41 lines (32 loc) · 984 Bytes
/
count.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import sys
import cv2
class CountFile:
file_nums = 0
def count(self, dir_):
if os.path.isdir(dir_):
for d in os.listdir(dir_):
self.count(os.path.join(dir_, d))
else:
self.file_nums += 1
class CountFrame:
frame_nums = 0
sizes = []
def video_info(self, dir_):
if os.path.isdir(dir_):
for d in os.listdir(dir_):
self.video_info(os.path.join(dir_, d))
elif dir_.endswith('mp4'):
cap = cv2.VideoCapture(dir_)
self.frame_nums += cap.get(cv2.CAP_PROP_FRAME_COUNT)
self.sizes.append((cap.get(cv2.CAP_PROP_FRAME_WIDTH), cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
if __name__ == '__main__':
path = sys.argv[1]
path = os.path.abspath(path)
cf = CountFile()
cf.count(dir_=path)
print(cf.file_nums)
# cf2 = CountFrame()
# cf2.video_info(dir_=path)
# print(cf2.frame_nums)
# print(cf2.sizes)