My Coding >
Programming language >
Python >
Exercise >
Python: How to make video from images
Python: How to make video from imagesstep by step making video from imagesVery common problem, convert series of images, taken for example with some interval, into a video. Of course, it is possible to use some third party programs, but today I will explain how to make video from images with python scripts. Libraries for making video from imagesNumpy - it is necessary to represent image an a numpy array for adding to video-library CV2 - OpenCV (Open Source Computer Vision Library) is an open-source library that includes several hundreds of computer vision algorithms, and one of them is an algorithm of making video. PIL – Pillow library to working with existing images
Let’s assume, that all our file names are stored in the list data and this list already sorted by the time of images should linked to the video. How to read content of the directory into a list I will tell somewhere else. I will not do any checks, to be sure that files are exists and all images are the same size etc. I will assume, that all given files are perfect Identify image size and create video dataLet’s read first image into a PIL object and check size of this object.
Now we need to select codec for making video. I prefer to use mp4v codec. And we need to think about preferable Frame Per Second rate for our video, let’s use 30, which is pretty common
And finally, it is time to initialize our video object
Reading and combining images into a videoWe will read every image and add it to video data structure
Very simple script Full python script to make video from imagesAll code in one place:
|
Last 10 artitles
9 popular artitles
|
|
© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit. |