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

feat: Caption services (608/708) metadata #1138

Merged
merged 19 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ Video.js Compatibility: 6.0, 7.0
- [cacheEncryptionKeys](#cacheencryptionkeys)
- [handlePartialData](#handlepartialdata)
- [liveRangeSafeTimeDelta](#liverangesafetimedelta)
- [captionServices](#captionservices)
- [Format](#format)
- [Example](#example)
- [Runtime Properties](#runtime-properties)
- [vhs.playlists.master](#vhsplaylistsmaster)
- [vhs.playlists.media](#vhsplaylistsmedia)
Expand Down Expand Up @@ -466,6 +469,45 @@ This option defaults to `false`.
* Default: [`SAFE_TIME_DELTA`](https://github.com/videojs/http-streaming/blob/e7cb63af010779108336eddb5c8fd138d6390e95/src/ranges.js#L17)
* Allow to re-define length (in seconds) of time delta when you compare current time and the end of the buffered range.

##### captionServices
* Type: `object`
* Default: undefined
* Allow to override instream captions like 608 and 708 to provide labels or languaages.
gkatsev marked this conversation as resolved.
Show resolved Hide resolved

The captionServices options object has properties that map to the caption services. Each property is an object itself that includes several properties, like a label or language.

For 608 captions, the service names are `CC1`, `CC2`, `CC3`, and `CC4`. For 708 captions, the service names are `SERVICEn` where `n` is a digit between `1` and `63`.
###### Format
```js
{
vhs: {
captionServices: {
[serviceName]: {
language: String,
label: String
}
}
}
}
```
###### Example
```js
{
vhs: {
captionServices: {
CC1: {
language: 'en',
label: 'English'
},
SERVICE1: {
langauge: 'kr',
label: 'Korean'
}
}
}
}
```

### Runtime Properties
Runtime properties are attached to the tech object when HLS is in
use. You can get a reference to the VHS source handler like this:
Expand Down
19 changes: 15 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"aes-decrypter": "3.1.2",
"global": "^4.4.0",
"m3u8-parser": "4.7.0",
"mpd-parser": "0.16.0",
"mpd-parser": "0.17.0",
"mux.js": "5.11.0",
"video.js": "^6 || ^7"
},
Expand Down
20 changes: 18 additions & 2 deletions src/util/text-tracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,28 @@ export const createCaptionsTrackIfNotExists = function(inbandTextTracks, tech, c
// in the m3u8 for us to use
inbandTextTracks[captionStream] = track;
} else {
const captionServices = tech.options_.vhs && tech.options_.vhs.captionServices || {};
gkatsev marked this conversation as resolved.
Show resolved Hide resolved
let label = captionStream;
let language = captionStream;
let instreamId = captionStream;

// we need to translate SERVICEn for 708 to how mux.js currently labels them
if (/^cc708_/.test(captionStream)) {
instreamId = 'SERVICE' + captionStream.split('_')[1];
}

if (captionServices[instreamId]) {
label = captionServices[instreamId].label;
language = captionServices[instreamId].language;
}

// Otherwise, create a track with the default `CC#` label and
// without a language
inbandTextTracks[captionStream] = tech.addRemoteTextTrack({
kind: 'captions',
id: captionStream,
label: captionStream
id: instreamId,
label,
language
}, false).track;
}
}
Expand Down