The simplest way to convert images (PNG, JPG) to a video is use ImageSequenceClip() method. In this tutorial, we will use an example to show you how to implement it.
ImageSequenceClip()
ImageSequenceClip() is defined as:
ImageSequenceClip(sequence, fps=None, durations=None, with_mask=True, ismask=False, load_images=False)
Here
sequence: images
fps: Number of picture frames to read per second.
durations: List of the duration of each picture.
You should notice:
If fps is not none, durations will be computed as:
durations = [1.0/fps for image in sequence]
Convert images (PNG, JPG) to video using python moviepy
We will use ImageSequenceClip() to convert some images to a video.
Here is an example:
from moviepy.editor import * files = ['1.png', '2.png', '3.png', '4.png'] clip = ImageSequenceClip(files, fps = 4) clip.write_videofile("video.mp4", fps = 24)
Run this code, you may get this error:
Moviepy: ImageSequenceClip requires all images to be the same size
In order to fix this error, you can do:
1.Convert all images to be the same size, here is a tutorial:
Best Pracice to Python Resize Images with Pillow – Python Tutorial
2.Use python moviey concatenate_videoclips() function. Here is a tutorial:
Python MoviePy Convert Different Size Images (PNG, JPG) to Video – Python MoviePy Tutorial
However, if all images size are same, you can use example code above.