Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating thumbnails from video files with Python

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.

like image 384
Alterlife Avatar asked Nov 20 '09 19:11

Alterlife


People also ask

How do you make a thumbnail from a video in Python?

You can use ffmpeg-python to create a thumbnail and upload it for use with your video. If you don't want to get into learning FFMPEG, you can also use api. video's endpoint that allows you to pick a time from the video, and have it set as the video thumbnail for you automatically.

How do you make a thumbnail in Python?

In the above code, we first import PIL library. Then we create thumbnails() function, where we use open() function to open the image file, which returns an object. We call thumbnail() function on this image object and input thumbnail size of 100px x 90px. Next, we call save() function to save the image as thumbnail.


2 Answers

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]) 
like image 62
Tobias Ernst Avatar answered Sep 23 '22 18:09

Tobias Ernst


You can use ffvideo

from ffvideo import VideoStream pil_image = VideoStream('0.flv').get_frame_at_sec(5).image() pil_image.save('frame5sec.jpeg') 
like image 25
zakhar Avatar answered Sep 23 '22 18:09

zakhar