imageio 图片转mp4
FFMPEG: pip install imageio[ffmpeg]
pyav: pip install imageio[pyav]
import glob
import os
import cv2
import imageio
from natsort import natsorted
from PIL import Image
import numpy as np
import orjson
if __name__ == '__main__':
dir_root=r'/lpai/volumes/ad-op-ga/vis/dongdong/lmdb_0817_2_res'
dir_save=r'/lpai/volumes/ad-op-ga/vis/dongdong/lmdb_0817_2_mp4'
dirs=glob.glob(dir_root+'/*/*')
for dir_path in dirs:
img_files = ['%s/%s' % (i[0].replace("\\","/"), j) for i in os.walk(dir_path) for j in i[-1] if j.endswith(('.jpg', 'apng', 'ajpeg'))]
print("len(img_files)",len(img_files),dir_path)
img_files=natsorted(img_files)
imgs=[]
for img_i, img_path in enumerate(img_files):
print(img_path)
output_image = Image.open(img_path)
imgs.append(output_image)
save_dir=dir_path.replace(dir_root,dir_save)
os.makedirs(save_dir,exist_ok=True)
imageio.mimsave(f'{save_dir}/pinjie.mp4',imgs,fps=6)
# imageio.mimwrite(save_path, output_images, fps=self.fps)
原文地址:https://blog.csdn.net/jacke121/article/details/143599801
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!