Docker support #2, Fixes #4, dynamic imports

This commit is contained in:
Shiny Nematoda 2022-07-29 19:21:59 +00:00
parent 2838030839
commit 7273fcabc8
No known key found for this signature in database
GPG key ID: 6506D50F5613A42D
10 changed files with 696 additions and 246 deletions

120
src/scripts/dash.js Normal file
View file

@ -0,0 +1,120 @@
import { Buffer } from 'buffer';
window.Buffer = Buffer;
import { json2xml } from 'xml-js';
export function useDash(streams, len) {
const sets = [],
mimes = [[]],
mimeTypes = [];
streams.forEach(stream => {
const i = mimeTypes.indexOf(stream.mimeType);
if (i > -1) {
mimes[i].push(stream);
} else {
mimeTypes.push(stream.mimeType);
mimes.push([]);
mimes[mimeTypes.length - 1].push(stream);
}
});
for (let i in mimeTypes) {
const set = {
type: 'element',
name: 'AdaptationSet',
attributes: {
id: i,
mimeType: mimeTypes[i],
startWithSAP: '1',
subsegmentAlignment: 'true',
},
elements: [],
};
mimes[i].forEach(format => {
const audio = {
type: 'element',
name: 'Representation',
attributes: {
id: format.itag,
codecs: format.codec,
bandwidth: format.bitrate,
},
elements: [
{
type: 'element',
name: 'AudioChannelConfiguration',
attributes: {
schemeIdUri:
'urn:mpeg:dash:23003:3:audio_channel_configuration:2011',
value: '2',
},
},
{
type: 'element',
name: 'BaseURL',
elements: [
{
type: 'text',
text: format.url,
},
],
},
{
type: 'element',
name: 'SegmentBase',
attributes: {
indexRange: `${format.indexStart}-${format.indexEnd}`,
},
elements: [
{
type: 'element',
name: 'Initialization',
attributes: {
range: `${format.initStart}-${format.initEnd}`,
},
},
],
},
],
};
set.elements.push(audio);
});
sets.push(set);
}
const gen = {
declaration: {
attributes: {
version: '1.0',
encoding: 'utf-8',
},
},
elements: [
{
type: 'element',
name: 'MPD',
attributes: {
xmlns: 'urn:mpeg:dash:schema:mpd:2011',
profiles: 'urn:mpeg:dash:profile:full:2011',
minBufferTime: 'PT1.5S',
type: 'static',
mediaPresentationDuration: `PT${len}S`,
},
elements: [
{
type: 'element',
name: 'Period',
elements: sets,
},
],
},
],
};
console.log(json2xml(gen));
return json2xml(gen);
}