render subtitles

This commit is contained in:
j 2023-11-14 17:48:55 +01:00
parent efd5e7310a
commit f00a023641
2 changed files with 20 additions and 1 deletions

View file

@ -99,9 +99,13 @@ class Command(BaseCommand):
if os.path.islink(target):
os.unlink(target)
os.symlink(src, target)
subs = []
for sub in vo.annotations.filter(layer="subtitles").exclude(value="").order_by("start"):
subs.append(sub.json(keys=['in', 'out', 'value']))
voice_over[fragment_id][batch] = {
"src": target,
"duration": source.duration
"duration": source.duration,
"subs": subs
}
with open(os.path.join(prefix, 'voice_over.json'), 'w') as fd:
json.dump(voice_over, fd, indent=2, ensure_ascii=False)

View file

@ -95,6 +95,7 @@ def compose(clips, target=150, base=1024, voice_over=None):
voice_overs.append(voice_over[vo2])
print("vo:", [x['src'] for x in voice_overs], list(sorted(voice_over)))
vo_min = sum([vo['duration'] for vo in voice_overs])
sub_offset = 0
if vo_min > target:
target = vo_min
elif vo_min < target:
@ -108,6 +109,8 @@ def compose(clips, target=150, base=1024, voice_over=None):
'duration': offset
})
vo_min += offset
sub_offset = offset
subs = []
for vo in voice_overs:
voc = vo.copy()
a, b = '3', '-6'
@ -124,6 +127,14 @@ def compose(clips, target=150, base=1024, voice_over=None):
vo_low = vo.copy()
vo_low['filter'] = {'volume': b}
scene['audio-rear']['A1'].append(vo_low)
for sub in voc.get("subs", []):
sub = sub.copy()
sub["in"] += sub_offset
sub["out"] += sub_offset
subs.append(sub)
sub_offset += voc["duration"]
if subs:
scene["subtitles"] = subs
clip = None
while target - length > 0 and clips:
@ -270,6 +281,10 @@ def render(root, scene, prefix=''):
files = []
scene_duration = int(get_scene_duration(scene) * 24)
for timeline, data in scene.items():
if timeline == "subtitles":
with open(os.path.join(root, prefix + "front.srt"), "wb") as fd:
fd.write(ox.srt.encode(data))
continue
#print(timeline)
project = KDEnliveProject(root)