don't merge subtitles into one per clip

This commit is contained in:
j 2021-08-12 11:41:38 +02:00
parent 9bd581cb46
commit 3f603ae136
2 changed files with 24 additions and 12 deletions

18
edit.py
View file

@ -214,15 +214,20 @@ if __name__ == '__main__':
subtitles = [] subtitles = []
position = 0 position = 0
for clip in sort_clips(edit, sort_by): for clip in sort_clips(edit, sort_by):
clip_out = position + clip['duration']
clip_subtitles = [] clip_subtitles = []
for sub in clip['layers'].get('subtitles', []): for sub in clip['layers'].get('subtitles', []):
value = sub['value'].replace('<br/>', '\n').replace('<br>', '\n').replace('\n\n', '\n')
subtitles.append({ subtitles.append({
'in': position, 'in': max(position, position + sub['in'] - clip['in']),
'out': position + (sub['out'] - sub['in']), 'out': min(position + sub['out'] - clip['in'], clip_out),
'value': sub['value'].replace('<br/>', '\n').replace('<br>', '\n').replace('\n\n', '\n'), 'value': value,
})
clip_subtitles.append({
'in': max(0, sub['in'] - clip['in']),
'out': min(sub['out'] - clip['in'], clip['out'] - clip['in']),
'value': value,
}) })
clip_subtitles.append(sub['value'].replace('<br/>', '\n').replace('<br>', '\n').replace('\n\n', '\n'))
part_pos = 0 part_pos = 0
for i, duration in enumerate(clip['durations']): for i, duration in enumerate(clip['durations']):
@ -251,11 +256,10 @@ if __name__ == '__main__':
'in': stream_in, 'in': stream_in,
'out': stream_out, 'out': stream_out,
'volume': clip.get('volume', 1), 'volume': clip.get('volume', 1),
'subtitles': clip_subtitles
}) })
if 'path' in info: if 'path' in info:
videos[-1]['path'] = os.path.join(prefix, info['path']) videos[-1]['path'] = os.path.join(prefix, info['path'])
if clip_subtitles:
videos[-1]['subtitles'] = '\n'.join(clip_subtitles)
part_pos += duration part_pos += duration
position += clip['duration'] position += clip['duration']

View file

@ -142,11 +142,19 @@ for clip in edit:
if abs(src_duration-duration) > 1: if abs(src_duration-duration) > 1:
print(clip.get('annotation', clip['item']), 'expected', src_duration, 'got', duration, out) print(clip.get('annotation', clip['item']), 'expected', src_duration, 'got', duration, out)
if clip.get('subtitles'): if clip.get('subtitles'):
subtitles.append({ if isinstance(clip['subtitles'], list):
'in': position, for sub in clip['subtitles']:
'out': position+duration, subtitles.append({
'value': clip['subtitles'] 'in': position + sub['in'],
}) 'out': position + sub['out'],
'value': sub['value']
})
else:
subtitles.append({
'in': position,
'out': position + duration,
'value': clip['subtitles']
})
position += duration position += duration
txt = output + '.txt' txt = output + '.txt'