Final version
This commit is contained in:
42
helpers.py
Normal file
42
helpers.py
Normal file
@@ -0,0 +1,42 @@
|
||||
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
|
||||
Reference in New Issue
Block a user