Created
January 21, 2021 21:02
-
-
Save seanmavley/cea1ec05cc6fc895ae7d0f181dcceead to your computer and use it in GitHub Desktop.
Generate thumbnails from list of .mp4 videos in folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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