fourcc = cv2.VideoWriter_fourcc('D', 'I', 'V', 'X') 对应格式 mp4
其他编码格式
CV_FOURCC('P','I','M','1') = MPEG-1 codec
CV_FOURCC('M','J','P','G') = motion-jpeg codec
CV_FOURCC('M', 'P', '4', '2') = MPEG-4.2 codec
CV_FOURCC('D', 'I', 'V', '3') = MPEG-4.3 codec
CV_FOURCC('D', 'I', 'V', 'X') = MPEG-4 codec
CV_FOURCC('U', '2', '6', '3') = H263 codec
CV_FOURCC('I', '2', '6', '3') = H263I codec
CV_FOURCC('F', 'L', 'V', '1') = FLV1 codec
#!/usr/bin/env python
# -*-coding:utf-8-*-
import cv2
import os
from tqdm import tqdm
fsp = 25
fourcc = cv2.VideoWriter_fourcc('D', 'I', 'V', 'X')
//https://blog.csdn.net/zj360202/article/details/79026891
# for n in range(4):
n = 0
video_path = './1-camrea{}.mp4'.format(n)
img_path = "D:\\data_test\\1\\Camera{}\\".format(n)
list_image = os.listdir('D:\\data_test\\1\\Camera{}\\'.format(n))
list_image.sort()
list_image = [os.path.join(img_path,x) for x in list_image]
width = cv2.imread(list_image[0]).shape[1]
heighth = cv2.imread(list_image[0]).shape[0]
video_out = cv2.VideoWriter(video_path, fourcc, fsp, (width,heighth))
print(len(list_image))
count = 0
for i in tqdm(range(len(list_image))):
if os.path.exists(list_image[i]):
frame = cv2.imread(list_image[i])
video_out.write(frame)
count += 1
print('cout',count)
video_out.release()