Skip to content

Commit

Permalink
feat: add CODECS attribute to subtitle playlists if it exists (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Sep 29, 2020
1 parent 26924c0 commit bc0872a
Show file tree
Hide file tree
Showing 5 changed files with 432 additions and 7 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<body>
<p>Open dev tools to try it out</p>
<ul>
<li><a id="test/debug.html">Run unit tests in browser.</a></li>
<li><a id="docs" href="docs/api/">Read generated docs.</a></li>
<li><a href="test/debug.html">Run unit tests in browser.</a></li>
<li><a href="docs/api/">Read generated docs.</a></li>
</ul>

<form id=parse>
Expand Down
16 changes: 11 additions & 5 deletions src/toM3u8.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,18 @@ export const formatVttPlaylist = ({ attributes, segments }) => {
// targetDuration should be the same duration as the only segment
attributes.duration = attributes.sourceDuration;
}

const m3u8Attributes = {
NAME: attributes.id,
BANDWIDTH: attributes.bandwidth,
['PROGRAM-ID']: 1
};

if (attributes.codecs) {
m3u8Attributes.CODECS = attributes.codecs;
}
return {
attributes: {
NAME: attributes.id,
BANDWIDTH: attributes.bandwidth,
['PROGRAM-ID']: 1
},
attributes: m3u8Attributes,
uri: '',
endList: (attributes.type || 'static') === 'static',
timeline: attributes.periodIndex,
Expand Down
11 changes: 11 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { parse, VERSION } from '../src';
import QUnit from 'qunit';

QUnit.dump.maxDepth = Infinity;

// manifests
import vttCodecsTemplate from './manifests/vtt_codecs.mpd';
import maatVttSegmentTemplate from './manifests/maat_vtt_segmentTemplate.mpd';
import segmentBaseTemplate from './manifests/segmentBase.mpd';
import segmentListTemplate from './manifests/segmentList.mpd';
Expand Down Expand Up @@ -31,6 +34,10 @@ import {
parsedManifest as locationsManifest
} from './manifests/locations.js';

import {
parsedManifest as vttCodecsManifest
} from './manifests/vtt_codecs.js';

QUnit.module('mpd-parser');

QUnit.test('has VERSION', function(assert) {
Expand Down Expand Up @@ -69,6 +76,10 @@ QUnit.test('has parse', function(assert) {
name: 'locations',
input: locationsTemplate,
expected: locationsManifest
}, {
name: 'vtt_codecs',
input: vttCodecsTemplate,
expected: vttCodecsManifest
}].forEach(({ name, input, expected }) => {
QUnit.test(`${name} test manifest`, function(assert) {
const actual = parse(input);
Expand Down
Loading

0 comments on commit bc0872a

Please sign in to comment.