fix subtitle overlaps

This commit is contained in:
j 2023-12-08 12:13:00 +00:00
parent 0505631c0e
commit 5f0bc63684

View file

@ -313,6 +313,7 @@ def render(root, scene, prefix=''):
for timeline, data in scene.items():
if timeline == "subtitles":
path = os.path.join(root, prefix + "front.srt")
data = fix_overlaps(data)
srt = ox.srt.encode(data)
write_if_new(path, srt, 'b')
continue
@ -560,6 +561,17 @@ def get_srt(sub, offset=0):
sdata["out"] += offset
return sdata
def fix_overlaps(data):
previous = None
for sub in data:
if previous is None:
previous = sub
else:
if sub['in'] < previous['out']:
previous['out'] = sub['in'] - 0.001
previous = sub
return data
def update_subtitles(options):
import item.models
@ -592,6 +604,7 @@ def update_subtitles(options):
print("could not find vo for %s" % clip['src'])
offset += clip['duration']
path = folder / "front.srt"
data = fix_overlaps(subs)
srt = ox.srt.encode(subs)
write_if_new(str(path), srt, 'b')