我正在生成大量图像并将它们写入磁盘。然后我将文件名数组传递给ImageSequenceClip
. 一个主要瓶颈是将图像写入磁盘。有没有办法将图像保存在内存中,然后将其传递给ImageSequenceClip
,从而避免写入/读取磁盘所需的时间?
filenames = []
for i in range(0, FRAMES):
filename = "tmp/frame_%s.png" % (i)
filenames.append(filename)
center_x = IMG_WIDTH / 2
center_y = IMG_HEIGHT - ((IMG_HEIGHT - i * HEIGHT_INC) / 2)
width = IMG_WIDTH - i * WIDTH_INC
height = IMG_HEIGHT - i * HEIGHT_INC
img = vfx.crop(img_w_usr_img, x_center=center_x, y_center=center_y, width=width, height=height)
img = img.resize( (VID_WIDTH, VID_HEIGHT) )
img.save_frame(filename)
print "Proccessed: %s" % (filename)
seq = ImageSequenceClip(filenames, fps=FPS)