-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_single_video.py
45 lines (37 loc) · 1.28 KB
/
check_single_video.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
42
43
44
45
import sys
import os
import cv2 as cv
from tqdm.auto import tqdm
import argparse
def check_single_video(name):
video = cv.VideoCapture(name)
end = video.get(cv.CAP_PROP_FRAME_COUNT)
for _ in tqdm(range(int(end) - 1), position=2):
frame = video.get(cv.CAP_PROP_POS_FRAMES)
ret, frame = video.read()
if not ret:
print(frame)
video.release()
return False
video.release()
return True
if __name__ == "__main__":
# parser = argparse.ArgumentParser(description='Process files in dir or single file \n can remove bad files if you'
# parser.add_argument('file_or_dir', metavar='file_or_dir', type=str)
# parser.add_argument('--rm_bad', metavar='rm_bad')
# args = parser.parse_args()
rm_bad = True
if os.path.isdir(sys.argv[1]):
bad_list = []
for file in tqdm(os.listdir(sys.argv[1]), position=1):
if ".mp4" not in file:
continue
file_path = os.path.join(sys.argv[1], file)
if not check_single_video(file_path):
bad_list.append(file_path)
if rm_bad:
for b_file in bad_list:
os.remove(b_file)
else:
check_single_video(sys.argv[1])
# 487