fix subtitle overlaps
This commit is contained in:
parent
0505631c0e
commit
5f0bc63684
1 changed files with 13 additions and 0 deletions
13
render.py
13
render.py
|
@ -313,6 +313,7 @@ def render(root, scene, prefix=''):
|
||||||
for timeline, data in scene.items():
|
for timeline, data in scene.items():
|
||||||
if timeline == "subtitles":
|
if timeline == "subtitles":
|
||||||
path = os.path.join(root, prefix + "front.srt")
|
path = os.path.join(root, prefix + "front.srt")
|
||||||
|
data = fix_overlaps(data)
|
||||||
srt = ox.srt.encode(data)
|
srt = ox.srt.encode(data)
|
||||||
write_if_new(path, srt, 'b')
|
write_if_new(path, srt, 'b')
|
||||||
continue
|
continue
|
||||||
|
@ -560,6 +561,17 @@ def get_srt(sub, offset=0):
|
||||||
sdata["out"] += offset
|
sdata["out"] += offset
|
||||||
return sdata
|
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):
|
def update_subtitles(options):
|
||||||
import item.models
|
import item.models
|
||||||
|
|
||||||
|
@ -592,6 +604,7 @@ def update_subtitles(options):
|
||||||
print("could not find vo for %s" % clip['src'])
|
print("could not find vo for %s" % clip['src'])
|
||||||
offset += clip['duration']
|
offset += clip['duration']
|
||||||
path = folder / "front.srt"
|
path = folder / "front.srt"
|
||||||
|
data = fix_overlaps(subs)
|
||||||
srt = ox.srt.encode(subs)
|
srt = ox.srt.encode(subs)
|
||||||
write_if_new(str(path), srt, 'b')
|
write_if_new(str(path), srt, 'b')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue