Creating thumbnails from video files with Python

Alterlife picture Alterlife · Nov 20, 2009 · Viewed 25.7k times · Source

I need to create thumbnails for a video file once I've uploaded to a webapp running python.

How would I go about this... I need a library that can basically either do this for me, or that can read the image frames out of video files (of several formats) automatically.

Answer

Tobias Ernst picture Tobias Ernst · Oct 9, 2017

I could not install ffvideo on OSX Sierra so i decided to work with ffmpeg.

OSX:

brew install ffmpeg

Linux:

apt-get install ffmpeg

Python 3 Code:

import subprocess
video_input_path = '/your/video.mp4'
img_output_path = '/your/image.jpg'
subprocess.call(['ffmpeg', '-i', video_input_path, '-ss', '00:00:00.000', '-vframes', '1', img_output_path])