subtitle formating
This commit is contained in:
parent
73922d537d
commit
bb9f8fc445
1 changed files with 11 additions and 5 deletions
|
|
@ -1,10 +1,11 @@
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import ox
|
|
||||||
import lxml.etree
|
import lxml.etree
|
||||||
|
import ox
|
||||||
|
|
||||||
from .render_kdenlive import melt_xml
|
from .render_kdenlive import melt_xml
|
||||||
|
from .utils import format_duration
|
||||||
|
|
||||||
|
|
||||||
def parse_lang(lang):
|
def parse_lang(lang):
|
||||||
|
|
@ -57,16 +58,20 @@ def get_clip_by_seqid(clips, seqid):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_scene_duration(scene):
|
def get_scene_duration(scene, fps=24, track=None):
|
||||||
if isinstance(scene, str):
|
if isinstance(scene, str):
|
||||||
with open(scene) as fd:
|
with open(scene) as fd:
|
||||||
scene = json.load(fd)
|
scene = json.load(fd)
|
||||||
duration = 0
|
duration = 0
|
||||||
for key, value in scene.items():
|
for key, value in scene.items():
|
||||||
for name, clips in value.items():
|
for name, clips in value.items():
|
||||||
|
if track and '%s:%s' % (key, name) != track:
|
||||||
|
continue
|
||||||
|
if clips:
|
||||||
for clip in clips:
|
for clip in clips:
|
||||||
duration += int(clip["duration"] * 24)
|
duration += round(clip["duration"] * fps)
|
||||||
return duration / 24
|
#print("scene duration based on %s:%s is %s %s" % (key, name, duration / fps, format_duration(duration / fps, fps)))
|
||||||
|
return duration / fps
|
||||||
|
|
||||||
|
|
||||||
def get_offset_duration(prefix):
|
def get_offset_duration(prefix):
|
||||||
|
|
@ -183,6 +188,7 @@ Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour,
|
||||||
stop = ass_timestamp(sub["out"])
|
stop = ass_timestamp(sub["out"])
|
||||||
for lang in reversed(langs):
|
for lang in reversed(langs):
|
||||||
value = sub["values"][lang]
|
value = sub["values"][lang]
|
||||||
|
value = value.replace('\n', '\\N')
|
||||||
event = f"Dialogue: 0,{start},{stop},{lang},,0,0,0,,{value}"
|
event = f"Dialogue: 0,{start},{stop},{lang},,0,0,0,,{value}"
|
||||||
events.append(event)
|
events.append(event)
|
||||||
ass += "\n\n[Events]\n" + "\n".join(events) + "\n"
|
ass += "\n\n[Events]\n" + "\n".join(events) + "\n"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue