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.
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.
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.
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])
You can use ffvideo
from ffvideo import VideoStream pil_image = VideoStream('0.flv').get_frame_at_sec(5).image() pil_image.save('frame5sec.jpeg')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With