TTML, SMPTE-TT, and IMSC1
*************************
The TTML module adds support for Timed Text Markup Language (TTML) and
related profiles, including SMPTE Timed Text (SMPTE-TT) and Internet
Media Subtitles and Captions 1 (IMSC1) text or image subtitles. Import
the module before creating the player:
import "@castlabs/prestoplay/cl.ttml";
Supported features
==================
Supported attributes:
* "tt:begin"
* "tt:end"
* "tt:region"
* "tt:style"
* "ttp:cellResolution"
* "ttp:frameRate"
* "ttp:subFrameRate"
* "ttp:frameRateMultiplier"
* "ttp:tickRate"
* "tts:backgroundColor"
* "tts:color"
* "tts:direction"
* "tts:displayAlign"
* "tts:origin"
* "tts:extent"
* "tts:fontFamily"
* "tts:fontSize"
* "tts:fontWeight"
* "tts:fontStyle"
* "tts:lineHeight"
* "tts:opacity"
* "tts:padding"
* "tts:textAlign"
* "tts:textOutline"
* "tts:textShadow"
* "tts:unicodeBidi"
* "tts:writingMode"
* "tts:zIndex"
* "smpte:backgroundImage"
SMPTE-TT and IMSC1 support covers bitmap images, such as PNG images
encoded in Base64. Position the bitmap images by enclosing them in a
region.
Support for legacy manifests
============================
A well-designed TTML manifest defines a root container and vertical
cell definitions, which let the layout adjust to different sizes, such
as fullscreen mode. Some legacy manifests use pixels instead to define
region or font size, for example:
Lorem ipsum
For manifests like this, provide hints to the parser:
const playerConfig = {
// ...
ttml: {
containerWidth: 640,
containerHeight: 480,
fontSizeRadix: 16,
},
};
"containerWidth" and "containerHeight" convert a region's size and
position into percentages of the container. In this example, the "r1"
region's width becomes "80%" and its height becomes "10%"; its
x-position becomes "10%" and its y-position becomes "80%", so the
region is centered horizontally near the bottom of the container.
"fontSizeRadix" converts a font size into "em". In this example, the
cue font size becomes "1em". The HTML displayer then adjusts the
parent font size based on the video size. See "TextStyleConfiguration"
(https://players.castlabs.com/web/latest/docs/api/clpp.TextStyleConfiguration.md)
for details. Cues sized this way are responsive.
SMPTE-TT over HLS
=================
HTTP Live Streaming (HLS) doesn't support SMPTE-TT natively. Harmonic
(https://www.harmonicinc.com/) proposed an extension to the HLS
specification to work around this, described in SMPTE-TT Embedded in
ID3 for HTTP Live Streaming
(https://datatracker.ietf.org/doc/html/draft-smpte-id3-http-live-streaming-00).
The HlsSmpte plugin implements this extension. It extends the TTML
parser and works exclusively on Safari with native HLS playback — it
has no effect on the MSE-based player.
To use it:
1. Import the TTML module:
import "@castlabs/prestoplay/cl.ttml";
2. Import the HLS-SMPTE module:
import "@castlabs/prestoplay/cl.hlssmpte";
3. Enable the "config.hlssmpte.patchMetadataTrack" flag if recent
Safari versions fail to create the metadata track on load. As a
workaround, the plugin briefly switches to another audio track and
back to force Safari to create it. This flag is opt-in rather than
default because the workaround requires at least two audio tracks
and causes an audible track switch.
4. Adjust "config.hlssmpte.timestampOffset" if cues are time-shifted.
5. Provide placeholder text tracks using "config.remoteTextTracks".
Each placeholder must define "kind", "language", "mimeType", and an
optional "label". Omit "url" — the HlsSmpte plugin injects cues
from the metadata track. The language code must match the metadata
track's language codes, and the MIME type must be "text/vtt".
In the example below, "url" is omitted from each placeholder because
cues are delivered through the metadata track; the placeholders are
still needed to expose the language options.