close

How to make a movie out of images in python

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to make a movie out of images in python in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to make a movie out of images in python?

  1. How to make a movie out of images in python?

    I'm attaching below a code snipped I used to combine all png files from a folder called “images” into a video.

  2. make a movie out of images in python

    I'm attaching below a code snipped I used to combine all png files from a folder called “images” into a video.

Method 1

I’m attaching below a code snipped I used to combine all png files from a folder called “images” into a video.

import cv2
import os

image_folder = 'images'
video_name = 'video.avi'

images = [img for img in os.listdir(image_folder) if img.endswith(".png")]
frame = cv2.imread(os.path.join(image_folder, images[0]))
height, width, layers = frame.shape

video = cv2.VideoWriter(video_name, 0, 1, (width,height))

for image in images:
    video.write(cv2.imread(os.path.join(image_folder, image)))

cv2.destroyAllWindows()
video.release()

It seems that the most commented section of this answer is the use of VideoWriter. You can look up it’s documentation in the link of this answer (static) or you can do a bit of digging of your own. The first parameter is the filename, followed by an integer (fourcc in the documentation, the codec used), the FPS count and a tuple of the dimensions of the frame. If you really like digging in that can of worms

Method 2

Thanks , but i found an alternative solution using ffmpeg:

def save():
    os.system("ffmpeg -r 1 -i img%01d.png -vcodec mpeg4 -y movie.mp4")

But thank you for your help 🙂

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read