From f07318bea7f4f86821ab97b08d939d31621c8ec7 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 9 Aug 2017 16:40:28 +0200 Subject: [PATCH] use file for large edits --- ffmpeg.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) mode change 100644 => 100755 ffmpeg.py diff --git a/ffmpeg.py b/ffmpeg.py old mode 100644 new mode 100755 index e680d3e..7a6f526 --- a/ffmpeg.py +++ b/ffmpeg.py @@ -5,8 +5,8 @@ import subprocess import sys def run(cmd): - print(' '.join('"%s"' % c for c in cmd)) - #subprocess.call(cmd) + #print(' '.join('"%s"' % c for c in cmd)) + subprocess.call(cmd) edit_json = sys.argv[1] @@ -18,10 +18,12 @@ height = 270 aspect = 16/9 width = int(height * aspect) -n = 0 files = [] for clip in edit: - out = render + '/%06d.ts' % n + out = render + '/%s_%0.3f-%0.3f.ts' % (clip['oshash'], clip['in'], clip['out']) + files.append(out) + if os.path.exists(out): + continue clip_aspect = clip['resolution'][0] / clip['resolution'][1] if clip_aspect < aspect: x = width @@ -37,7 +39,7 @@ for clip in edit: vf += ',crop=w=%s:h=%s:x=0:y=%s' % (width, height, offset) options = [ '-vf', vf, - '-aspect', aspect, + '-aspect', str(aspect), '-c:v', 'libx264', '-b:v', '8M', '-r:v', '25', @@ -54,10 +56,11 @@ for clip in edit: '-t', str(clip['out'] - clip['in']), out ] - files.append(out) run(cmd) - n += 1 -files = '|'.join(files) -cmd = ['ffmpeg', '-y', '-i', 'concat:' + files, '-c', 'copy', output] +txt = output + '.txt' +with open(txt, 'w') as fd: + fd.write('file ' + '\nfile '.join(files)) +cmd = ['ffmpeg', '-y', '-f', 'concat', '-safe', '0', '-i', txt, '-c', 'copy', output] run(cmd) +os.unlink(txt)