Skip to content

Instantly share code, notes, and snippets.

@djshaji
Created August 11, 2023 14:59
Show Gist options
  • Save djshaji/92e87285da0dc832ad249b6096ae0b31 to your computer and use it in GitHub Desktop.
Save djshaji/92e87285da0dc832ad249b6096ae0b31 to your computer and use it in GitHub Desktop.
Generate thumbnail from video
#!/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