python 制作视频

python制作视频

import os
import cv2
from PIL import Image

def makevideo(path, fps):
    """ 将图片合成视频. path: 视频路径,fps: 帧率 """
    fourcc = cv2.VideoWriter_fourcc(*"MJPG")
    images = os.listdir('./tu4')
    im = Image.open('./tu4/' + images[0])
    print(im.size)
    vw = cv2.VideoWriter(path, fourcc, fps, im.size)

    for image in tqdm(range(0, data.shape[0])):
        imgfile = str(image + 1) + '.png'
        try:
            #读取图片
            frame = cv2.imread('./tu4/%d.png'%image)
            vw.write(frame)
        except Exception as exc:
            print(imgfile, exc)
    vw.release()

if __name__ == '__main__':
    video_path = 'test_new_ppt_16fps.avi'
    makevideo(video_path, 16)  # 图片转视频

你可能感兴趣的:(python 制作视频)