Skip to content

Commit

Permalink
Issue #19: uploading video files with delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekmo committed Mar 22, 2019
1 parent 0451638 commit 1083a39
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions telegram_upload/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ def video_metadata(file):
def get_video_thumb(file, output=None, width=90):
output = output or tempfile.NamedTemporaryFile(suffix='.jpg').name
metadata = video_metadata(file)
duration = metadata.get('duration').seconds if metadata.has('duration') else 0
p = subprocess.Popen([
'ffmpeg', '-i', file,
'-ss', str(int((0, metadata.get('duration').seconds)[metadata.has('duration')] / 2)),
'-filter:v', 'scale={}:-1'.format(width),
'-vframes', '1',
'ffmpeg',
'-ss', str(int(duration / 2)),
'-i', file,
'-filter:v',
'scale={}:-1'.format(width),
'-vframes:v', '1',
output,
], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
p.communicate()
Expand Down

0 comments on commit 1083a39

Please sign in to comment.