-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange_video_param.py
60 lines (50 loc) · 1.5 KB
/
change_video_param.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
53
54
55
56
57
58
59
60
# Date: 2020/10/15
# Author: LiaoSteve
import cv2
import os
cap_input = 'result_last.avi'
save = True
out_resize = 0
out_width = 640
out_height = 480
fast_factor = 3
out_name = 'fast_result_last_x'+str(fast_factor)+'.avi'
if not os.path.exists(cap_input):
raise RuntimeError(f'- [x] cap input: {cap_input} error happened.')
cap = cv2.VideoCapture(cap_input)
cap_width = int(cap.get(3))
cap_height = int(cap.get(4))
cap_fps = int(cap.get(5))
out_fps = int(cap_fps * fast_factor)
#out_fps = 23
if out_resize:
out = cv2.VideoWriter(out_name,
cv2.VideoWriter_fourcc(*'XVID'),
out_fps,
(out_width,out_height))
else:
out = cv2.VideoWriter(out_name,
cv2.VideoWriter_fourcc(*'XVID'),
out_fps,
(cap_width,cap_height))
print(f'[ Input ] size: ({cap_width},{cap_height}), fps: {cap_fps}')
if out_resize:
print(f'[ Output ] size: ({out_width},{out_height}), fps: {out_fps} ')
else:
print(f'[ Output ] size: ({cap_width},{cap_height}), fps: {out_fps} ')
print(f' video speed: x{out_fps/cap_fps}')
if not cap.isOpened():
raise RuntimeError(f'- [x] cap input: {cap_input} error happened.')
in_count = 0
while 1:
ret, frame = cap.read()
if not ret:
break
if out_resize:
frame = cv2.resize(frame, (out_width, out_height), interpolation=cv2.INTER_LINEAR)
in_count += 1
if save:
out.write(frame)
print(f'input_images: {in_count}')
out.release()
print('Done')