Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse x-timestamp-map #4

Merged
merged 2 commits into from
Mar 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
51 changes: 43 additions & 8 deletions lib/vtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, ontimestampmap is a method on the parser that will be called with the MPEGTS and LOCAL times? Does it mean that the user still needs to manually shift all the timestamps by this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the user would have to manually shift the timestamps. The timestamp map tag only gives a mapping from cue time to TS time, but the mapping from TS to display time is still needed for the shift. I think this approach is the easiest instead of storing state on the parse for the extra mapping

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm... maybe it's the best option; it just seems to be only half complete this way.

"MPEGTS": settings.get("MPEGTS"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is hilarious.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And by this, I mean LOCA and MPEGT.

"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.
Expand Down