Skip to content

[TTML] Fix clock-time fractional seconds parsing - #2125

Merged
CastagnaIT merged 1 commit into
xbmc:Piersfrom
mediaminister:ttml
Oct 15, 2026
Merged

CastagnaIT merged 1 commit into
xbmc:Piersfrom
mediaminister:ttml

Conversation

@mediaminister

@mediaminister mediaminister commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes parsing of clock-time expressions with fractional seconds (hh:mm:ss.fraction) in TTML2SRT::GetTime. The digits after the decimal point were added to the timestamp as a raw integer, without taking their count or m_timescale into account. The fraction is now parsed as digits, padded to 9 digits (nanosecond precision, longer fractions are truncated) and scaled by m_timescale. Plain hh:mm:ss without a fraction is handled by its own branch.

Motivation and context

The TTML2 clock-time grammar allows hh:mm:ss.fraction, where the fraction is a fraction of a second with any number of digits. The old code treated the digits as an integer count of timescale units:

  • 00:00:01.5 gave 1 s + 5 units instead of 1.5 s
  • .05 and .5 both parsed to 5, so leading zeros were lost
  • the result was only correct by accident for exactly 3 digits at a timescale of 1000

This resulted in wrong cue timings for TTML subtitles with fractional seconds, whenever the fraction did not have exactly 3 digits or the timescale was not 1000.

How has this been tested?

Checked the parsing by hand with m_timescale = 1000 and m_timescale = 90000:

Input m_timescale Before After
00:00:01.5 1000 1005 1500
00:00:01.05 1000 1005 1050
00:00:01.050 1000 1050 1050
00:00:01.5 90000 90005 135000
00:00:01 1000 1000 1000

Tested with real TTML Dash in VRT MAX Add-on: https://github.com/add-ons/plugin.video.vrt.nu

Screenshots (if appropriate):

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • I have read the Contributing document
  • My code follows the Code Guidelines of this project
  • My change requires a change to the Wiki documentation
  • I have updated the documentation accordingly

Summary by CodeRabbit

  • Bug Fixes
    • Corrected subtitle timing for TTML clock times with fractional seconds, including fractions with fewer than nine digits.

@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 446efadd-4360-4a60-b83b-fab1537a4fd1
📥 Commits

Reviewing files that changed from the base of the PR and between 84bdb35 and 9ef9fbb.

📒 Files selected for processing: 1
  • src/codechandler/ttml/TTML.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

TTML clock-time parsing now reads fractional seconds to nanosecond precision, pads fractions shorter than nine digits, and scales them to the configured timescale.

Changes: TTML clock-time fraction parsing

Layer / File(s) Summary
Parse and scale clock-time fractions
src/codechandler/ttml/TTML.cpp
The fraction accumulator now stores fractional seconds. Clock-time fractions are padded to nine digits and scaled by m_timescale.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 9ef9f

Clock-time fractions are now scaled to the configured timescale. The inspected call paths keep the conversion within safe arithmetic bounds, and no concrete merge-blocking risk remains.

### Architecture Summary

Architecture risk: 🔵 Low · up to 9ef9f

The change affects 1 system.

Changed systems: src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/codechandler/ttml/TTML.cpp: The clock-time fraction accumulator changes from milliseconds to fractional seconds (fs).
  • observed — Modified behavior in src/codechandler/ttml/TTML.cpp: Clock-time fractions are now read with up to nine digits and padded to nanosecond precision before being scaled by m_timescale. Previously, the parsed fraction was added directly to the timestamp, regardless of timescale.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: fixing fractional-second parsing for TTML clock-time expressions.
Description check Passed The description covers the change, motivation, test results, change type, and checklist. It provides concrete examples and test environments. No critical section is missing.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR

@CastagnaIT CastagnaIT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks,
if you want you can do a PR backport to Omega

@CastagnaIT
CastagnaIT merged commit e7418d4 into xbmc:Piers Oct 15, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants