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)