video is now generated in memory

This commit is contained in:
Askill 2020-09-19 23:23:01 +02:00
parent 5f2d3e890d
commit 434d6df1e4
2 changed files with 7 additions and 3 deletions

View File

@ -5,7 +5,7 @@ import random
import imageio import imageio
import glob import glob
import os import os
import numpy as np
def getRandomColorString(): def getRandomColorString():
return '#{:06x}'.format(random.randint(0, 256**3)) return '#{:06x}'.format(random.randint(0, 256**3))
@ -27,6 +27,7 @@ outputPath = os.path.join(dirname, 'out.mp4')
# creating new Image object # creating new Image object
def genImages(): def genImages():
counter = 0 counter = 0
writer = imageio.get_writer(outputPath, fps=fps)
for i in range(numberOfEvents): for i in range(numberOfEvents):
objectWidth = (5 + random.randint(0, 5)) * xmax / 100 objectWidth = (5 + random.randint(0, 5)) * xmax / 100
@ -52,7 +53,10 @@ def genImages():
img1 = ImageDraw.Draw(img) img1 = ImageDraw.Draw(img)
img1.rectangle(objectShape, fill = color) img1.rectangle(objectShape, fill = color)
img.save( imagesPath + str(counter).zfill(6) + imageType) #img.save( imagesPath + str(counter).zfill(6) + imageType)
writer.append_data(np.array(img))
writer.close()
def makeVideo(): def makeVideo():
fileList = [] fileList = []
@ -72,5 +76,5 @@ def deleteImages():
os.remove(f) os.remove(f)
genImages() genImages()
makeVideo() #makeVideo()
#deleteImages() #deleteImages()

Binary file not shown.