commit 62831c5067126fefaa2d7c0289c07e00ec84b0eb Author: j Date: Wed Aug 9 12:30:58 2017 +0200 minimal editing system diff --git a/ffmpeg.py b/ffmpeg.py new file mode 100644 index 0000000..e680d3e --- /dev/null +++ b/ffmpeg.py @@ -0,0 +1,63 @@ +#!/usr/bin/python3 +import json +import os +import subprocess +import sys + +def run(cmd): + print(' '.join('"%s"' % c for c in cmd)) + #subprocess.call(cmd) + + +edit_json = sys.argv[1] +edit = json.load(open(edit_json)) + +render = '/tmp/out' +output = '/tmp/test.mp4' +height = 270 +aspect = 16/9 +width = int(height * aspect) + +n = 0 +files = [] +for clip in edit: + out = render + '/%06d.ts' % n + clip_aspect = clip['resolution'][0] / clip['resolution'][1] + if clip_aspect < aspect: + x = width + y = int(x / clip_aspect) + else: + y = height + x = int(y * clip_aspect) + vf = 'scale=%s:%s' % (x, y) + if x != width: + vf += ',crop=%s:%s' % (width, height) # crop center + elif y != height: + offset = int((y - height) / 2) + vf += ',crop=w=%s:h=%s:x=0:y=%s' % (width, height, offset) + options = [ + '-vf', vf, + '-aspect', aspect, + '-c:v', 'libx264', + '-b:v', '8M', + '-r:v', '25', + '-c:a', 'aac', + '-ar', '48000', + '-ac', '2', + '-b:a', '192k', + ] + cmd = [ + 'ffmpeg', + '-ss', str(clip['in']), + '-i', clip['path'] + ] + options + [ + '-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] +run(cmd)