Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Add support for description audio tracks in HLS #1019

Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 13 additions & 3 deletions docs/multiple-alternative-audio-tracks.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The mapping between `AudioTrack` and the parsed m3u8 file is fairly straight fo

As you can see m3u8's do not have a property for `AudioTrack.id`, which means that we let `video.js` randomly generate the id for `AudioTrack`s. This will have no real impact on any part of the system as we do not use the `id` anywhere.

The other property that does not have a mapping in the m3u8 is `AudioTrack.kind`. It was decided that we would set the `kind` to `main` when `default` is set to `true` and in all other cases we set it to `alternative`
The other property that does not have a mapping in the m3u8 is `AudioTrack.kind`. It was decided that we would set the `kind` to `main` when `default` is set to `true` and in other cases we set it to `alternative` unless the track has `characteristics` which include `public.accessibility.describes-video`, in which case we set it to `main-desc` (note that this `kind` indicates that the track is a mix of the main track and description, so it can be played *instead* of the main track; a track with kind `description` *only* has the description, not the main track).

Below is a basic example of a mapping
m3u8 layout
Expand All @@ -27,8 +27,13 @@ m3u8 layout
lang: 'eng'
},
'audio-track-2': {
default: true,
default: false,
lang: 'fr'
},
'audio-track-3': {
default: false,
lang: 'eng',
characteristics: 'public.accessibility.describes-video'
}
}]
}
Expand All @@ -48,6 +53,12 @@ Corresponding AudioTrackList when media-group-1 is used (before any tracks have
language: 'fr',
kind: 'alternative',
id: 'random'
}, {
label: 'audio-tracks-3',
enabled: false,
language: 'eng',
kind: 'main-desc',
id: 'random'
}]
```

Expand Down Expand Up @@ -83,4 +94,3 @@ Corresponding AudioTrackList when media-group-1 is used (before any tracks have
1. `MasterPlaylistController` maps the `label` to the `PlaylistLoader` containing the audio
1. `MasterPlaylistController` turns on that `PlaylistLoader` and the Corresponding `SegmentLoader` (master or audio only)
1. `MediaSource`/`mux.js` determine how to mux

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"dependencies": {
"aes-decrypter": "1.0.3",
"global": "^4.3.0",
"m3u8-parser": "2.0.1",
"m3u8-parser": "2.1.0",
"mux.js": "4.1.0",
"url-toolkit": "^1.0.4",
"video.js": "^5.17.0",
Expand Down
19 changes: 18 additions & 1 deletion src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ export class MasterPlaylistController extends videojs.EventTarget {
let properties = mediaGroups.AUDIO[mediaGroup][label];
let track = new videojs.AudioTrack({
id: label,
kind: properties.default ? 'main' : 'alternative',
kind: this.audioTrackKind_(properties),
enabled: false,
language: properties.language,
label
Expand All @@ -568,6 +568,23 @@ export class MasterPlaylistController extends videojs.EventTarget {
})[0] || this.activeAudioGroup()[0]).enabled = true;
}

/**
* Convert the properties of an HLS track into an audioTrackKind.
*
* @private
*/
audioTrackKind_(properties) {
let kind = properties.default ? 'main' : 'alternative';

if (properties.characteristics) {
if (properties.characteristics.indexOf('public.accessibility.describes-video') >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor, but can just have one conditional:

if (properties.characteristics &&
    properties.characteristics.indexOf('public.accessibility.describes-video') >= 0)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure - I wasn't sure how to deal with the line getting too long! I'll change that.

kind = 'main-desc';
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible for there to be two tracks with 'public.accessibility.describes-video' (something like an alt-desc)?

Copy link
Member Author

Choose a reason for hiding this comment

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

In theory that's possible; I'd assume it would need to follow the same rules as, say, a CAPTIONS or SUBTITLES tracks:

https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-4.3.4.1.1:

All EXT-X-MEDIA tags in a Playlist MUST meet the following
constraints:

o All EXT-X-MEDIA tags in the same Group MUST have different NAME
attributes.

o A Group MUST NOT have more than one member with a DEFAULT
attribute of YES.

o All members of a Group whose AUTOSELECT attribute has a value of
YES MUST have LANGUAGE [RFC5646] attributes with unique values.

So you could tell them apart by name (label) and language. But it wouldn't change the audio track's kind. Is that what you were wondering about?

}
}

return kind;
}

/**
* Call load on our SegmentLoaders
*/
Expand Down