python批量图片转视频并保存到本地

fps = 4 # 帧率
num = 25 #文件夹里图片的数量
img_array = []
img_width = 1470
img_height = 1108
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter(r'C:\Users\animn\Desktop\aaaa1.mp4', fourcc, fps, (img_width, img_height))
for i in range(0, num):
    filename = r"C:\Users\animn\Desktop\data\tem/" + str(i) +".jpg"
    img = cv2.imread(filename)
    if img is None:
        print(filename + " is non-existent!")
        continue
    img_array.append(img)
for i in range(len(img_array)):
    out.write(img_array[i])
out.release()

如果保存下来播放不了,调一下fps,也要看一下 cv2.VideoWriter里面的img_width, img_height是否写反了,

你可能感兴趣的:(Python,python)