From cd2fe0cf8ac4b5b667f45c4b854596b5c92da709 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 2 Mar 2017 22:10:14 +0100 Subject: [PATCH] chop --- encode.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/encode.py b/encode.py index 7251ad9..ce98399 100755 --- a/encode.py +++ b/encode.py @@ -1,9 +1,25 @@ #!/usr/bin/python3 from glob import glob import os +import json import shutil import subprocess +def get_videoduration(video): + cmd = [ + 'ffprobe', + '-show_format', + '-show_chapters', + '-show_streams', + '-print_format', 'json', + '-i', video + ] + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stdin = p.communicate() + data = json.loads(stdout.decode()) + duration = float([s for s in data['streams'] if 'width' in s][0]['duration']) - 10/60 + return '%0.3f' % duration + for xml in sorted(glob('output/*/*.xml')): if xml.endswith('.audio.xml'): continue @@ -35,4 +51,15 @@ for xml in sorted(glob('output/*/*.xml')): os.unlink(audio) shutil.move(pre, mp4) ''' - shutil.move(video, mp4) + duration = get_videoduration(video) + cmd = [ + 'ffmpeg', '-y', + '-i', video, + '-c:a', 'copy', + '-c:v', 'copy', + '-t', duration, + pre + ] + subprocess.call(cmd) + os.unlink(video) + shutil.move(pre, mp4)