Captions class provides API for parsing and manipulating subtitle and captions objects.
Guesses subtitle codec/format based on url
url
(String): url to subtitles
(String): subtitle codec/format ("srt", "webvtt", etc.)
Captions.guessSubtitleCodec("http://server/url/to/subs.srt");
// => "srt"
Downloads and parses subtitles given a url.
List of subtitle and closed caption formats currently supported by the player:
- DLP Cinema (Cinecanvas 1.1 XML, UTF-8/16)
- EBU (STL)
- Cavena 890
- Web VTT
- TTML
timeline
(Timeline
):Player Timeline
object to align subtitles tourl
(String): url to subtitlescodec
(String): subtitle type. Available codecs:srt
,webvtt
,stl
,c890
,dcsubs
callback
(Function): callback function to execute when the subtitles are parsedlogLevel
(LogLevel
): optional logging level, seeLogLevel
excludeLastFrame
(Boolean): optional parameter to exclude last frame for each subtitle, supported by TTML parser only!
var codec = Captions.guessSubtitleCodec("http://server/url/to/subs.srt");
Captions.parseSubs(player.getTimeline(), "http://server/url/to/subs.srt", codec, function(err, subs) {
if (err) {
console.error("error parsing subs", err);
return;
}
console.log("subs parsed", subs);
});
var codec = Captions.guessSubtitleCodec("http://server/url/to/subs.srt");
Captions.parseSubs(player.getTimeline(), "http://server/url/to/subs.srt", codec, function(err, subs) {
if (err) {
console.error("error parsing subs", err);
return;
}
console.log("subs parsed", subs);
}, VG.LogLevel.INFO, false);
Offsets subtitles by specified time value
captions
(Subtitles
): source subtitle object to offsetoffsetTv
(Integer): timevalue to offset bytimeline
(Timeline
):Player Timeline
object to align subtitles to
var codec = Captions.guessSubtitleCodec("http://server/url/to/subs.srt");
Captions.parseSubs(player.getTimeline(), "http://server/url/to/subs.srt", codec, function(err, subs) {
if (err) return console.error("error parsing subs", err);
Captions.offsetCaptions(subs, 42042, player.getTimeline());
console.log("subs are offset by 42042", subs);
});
--
Subtitles
object represents one imported subtitle or captions file into the player
Property | Description | Type |
---|---|---|
id |
Id of the subtitle object | String |
rows |
Array of subtitle entries representing timed text | Array of SubtitleEntry objects |
title |
Human readable name of the represented subtitles (e.g. filename.srt ) |
String |
SubtitleEntry
object represents a single text entry on player timeline
Property | Description | Type |
---|---|---|
startMsec |
Millisecond relative to current video at which subtitle text should appear | Integer |
endMsec |
Millisecond at which text should disappear | Integer |
startTv |
Timevalue relative to current video at which subtitle text should appear | Integer |
endTv |
Timevalue relative to current video at which subtitle text should disappear | Integer |
timeCodeIn |
Tape timecode string relative to start tape timecode at which subtitle text should appear | String |
timeCodeOut |
Tape timecode string relative to start tape timecode at which subtitle text should disappear | String |
notes |
Text of the subtitle | String |
red |
Attention of user should be drawn to current subtitle entry | Boolean |
{
"startMsec": 660,
"endMsec": 1650,
"startTv": 60060,
"endTv": 150150,
"timeCodeIn": "00:58:02:00",
"timeCodeOut": "00:58:05:00",
"notes": "hello world",
"red": true
}