import cv2
import os
# Set the duration of each image in the video (in seconds)
image_duration = 5
# Set the frame rate of the video (frames per second)
fps = 30
# Set the directory containing the images
image_dir = 'image'
# /image/ thumbnail.jpg , thumbnail2.jpg, thumbnail3.jpg, thumbnail4.jpg
# Get a list of the images in the directory
image_paths = [os.path.join(image_dir, f) for f in os.listdir(image_dir)]
# Sort the images by file name
image_paths.sort()
# Set the size of the output video
width = 1280
height = 720
# Set the fourcc code for the video codec
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
# Create a VideoWriter object for the output video
out = cv2.VideoWriter('video.mp4', fourcc, fps, (width, height))
# Calculate the number of frames to generate for each image
num_frames = fps * image_duration
# Iterate through the images, converting each to a series of frames in the video
for image_path in image_paths:
# Load the image
image = cv2.imread(image_path)
# Resize the image to the desired size
image = cv2.resize(image, (width, height))
# Write the image to the video for the specified number of frames
for i in range(num_frames):
out.write(image)
# Release the VideoWriter object
out.release()
Python 3 OpenCV Script for Custom Video Creation from Images