import moviepy.editor as mp
import numpy as np
from PIL import Image
def create_thumbnails(video_path, output_path, number=60, width=160, height=90, columns=10):
# Load the video
video = mp.VideoFileClip(video_path)
# Calculate the interval between thumbnails
duration = video.duration
interval = duration / number
# Create a list to store the thumbnails
thumbnails = []
for i in range(number):
# Get the frame at the specific time
frame = video.get_frame(i * interval)
# Convert the frame to an image
img = Image.fromarray(frame)
# Resize the image
img = img.resize((width, height))
thumbnails.append(img)
# Create a blank image to paste the thumbnails
rows = (number + columns - 1) // columns
result_img = Image.new('RGB', (columns * width, rows * height))
for i, thumbnail in enumerate(thumbnails):
x = (i % columns) * width
y = (i // columns) * height
result_img.paste(thumbnail, (x, y))
# Save the result image
result_img.save(output_path)
# Example usage
create_thumbnails('output.mp4', 'output_thumbnail.jpg')