Skip to content

Instantly share code, notes, and snippets.

@AalbatrossGuy
Created May 15, 2025 05:44
Show Gist options
  • Select an option

  • Save AalbatrossGuy/193d2db84066e2f1018c84d298937067 to your computer and use it in GitHub Desktop.

Select an option

Save AalbatrossGuy/193d2db84066e2f1018c84d298937067 to your computer and use it in GitHub Desktop.
How to create thumbnail of a video in python using OpenCV & moviepy
from dotenv import load_dotenv
from moviepy import VideoFileClip
import cv2
def create_thumbnail(file) -> None:
video = VideoFileClip(f"{os.getenv('path/to/video.mp4')}") # Get the video from storage.
filenoext = file.rsplit('.', 1)[0] # Get the filename without the extension ['mp4', 'mov', 'mkv', etc.]
get_frame = video.get_frame(3) # Get the 3rd frame from the video. You can choose the frame you need. Getting a single frame from the video helps in memory efficiency as the video doesn't need to be loaded in memory completely.
cv2.imwrite(f"{os.getenv('path/to/save/image.jpg')}", get_frame) # Save the frame to the desired path.
# Don't load the whole video in memory unless it's a lightweight video.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment