fix(subtitles): accept TTML2 rw/rh and vw/vh sizes in fTTML conversion

pycaption rejects these units on extent/origin/padding, which failed every STPP track that uses them; rewrite them to % before parsing.
This commit is contained in:
imSp4rky
2026-10-30 13:59:15 -06:00
parent 17d4905577
commit 47f88b1b65
2 changed files with 43 additions and 0 deletions
+5
View File
@@ -752,6 +752,11 @@ class Subtitle(Track):
elif codec == Subtitle.Codec.TimedTextMarkupLang:
text = try_ensure_utf8(data).decode("utf8")
text = text.replace("tt:", "")
text = re.sub(
r"tts:(?:extent|origin|padding)=(\"[^\"]*\"|'[^']*')",
lambda m: re.sub(r"(?<=\d)[vr][wh]\b", "%", m[0]),
text,
)
# negative size values aren't allowed in TTML/DFXP spec, replace with 0
text = re.sub(r"-(\d+(?:\.\d+)?)(px|em|%|c|pt)", r"0\2", text)
caption_set = pycaption.DFXPReader().read(text)