- 导包
import os import cv2
- 获取图片列表
pic_path = '/<path>/pics/out' pics_list = [i for i in os.listdir(pic_path) if i.endswith('.jpg')]
- 定义视频变量
fps = 1.1 # size = (1140, 640) # 视频尺寸 out_file_name = '{0}.mp4'.format('示例视频') # 输出视频名称 out_path = '/<path>/pics/out' # 输出视频路径 out_file = os.path.join(out_path, out_file_name)
-
fourcc = cv2.VideoWriter_fourcc('D', 'I', 'V', 'X') video = cv2.VideoWriter(out_file, fourcc, fps, size)
-
for item in pics_list: item = out_path + '/' + item img = cv2.imread(item) video.write(img)
- 保存视频
video.release()