Skip to content

fix: default DFXP tick rate to 1 when no frame rate is given - #472

Open
kevincommits wants to merge 1 commit into
pbs:mainfrom
kevincommits:fix/dfxp-default-tickrate
Open

kevincommits wants to merge 1 commit into
pbs:mainfrom
kevincommits:fix/dfxp-default-tickrate

Conversation

@kevincommits

Copy link
Copy Markdown

DFXPReader reads tick times (5t) 30 times too fast when the document sets neither ttp:tickRate nor ttp:frameRate.

from pycaption import DFXPReader
xml = ('<?xml version="1.0"?><tt xmlns="http://www.w3.org/ns/ttml" xml:lang="en">'
       '<body><div><p begin="5t" end="12t">Hello</p></div></body></tt>')
c = DFXPReader().read(xml).get_captions("en")[0]
print(c.start, c.end)

Today this prints 166666 400000. Expected is 5000000 12000000. TTML1 section 6.2.10 (ttp:tickRate) says that when no frame rate is specified either, the tick rate is one tick per second of media time. The repo's own ai_artifacts/specs/dfxp/dfxp_specs_summary.md (RULE-PAR-005) says the same.

Tick support came in with #392, which computes the default as frameRate x subFrameRate and applies the 30 fps default frame rate even when the document has no ttp:frameRate. This pull request changes that one case, so please say if 30 was wanted there.

The fix uses frameRate x subFrameRate only when ttp:frameRate is present on <tt> and falls back to 1 otherwise. Documents with an explicit ttp:tickRate or ttp:frameRate read exactly as before, and frame-based times still default to 30 fps. DFXP_DEFAULT_TICKRATE, the value a reader holds before it reads a document, is untouched.

The new test in tests/test_dfxp.py reads a document with tick times and no rate parameters and checks the begin and end times. It fails on main and passes with the fix.

Ran: pytest (1429 passed, Python 3.12), and pre-commit run --files on the two changed files (ruff and ruff-format pass).

Not run: the Docker-based run_tests.sh and the Python 3.10 and 3.11 jobs.

The version bump and changelog are left to you, as on earlier outside fixes.

@kevincommits
kevincommits requested a review from a team as a code owner December 3, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant