This repository has been archived on 2022-10-08. You can view files and clone it, but cannot push or open issues or pull requests.
memories/memories/collection/video.py

16 lines
707 B
Python

import subprocess
from PIL import Image
def get_thumbnail_from_video(path, checksum):
cmd = ["ffmpeg", "-y", f"-i", f"{path}", "-vframes", "1", "-vf", "scale=480:-2", "-q:v", "3", f"/tmp/{checksum}-thumb-320.jpg"]
subprocess.call(cmd)
image = Image.open(f"/tmp/{checksum}-thumb-320.jpg")
play = Image.open("/home/fmartingr/Code/memories/memories/collection/play.png")
play = play.resize((round(play.size[0] * 0.5), round(play.size[1] * 0.5)))
image.paste(
play, (int(image.size[0] / 2 - play.size[0] / 2), int(image.size[1] / 2 - play.size[1] / 2)), play
)
image.save(f"/tmp/{checksum}-thumb-320.jpg")
return open(f"/tmp/{checksum}-thumb-320.jpg", "rb").read()