diff --git a/ffmpeg.py b/ffmpeg.py index 4946fb3..1f19a9a 100755 --- a/ffmpeg.py +++ b/ffmpeg.py @@ -11,6 +11,22 @@ def run(cmd): #print(' '.join('"%s"' % c for c in cmd)) subprocess.call(cmd) +def add_subtitles(subtitles, clip, position, duration): + if clip.get('subtitles'): + if isinstance(clip['subtitles'], list): + for sub in clip['subtitles']: + subtitles.append({ + 'in': position + sub['in'], + 'out': position + sub['out'], + 'value': sub['value'] + }) + else: + subtitles.append({ + 'in': position, + 'out': position + duration, + 'value': clip['subtitles'] + }) + usage = "usage: %(prog)s [options] edit.json" parser = ArgumentParser(usage=usage) @@ -62,12 +78,7 @@ for clip in edit: src_duration = clip['out']-clip['in'] if abs(src_duration-duration) > 1: print(clip.get('annotation', clip['item']), 'expected', src_duration, 'got', duration, out) - if clip.get('subtitles'): - subtitles.append({ - 'in': position, - 'out': position+duration, - 'value': clip['subtitles'] - }) + add_subtitles(subtitles, clip, position, duration) position += duration continue src_info = ox.avinfo(clip['path']) @@ -142,20 +153,7 @@ for clip in edit: src_duration = clip['out']-clip['in'] if abs(src_duration-duration) > 1: print(clip.get('annotation', clip['item']), 'expected', src_duration, 'got', duration, out) - if clip.get('subtitles'): - if isinstance(clip['subtitles'], list): - for sub in clip['subtitles']: - subtitles.append({ - 'in': position + sub['in'], - 'out': position + sub['out'], - 'value': sub['value'] - }) - else: - subtitles.append({ - 'in': position, - 'out': position + duration, - 'value': clip['subtitles'] - }) + add_subtitles(subtitles, clip, position, duration) position += duration txt = output + '.txt'