import os
import cv2
from PIL import Image
def makevideo(path, fps):""" 将图片合成视频. path: 视频路径,fps: 帧率 """fourcc = cv2.VideoWriter_fourcc(*'mp4v')path1 = r'F:\code1\auto_panorama\res_img\20'img_list = os.listdir(path1)im = Image.open(r'F:\code1\auto_panorama\res_img\20\1.jpg')print(im.size)vw = cv2.VideoWriter(path, fourcc, fps, im.size)for i in range(len(img_list)):frame = cv2.imread(path1 + '/' + str(i)+ ".jpg" )vw.write(frame)if __name__ == '__main__':video_path = './output2.mp4'makevideo(video_path, 10)
ffmpeg转图片为视频
ffmpeg -r 10 -f image2 -i output/img%d.png -s 448x256 -c:v libx264 -pix_fmt yuv420p output/demo.mp4 -q:v 0 -q:a 0
使用ffmpeg将图片转成gif
ffmpeg -r 10 -f image2 -i output/img%d.png -s 448x256 -vf "split[s0][s1];[s0]palettegen=stats_mode=single[p];[s1][p]paletteuse=new=1" output/demo.gif