From 69f8609c5bffdb43ceace164cafdb63e03d18ad5 Mon Sep 17 00:00:00 2001 From: Matthew Neil Date: Thu, 9 Feb 2017 11:08:05 -0500 Subject: [PATCH 1/2] parse x-timestamp-map --- lib/vtt.js | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/lib/vtt.js b/lib/vtt.js index 4642e77..85d82cc 100644 --- a/lib/vtt.js +++ b/lib/vtt.js @@ -1138,16 +1138,51 @@ } } - // 3.2 WebVTT metadata header syntax - function parseHeader(input) { - parseOptions(input, function (k, v) { - switch (k) { - case "Region": - // 3.3 WebVTT region metadata header syntax - parseRegion(v); + // draft-pantos-http-live-streaming-20 + // https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-3.5 + // 3.5 WebVTT + function parseTimestampMap(input) { + var settings = new Settings(); + + parseOptions(input, function(k, v) { + switch(k) { + case "MPEGT": + settings.integer(k + 'S', v); + break; + case "LOCA": + settings.set(k + 'L', parseTimeStamp(v)); break; } - }, /:/); + }, /[^\d]:/, /,/); + + self.ontimestampmap && self.ontimestampmap({ + "MPEGTS": settings.get("MPEGTS"), + "LOCAL": settings.get("LOCAL") + }); + } + + // 3.2 WebVTT metadata header syntax + function parseHeader(input) { + if (input.match(/X-TIMESTAMP-MAP/)) { + // This line contains HLS X-TIMESTAMP-MAP metadata + parseOptions(input, function(k, v) { + switch(k) { + case "X-TIMESTAMP-MAP": + parseTimestampMap(v); + break; + } + }, /=/); + } else { + parseOptions(input, function (k, v) { + switch (k) { + case "Region": + // 3.3 WebVTT region metadata header syntax + parseRegion(v); + break; + } + }, /:/); + } + } // 5.1 WebVTT file parsing. From 9864d0001ebc40ca9dff57650569677e0c3b7cba Mon Sep 17 00:00:00 2001 From: Matthew Neil Date: Wed, 1 Mar 2017 11:14:05 -0500 Subject: [PATCH 2/2] update README --- README.md | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a68c5a5..4353f46 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ This is a fork of vttjs with some changes that are used by Video.js. - [oncue(cue)](#oncuecue) - [onflush()](#onflush) - [onparsingerror(error)](#onparsingerrorerror) + - [ontimestampmap(timestampmap)](#ontimestampmaptimestampmap) - [WebVTT.convertCueToDOMTree(window, cuetext)](#webvttconvertcuetodomtreewindow-cuetext) - [WebVTT.processCues(window, cues, overlay)](#webvttprocesscueswindow-cues-overlay) - [ParsingError](#parsingerror) @@ -159,6 +160,17 @@ parser.onparsingerror = function(e) { }; ``` +####ontimestampmap(timestampmap)#### + +Is invoked when an `X-TIMESTAMP-MAP` metadata header ([defined here](https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-3.5)) is parsed. This header maps WebVTT cue timestamps to MPEG-2 (PES) timestamps in other Renditions of the Variant Stream. + +```js +parser.ontimestampmap = function(timestamp) { + console.log('LOCAL:', timestamp.LOCAL); + console.log('MPEGTS:', timestamp.MPEGTS); +}; +``` + ####WebVTT.convertCueToDOMTree(window, cuetext)#### Parses the cue text handed to it into a tree of DOM nodes that mirrors the internal WebVTT node structure of @@ -538,18 +550,18 @@ for the task. If you want to know more about `cue2json` you can run it directly like so: ```bash -$ ./bin/cue2json.js +$ ./bin/cue2json.js $ Generate JSON test files from a reference VTT file. $ Usage: node ./bin/cue2json.js [options] -$ +$ $ Options: -$ -v, --vtt Path to VTT file. +$ -v, --vtt Path to VTT file. $ -d, --dir Path to test directory. Will recursively find all JSON files with matching VTT files and rewrite them. -$ -c, --copy Copies the VTT file to a JSON file with the same name. -$ -p, --process Generate a JSON file of the output returned from the processing model. +$ -c, --copy Copies the VTT file to a JSON file with the same name. +$ -p, --process Generate a JSON file of the output returned from the processing model. ``` -**Notes:** +**Notes:** * `cue2json` utilizes the last development build done. This is why the Grunt `run` task is good as you don't have to remember to build it yourself. If you don't build it yourself then you could