43 lines
977 B
Python
43 lines
977 B
Python
import asyncio
|
|
import os
|
|
import time
|
|
from datetime import datetime
|
|
|
|
|
|
def hhmmss(seconds):
|
|
x = time.strftime('%H:%M:%S', time.gmtime(seconds))
|
|
return x
|
|
|
|
|
|
async def screenshot(video, duration, sender):
|
|
if os.path.exists(f'{sender}.jpg'):
|
|
return f'{sender}.jpg'
|
|
time_stamp = hhmmss(int(duration)/2)
|
|
out = datetime.now().isoformat("-", "seconds")+".jpg"
|
|
cmd = ["ffmpeg",
|
|
"-ss",
|
|
f"{time_stamp}",
|
|
"-i",
|
|
f"{video}"
|
|
"-frames:v",
|
|
"1",
|
|
f"{out}"
|
|
"-y"
|
|
]
|
|
process = await asyncio.create_subprocess_exec(
|
|
*cmd,
|
|
stdout=asyncio.subprocess.PIPE,
|
|
stderr=asyncio.subprocess.PIPE
|
|
)
|
|
stdout, stderr = await process.communicate()
|
|
x = stderr.decode().strip()
|
|
y = stdout.decode().strip()
|
|
if os.path.isfile(out):
|
|
return out
|
|
else:
|
|
None
|
|
if os.path.isfile(out):
|
|
return out
|
|
else:
|
|
None
|