Skip to content

Commit

Permalink
feat: Support for vtt (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahlabs authored and forbesjo committed Dec 11, 2017
1 parent 42fc42e commit 96fc406
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
12 changes: 10 additions & 2 deletions src/toM3u8.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export const formatAudioPlaylist = ({ attributes, segments }) => {
};

export const formatVttPlaylist = ({ attributes, segments }) => {
if (segments === undefined) {
segments = [{
uri: attributes.url,
timeline: attributes.periodIndex,
resolvedUri: attributes.url || '',
duration: attributes.sourceDuration
}];
}
return {
attributes: {
NAME: attributes.id,
Expand Down Expand Up @@ -86,6 +94,7 @@ export const formatVideoPlaylist = ({ attributes, segments }) => {
attributes: {
NAME: attributes.id,
AUDIO: 'audio',
SUBTITLES: 'subs',
RESOLUTION: {
width: parseInt(attributes.width, 10),
height: parseInt(attributes.height, 10)
Expand Down Expand Up @@ -141,8 +150,7 @@ export const toM3u8 = dashPlaylists => {
master.mediaGroups.AUDIO.audio = organizeAudioPlaylists(audioPlaylists);
}

// TODO: vtt playlists not yet supported
if (vttPlaylists.length && false) {
if (vttPlaylists.length) {
master.mediaGroups.SUBTITLES.subs = organizeVttPlaylists(vttPlaylists);
}

Expand Down
20 changes: 14 additions & 6 deletions test/manifests/maat_vtt_segmentTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ export const parsedManifest = {
}
},
['CLOSED-CAPTIONS']: {},
// Subtitles feature is turned off
SUBTITLES: {},
/*
SUBTITLES: {
subs: {
en: {
Expand All @@ -118,7 +115,12 @@ export const parsedManifest = {
},
endList: true,
resolvedUri: 'https://example.com/en.vtt',
segments: undefined,
segments: [{
duration: 6,
resolvedUri: 'https://example.com/en.vtt',
timeline: 0,
uri: 'https://example.com/en.vtt'
}],
timeline: 0,
uri: ''
}],
Expand All @@ -136,20 +138,25 @@ export const parsedManifest = {
},
endList: true,
resolvedUri: 'https://example.com/es.vtt',
segments: undefined,
segments: [{
duration: 6,
resolvedUri: 'https://example.com/es.vtt',
timeline: 0,
uri: 'https://example.com/es.vtt'
}],
timeline: 0,
uri: ''
}],
uri: ''
}
}
},
*/
VIDEO: {}
},
playlists: [{
attributes: {
AUDIO: 'audio',
SUBTITLES: 'subs',
BANDWIDTH: 449000,
CODECS: 'avc1.420015',
NAME: '482',
Expand Down Expand Up @@ -194,6 +201,7 @@ export const parsedManifest = {
}, {
attributes: {
AUDIO: 'audio',
SUBTITLES: 'subs',
BANDWIDTH: 3971000,
CODECS: 'avc1.64001e',
NAME: '720',
Expand Down
5 changes: 1 addition & 4 deletions test/toM3u8.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ QUnit.test('playlists', function(assert) {
}
},
['CLOSED-CAPTIONS']: {},
// Subtitles feature is turned off
SUBTITLES: {},
/*
SUBTITLES: {
subs: {
text: {
Expand All @@ -113,12 +110,12 @@ QUnit.test('playlists', function(assert) {
}
}
},
*/
VIDEO: {}
},
playlists: [{
attributes: {
AUDIO: 'audio',
SUBTITLES: 'subs',
BANDWIDTH: 10000,
CODECS: 'foo;bar',
NAME: '1',
Expand Down

0 comments on commit 96fc406

Please sign in to comment.