Created
August 11, 2023 14:59
-
-
Save djshaji/92e87285da0dc832ad249b6096ae0b31 to your computer and use it in GitHub Desktop.
Generate thumbnail from video
This file contains hidden or 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
#!/usr/bin/python | |
# pip install ffmpeg-python | |
# puts a thumnail in .thumb folder | |
import ffmpeg | |
def thumbnail (filename, thumb): | |
time = 0 | |
width = 640 | |
try: | |
probe = ffmpeg.probe(filename) | |
except Exception as e: | |
print (e) | |
return | |
# print (probe) | |
time = 0 | |
if "duration" in probe ["streams"][0]: | |
time = (float)(probe ["streams"][0]['duration']) / 2 | |
elif "DURATION" in probe ["streams"][0]: | |
time = (float)(probe ["streams"][0]['DURATION']) / 2 | |
ffmpeg.input(filename, ss=time).filter('scale', width, -1).output(thumb, vframes=1).run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment