Skip to content

Commit bc0872a

Browse files
feat: add CODECS attribute to subtitle playlists if it exists (#106)
1 parent 26924c0 commit bc0872a

File tree

5 files changed

+432
-7
lines changed

5 files changed

+432
-7
lines changed

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<body>
88
<p>Open dev tools to try it out</p>
99
<ul>
10-
<li><a id="test/debug.html">Run unit tests in browser.</a></li>
11-
<li><a id="docs" href="docs/api/">Read generated docs.</a></li>
10+
<li><a href="test/debug.html">Run unit tests in browser.</a></li>
11+
<li><a href="docs/api/">Read generated docs.</a></li>
1212
</ul>
1313

1414
<form id=parse>

src/toM3u8.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,18 @@ export const formatVttPlaylist = ({ attributes, segments }) => {
105105
// targetDuration should be the same duration as the only segment
106106
attributes.duration = attributes.sourceDuration;
107107
}
108+
109+
const m3u8Attributes = {
110+
NAME: attributes.id,
111+
BANDWIDTH: attributes.bandwidth,
112+
['PROGRAM-ID']: 1
113+
};
114+
115+
if (attributes.codecs) {
116+
m3u8Attributes.CODECS = attributes.codecs;
117+
}
108118
return {
109-
attributes: {
110-
NAME: attributes.id,
111-
BANDWIDTH: attributes.bandwidth,
112-
['PROGRAM-ID']: 1
113-
},
119+
attributes: m3u8Attributes,
114120
uri: '',
115121
endList: (attributes.type || 'static') === 'static',
116122
timeline: attributes.periodIndex,

test/index.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { parse, VERSION } from '../src';
22
import QUnit from 'qunit';
33

4+
QUnit.dump.maxDepth = Infinity;
5+
46
// manifests
7+
import vttCodecsTemplate from './manifests/vtt_codecs.mpd';
58
import maatVttSegmentTemplate from './manifests/maat_vtt_segmentTemplate.mpd';
69
import segmentBaseTemplate from './manifests/segmentBase.mpd';
710
import segmentListTemplate from './manifests/segmentList.mpd';
@@ -31,6 +34,10 @@ import {
3134
parsedManifest as locationsManifest
3235
} from './manifests/locations.js';
3336

37+
import {
38+
parsedManifest as vttCodecsManifest
39+
} from './manifests/vtt_codecs.js';
40+
3441
QUnit.module('mpd-parser');
3542

3643
QUnit.test('has VERSION', function(assert) {
@@ -69,6 +76,10 @@ QUnit.test('has parse', function(assert) {
6976
name: 'locations',
7077
input: locationsTemplate,
7178
expected: locationsManifest
79+
}, {
80+
name: 'vtt_codecs',
81+
input: vttCodecsTemplate,
82+
expected: vttCodecsManifest
7283
}].forEach(({ name, input, expected }) => {
7384
QUnit.test(`${name} test manifest`, function(assert) {
7485
const actual = parse(input);

0 commit comments

Comments
 (0)