From 47f88b1b65aa4416d321068449010901a891f14c Mon Sep 17 00:00:00 2001 From: imSp4rky Date: Fri, 30 Oct 2026 13:59:15 -0600 Subject: [PATCH] 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. --- tests/tracks/test_subtitle_convert.py | 38 +++++++++++++++++++++++++++ unshackle/core/tracks/subtitle.py | 5 ++++ 2 files changed, 43 insertions(+) diff --git a/tests/tracks/test_subtitle_convert.py b/tests/tracks/test_subtitle_convert.py index 1c231e61..15408dd7 100644 --- a/tests/tracks/test_subtitle_convert.py +++ b/tests/tracks/test_subtitle_convert.py @@ -16,6 +16,7 @@ import pathlib import re import struct +import pycaption import pytest from unshackle.core import binaries @@ -371,3 +372,40 @@ def test_segmented_fttml_parses_and_converts(tmp_path, monkeypatch): assert sub.codec == Codec.TimedTextMarkupLang out = sub.convert(Codec.SubRip, forced=True) assert cue_count(out) == 2 + + +def test_fttml_with_viewport_units_converts(tmp_path, monkeypatch): + """TTML2 ``vw``/``vh`` and ``rw``/``rh`` sizes, which pycaption rejects, still parse and convert. + + Only the size attributes pycaption parses are rewritten: a negative one becomes 0, while an ``rh`` + font size and the same units in cue text stay as they are. + """ + monkeypatch.setattr("unshackle.core.config.config.subtitle", {}, raising=False) + frag = ( + '' + '' + '