Skip to content

Instantly share code, notes, and snippets.

@seanmavley
Created January 21, 2021 21:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanmavley/cea1ec05cc6fc895ae7d0f181dcceead to your computer and use it in GitHub Desktop.
Save seanmavley/cea1ec05cc6fc895ae7d0f181dcceead to your computer and use it in GitHub Desktop.
Generate thumbnails from list of .mp4 videos in folder
# run as
# python generate_thumbnails_from_video.py path/to/directory
import os
import sys
# using moviepy
from moviepy.editor import *
from PIL import Image
# directory of video files param
sourceDirectory = sys.argv[1]
directoryList = os.listdir(sourceDirectory)
for video in directoryList:
if video.endswith('.mp4'):
clip = VideoFileClip(sourceDirectory + '/' + video)
# getting only first 2 seconds
clip = clip.subclip(0, 2)
# saving a frame at 1 second
clip.save_frame("tempFile.png", t = 1)
# Convert to JPG
im = Image.open("tempFile.png")
rgb_im = im.convert('RGB').save(sourceDirectory + '/exports/' + video + '.jpg', quality=30)
print('processed', format(video))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment