fix subtitle rendering

This commit is contained in:
j 2024-05-22 10:46:26 +02:00
parent eb1ea250eb
commit ad33ce2c41

View file

@ -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'