图片转视频

图片转视频

将文件夹内的图片按图片名称顺序转为一个视频文件

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
# -*-coding:utf-8 -*-
import cv2
import numpy as np
import glob
import sys

__author__ = 'Heroinlj <heroinlj@gmail.com>'


def image2video(image_folder, save_video_name):
video_result = cv2.VideoWriter(save_video_name,
cv2.VideoWriter_fourcc('X', 'V', 'I', 'D'),
25, frameSize=(320, 288), isColor=True)
for image_path in sorted(glob.glob("{}/*.jpg".format(image_folder))):
image = cv2.imdecode(np.fromfile(image_path, dtype=np.uint8), 1)
video_result.write(image)


def main():
image_folder = sys.argv[1]
save_video_name = sys.argv[2]
# image_folder = r"./images"
# save_video_name = "result.avi"
image2video(image_folder, save_video_name)


if __name__ == '__main__':
main()