Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python imageio mp4 video from a set of png images

How do I make an mp4 video from a set of png images with the module imageio? I've tried this:

import imageio
import glob
writer = imageio.get_writer('test.mp4', fps=20)
for png_path in glob.glob('*.png'):
    im = imageio.imread(png_path),
    writer.append_data(im[:, :, 1])
writer.close()

I've also tried replacing im[:, :, 1] with im. What am I doing wrong? I'm happy to use another module.

like image 916
tommy.carstensen Avatar asked Dec 18 '22 02:12

tommy.carstensen


1 Answers

You don't need to modify the image through im[:, :, 1]. For example, the code below takes all images starting with name in a folder specified by path and creates a videofile called "test.mp4"

fileList = []
for file in os.listdir(path):
    if file.startswith(name):
        complete_path = path + file
        fileList.append(complete_path)

writer = imageio.get_writer('test.mp4', fps=20)

for im in fileList:
    writer.append_data(imageio.imread(im))
writer.close()

All images have to be the same size so you should resize them before appending them to the video file. You can modify the fps through fps, I just set it at 20 because I was following your code.

like image 197
Mr K. Avatar answered Jan 04 '23 23:01

Mr K.