TTML Time Format and Precision
When processing TTML files, the most common point of failure is not the content but the timing: Why is there a letter after `12.340s`? Can it be written as `00:00:12.340`? How many decimal places can be specified? These details determine whether the file can be correctly parsed. Another crucial distinction that often causes confusion is—Time precision (how detailed the time specification is) is not the same as time accuracy (whether the values are correct).A file with millisecond-level precision may, if its values are merely estimates, actually perform worse in real-world timing than a manual file with precision limited to hundredths of a second. This page clarifies the relationship between TTML time formatting and these two concepts.
direction for use
Two valid ways to write time in TTMML
The first type isclock time`00:00:12.340`, read as "hour: minute: second. millisecond"; both the hour and minute fields should be padded to two digits, while the second field may include a decimal part. The second type isOffset time relative to the unit`12.340s`: Simply write the number of seconds and append the letter `s` at the end as the unit marker. Both formats are valid, and the parser must support both—this means that if you are writing a TTML parser that only recognizes one of these formats, it will fail to parse the time when encountering the other format. In addition to `s` (seconds), the standard also defines unit markers such as `h` (hours), `m` (minutes), and `ms` (millisecond), but in actual lyric files, you will almost always see only `s`.
Why does the SEC have an "s" suffix?
Because TTML's temporal syntax allows mixing different units, the letter `s` is used to eliminate ambiguity. Bare numbers without unit markers in TTML have no fixed meaning—they can be interpreted as frame counts or scale values, depending on the settings of parameters like "ttp:frameRate" at the beginning of the file. Therefore, the `s` in `12.340s` is not an optional decoration; if removed, the file may still be valid XML, but the timing will be interpreted in a different unit, leading to incorrect timing across the entire lyric track. This is fundamentally different from LRC, where the timestamp format is fixed, and there is no issue with units.
Precision: LRC to hundredths of a second, TTMML to milliseconds
The timestamp in LRC is denoted as `[分:秒.百分秒]`, meaning its finest resolution is 0.01 seconds. In contrast, timestamps in TTMML can be expressed in milliseconds, or 0.001 seconds, which is one hundred times finer than LRC. However, it should be clearly stated:This difference in precision is virtually irrelevant in the context of this tool's use case.When the input is LRC, all time values are inherently precise only to the hundredth of a second. Converting them to TTML merely involves replacing `12.34` with `12.340s`——— the trailing zero is a formatting adjustment and does not indicate improved precision. Scenarios where millisecond precision is truly necessary include manually typing out tracks word by word, recording in milliseconds, or directly obtaining millisecond-level time points from audio analysis.
High precision = accurate targeting (the most common point of misunderstanding)
These are two distinct concepts.accuracyIt refers to "how finely one can write."accuracyIt refers to "how close this value is to the actual moment." A TTML file generated with equal distribution of characters, where the timing for each character is recorded to three decimal places (e.g., `12.347s`), may appear highly precise, but these values are merely estimates derived from division——— in actual performance, that character might not even begin until `12.512s`, with a discrepancy of 165 milliseconds, which can be easily detected with one ear. Conversely, a manually annotated file (`12.51s`) that only specifies percentages and seconds, with values accurate to 10 milliseconds, can actually exhibit much higher accuracy because it is annotated by human listeners. Therefore, to assess the quality of a lyric file,What matters is how the time was derived, rather than how many decimal places it contains.。
frequently asked questions
- Will writing more decimal places make the result more accurate?
- No. Adding extra decimal places merely allows you to "express the details more granularly"; it does not bring the numerical values closer to the actual values. If the original data is only precise to hundredths of a second (e.g., from LRC), converting it to milliseconds simply involves appending zeros; however, if the values were derived from averaging, adding extra decimal places could instead create a false impression of precision. The appropriate mindset is to use only as many decimal places as are necessary, with the primary focus being on whether the data source is reliable.
- Can the two ways of writing time be used interchangeably?
- Grammatically, it is permissible for a single file to contain both `12.340s` and `00:00:12.340`. However, this practice is strongly discouraged—using both styles in hand-written or script-generated code can easily lead to errors during subsequent processing due to inconsistent parsing rules. It is recommended that the entire file adhere to a consistent style; this tool consistently uses the offset style with the suffix `s`.
- Why is my time display showing strange values?
- In most cases, the unit specification has been lost, causing the time to be interpreted using a different unit. Check the following two points: whether there is an `s` suffix following the second value; and, if a clock format is used, whether the hours and minutes are padded to two digits. Additionally, verify that the parameters at the beginning of the file (e.g., frame rate-related attributes) have not overridden the default units—especially if you have copied the file header from another source, as you may have inadvertently carried over the time parameters from that source.
- How is the timestamp for the final line determined during generation?
Since there is no "next line" to reference at the end of the line, its end position requires a default value. The processing logic of this tool is as follows:Extend the final line by several seconds.(Adjustable on the page; defaults to 3 seconds) – this setting prevents the lyrics from disappearing abruptly immediately after the final line appears. This duration does not affect the timing accuracy of any individual line; it only determines how long the final line remains visible. If you find that the final line disappears too quickly or stays visible for too long, simply adjust this value.
- Could the time value become negative or exceed its bounds?
- Under normal circumstances, this will not occur. The time offsets of LRC are relative, starting from zero and increasing progressively; after conversion, they are directly mapped to seconds, and negative values will not appear. The only consideration is "trailing line extension" —if the extension value is set to an extremely large value (e.g., 30 seconds) while the audio itself is short, the player may still attempt to display lyrics after the audio has ended. In most players, this manifests as the lyrics remaining on the screen; this is not an error, but it can create an odd visual effect.