fix subtitles
This commit is contained in:
parent
88e1cf8837
commit
6da2cc58c0
1 changed files with 24 additions and 2 deletions
|
|
@ -115,6 +115,28 @@ def shift_clips(data, offset):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def ass_timestamp(seconds):
|
||||||
|
hours = int(seconds // 3600)
|
||||||
|
minutes = int((seconds % 3600) // 60)
|
||||||
|
secs = seconds % 60
|
||||||
|
|
||||||
|
whole_seconds = int(secs)
|
||||||
|
centiseconds = int(round((secs - whole_seconds) * 100))
|
||||||
|
|
||||||
|
# Handle centisecond rollover (e.g., 59.999 → 60.00)
|
||||||
|
if centiseconds == 100:
|
||||||
|
whole_seconds += 1
|
||||||
|
centiseconds = 0
|
||||||
|
if whole_seconds == 60:
|
||||||
|
whole_seconds = 0
|
||||||
|
minutes += 1
|
||||||
|
if minutes == 60:
|
||||||
|
minutes = 0
|
||||||
|
hours += 1
|
||||||
|
|
||||||
|
return f"{hours}:{minutes:02d}:{whole_seconds:02d}.{centiseconds:02d}"
|
||||||
|
|
||||||
|
|
||||||
def ass_encode(subs, options):
|
def ass_encode(subs, options):
|
||||||
if "lang" in options:
|
if "lang" in options:
|
||||||
langs = options["lang"].split(",")
|
langs = options["lang"].split(",")
|
||||||
|
|
@ -157,8 +179,8 @@ Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour,
|
||||||
"Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"
|
"Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"
|
||||||
]
|
]
|
||||||
for sub in subs:
|
for sub in subs:
|
||||||
start = ox.format_timecode(sub["in"]).rstrip("0")
|
start = ass_timestamp(sub["in"])
|
||||||
stop = ox.format_timecode(sub["out"]).rstrip("0")
|
stop = ass_timestamp(sub["out"])
|
||||||
for lang in reversed(langs):
|
for lang in reversed(langs):
|
||||||
value = sub["values"][lang]
|
value = sub["values"][lang]
|
||||||
event = f"Dialogue: 0,{start},{stop},{lang},,0,0,0,,{value}"
|
event = f"Dialogue: 0,{start},{stop},{lang},,0,0,0,,{value}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue