-
Notifications
You must be signed in to change notification settings - Fork 0
/
video_processing.py
52 lines (38 loc) · 1.39 KB
/
video_processing.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
46
47
48
49
50
51
52
import argparse
import tqdm
from youtube_dl.utils import DownloadError
from src.manager import Manager
from src.video_processor import VideoProcessor
from src.keypoints_loger import make_log
def youtube_video_process(link: str):
manager = Manager()
manager.prepare_processing(link)
processor = VideoProcessor(manager.cfg)
process_gen = processor.run(manager.video)
file_name = manager.processed_file.split(".")[0]
frames_count = manager.frames_count
output_txt_path = f'data/results/{file_name}.txt'
with open(output_txt_path, 'a') as output_txt:
for frame_pos, (vis_frame, predictions) in tqdm.tqdm(process_gen, total=frames_count):
manager.output_video.write(vis_frame)
output_txt.write(make_log(frame_pos, predictions))
manager.finish_processing()
def get_parser():
parser = argparse.ArgumentParser(
description="Detectron2 human pose estimation")
parser.add_argument(
"--link",
help="Link to youtube video",
)
return parser
if __name__ == '__main__':
args = get_parser().parse_args()
if args.link:
try:
youtube_video_process(args.link)
except DownloadError:
print(f'Can not download video from link: {args.link}')
except Exception as ex:
print(f'Something went wrong!\n{ex}')
else:
print('Link to YouTube video required')