图片转视频 发表于 2017-09-27 | 更新于 2019-06-13 | 分类于 scripts 图片转视频将文件夹内的图片按图片名称顺序转为一个视频文件 12345678910111213141516171819202122232425262728# -*-coding:utf-8 -*-import cv2import numpy as npimport globimport 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()