WebVTT and SRT¶
Code samples
SRT subtitles: side-loaded SRT subtitles.
The VTT module adds support for WebVTT subtitles and SubRip (SRT) files.
Files with the text/srt, application/x-subrip, or text/plain MIME type
are converted to WebVTT internally. Import the module before creating the
player:
import "@castlabs/prestoplay/cl.vtt";
Supported features¶
Inline text formatting
Voice spans
Ruby characters
Text direction
Text alignment
Positioning
Size
Regions
Embedded styles
SubRip (SRT) subtitles¶
SRT files are usually side-loaded next to the stream. Import the VTT module
and add the file as a remote text track with the text/srt MIME type:
import { clpp } from "@castlabs/prestoplay";
import "@castlabs/prestoplay/cl.mse";
import "@castlabs/prestoplay/cl.dash";
import "@castlabs/prestoplay/cl.vtt";
const player = new clpp.Player("video", {});
await player.open({
source: "https://testcontent.castlabs.com/QA/tos_1080_clear/manifest.mpd",
remoteTextTracks: [
{
url: "https://demo.cf.castlabs.com/media/TOS/TOS-ml.srt",
mimeType: "text/srt",
kind: "subtitles",
language: "mal",
label: "Malayalam",
},
],
preferredTextLanguage: "mal",
});
preferredTextLanguage selects the track when playback starts. To switch
tracks later, use the TrackManager (see
Tracks and languages).
The SRT conversion has these requirements and limitations:
The file must be UTF-8 encoded.
Each cue must start with a numeric identifier, followed by a timestamp line in the
00:00:23,000 --> 00:00:24,500format and the cue text. The player drops cues without an identifier.The player removes HTML formatting tags such as
<i>and<b>from the cue text, so cues render as plain text.