Skip to content

Latest commit

 

History

History
130 lines (102 loc) · 5.34 KB

Captions.md

File metadata and controls

130 lines (102 loc) · 5.34 KB

Captions class

Captions class provides API for parsing and manipulating subtitle and captions objects.

Captions Class Methods

Captions Class Methods

Captions.guessSubtitleCodec(url)

Guesses subtitle codec/format based on url

Arguments

  1. url (String): url to subtitles

Returns

(String): subtitle codec/format ("srt", "webvtt", etc.)

Example

Captions.guessSubtitleCodec("http://server/url/to/subs.srt");
// => "srt"

Captions.parseSubs(timeline, url, codec, callback, [logLevel])

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

Arguments

  1. timeline (Timeline): Player Timeline object to align subtitles to
  2. url (String): url to subtitles
  3. codec (String): subtitle type. Available codecs: srt, webvtt, stl, c890, dcsubs
  4. callback (Function): callback function to execute when the subtitles are parsed
  5. logLevel (LogLevel): optional logging level, see LogLevel
  6. excludeLastFrame (Boolean): optional parameter to exclude last frame for each subtitle, supported by TTML parser only!

Example

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);

Captions.offsetCaptions(captions, offsetTv, timeline)

Offsets subtitles by specified time value

Arguments

  1. captions (Subtitles): source subtitle object to offset
  2. offsetTv (Integer): timevalue to offset by
  3. timeline (Timeline): Player Timeline object to align subtitles to

Example

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

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

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

Example SubtitleEntry JSON

{
    "startMsec": 660,
    "endMsec": 1650,
    "startTv": 60060,
    "endTv": 150150,
    "timeCodeIn": "00:58:02:00",
    "timeCodeOut": "00:58:05:00",
    "notes": "hello world",
    "red": true
}