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

View file

@ -142,6 +142,14 @@ for clip in edit:
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,