Mercurial > code > home > repos > video
view thumbnail.py @ 46:882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
author | drewp@bigasterisk.com |
---|---|
date | Fri, 06 Dec 2024 01:16:54 -0800 |
parents | 7cacfae58430 |
children |
line wrap: on
line source
import asyncio from tempfile import NamedTemporaryFile import pymongo.collection import logging log = logging.getLogger('thumb') async def getThumbnailData(coll: pymongo.collection.Collection, diskPath: str) -> bytes: doc=coll.find_one({'diskPath':diskPath}) if doc is None: raise Exception(f"no thumb found for {diskPath}") return doc['thumbData'] async def createThumbnail(coll: pymongo.collection.Collection, diskPath: str): if coll.find_one({'diskPath':diskPath}): return coll.delete_one({'diskPath':diskPath}) # diskPath could be a YT sidecar file? thumbFile = NamedTemporaryFile(suffix='.jpg') log.info(f'createThumbnail: {diskPath=} to {thumbFile.name=}') proc = await asyncio.create_subprocess_exec('ffmpegthumbnailer', '-s', '250', '-i', diskPath, '-o', thumbFile.name) await proc.wait() if proc.returncode != 0: log.error(f'createThumbnail: {proc.returncode=}') return thumbFile.seek(0) imgData = thumbFile.read() log.info(f'createThumbnail: {len(imgData)=}') coll.insert_one({'diskPath':diskPath,'thumbData':imgData})