Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Generate thumbnails from list of .mp4 videos in folder
# run as
# python 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 ="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