Python MoviePy Convert Different Size Images (PNG, JPG) to Video – Python MoviePy Tutorial

By | March 19, 2021

In python moviepy, we can use ImageSequenceClip() function to convert a serial of images to a video. However, this method needs all image should be the same size. Can python moviepy convert images with different width and height to a video?

concatenate_videoclips()

Python moviepy concatenate_videoclips() method can allow us to convert images with different width and height to a video. It can concatenate several video clips.

It will use two methods to concatenate images:

method=”chain”: will produce a clip that simply outputs the frames of the succesive clips, without any correction if they are not of the same size of anything.

method=”compose”, if the clips do not have the same resolution, the final resolution will be such that no clip has
to be resized.

We will use an example to show you how to use this method.

Convert different size images (PNG, JPG) to video using python moviepy

We should import some packages first.

from moviepy.editor import *

Then, we will use some images to create some video clips.

files = ['1.png', '2.png', '3.png', '4.png']
frames = [ImageClip(f, duration = 4) for f in files]

You should notice: duration = 4 means each image is 4 seconds. There are 4 images in this example, the total time of the final video is 4*4 = 16 seconds.

Use concatenate_videoclips() to concatenate video clips above.

clip = concatenate_videoclips(frames, method = "chain")
clip.write_videofile("video.mp4", fps = 24)

Here we use chain method to compose video clips, you also can use compose method.

However, the effect may be not good if your images are poor quality.

python moviepy convert png images to video

 

Leave a Reply