前一阵查到一个用python生成视频的脚本,记录一下:
脚本如下:
import os
import cv2
import numpy as np
def getImagePathListFromRoot(root,shuffle=False):
pathList=[]
for dirPath, dirNames, fileNames in os.walk(root):
for file in fileNames:
if file.split(’.’)[-1].lower() in {‘bmp’, ‘png’, ‘jpg’, ‘jpeg’, }:
imagePath = os.path.join(dirPath, file)
pathList.append(imagePath)
if shuffle:
np.random.shuffle(pathList)
return pathList
def makeVideo():
path = ‘.’
#filelist = os.listdir(path)
filelist = getImagePathListFromRoot( path, True )
print(filelist)
fps = 1 #视频每秒1帧
size = (3840, 2748) #需要转为视频的图片的尺寸, 可以使用cv2.resize()进行修改