Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# pip install pillow opencv-python opencv-contrib-python
import os
import sys
import cv2
from PIL import Image
video_name = 'myVideo.avi';
image_folder = './images'; # C:\\Python\\MyDirectory
fps = 10;
def generate_video():
# os.chdir( global_path );
images = [img for img in os.listdir(image_folder)
if img.endswith(".jpg") or
img.endswith(".jpeg") or
img.endswith("png")]
# exit();
images.sort();
# print(images);
frame = cv2.imread(os.path.join(image_folder, images[0]))
# setting the frame width, height width
# the width, height of first image
height, width, layers = frame.shape
video = cv2.VideoWriter(video_name, 0, fps, (width, height));
# Appending the images to the video one by one
for image in images:
video.write(cv2.imread(os.path.join(image_folder, image)))
# Deallocating memories taken for window creation
cv2.destroyAllWindows()
video.release() # releasing the video generated
print(' Done ...');
# Calling the generate_video function
generate_video()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment