-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjpg2avi.py
More file actions
30 lines (22 loc) · 859 Bytes
/
jpg2avi.py
File metadata and controls
30 lines (22 loc) · 859 Bytes
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
import cv2
import os
# TODO:无法在win10下安装video decoder,没找到合适的包,在Ubuntu18.04下可转可用
def img2vedio(img_size, img_dir, video_path, fps):
format = cv2.VideoWriter_fourcc(*'XVID')
video_write = cv2.VideoWriter(video_path, format, fps, img_size)
for idx in (os.listdir(img_dir)):
# img = os.path.join(img_dir, idx)
frame = cv2.imread(img_dir + idx)
# print(frame.shape)
video_write.write(frame)
video_write.release()
print(f'finish changing, saving in {video_path}')
if __name__ == '__main__':
img_dir = 'path/to/your/img'
par_path = os.path.dirname(img_dir)
file = os.path.split(img_dir)[-1]
filename = 'out.avi'
video_path = 'path/to/your/save/video.avi'
fps = 3.0
img_size = (640, 512)
img2vedio(img_size, img_dir, video_path, fps)