dasha 2.2.6 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/manifest.js +38 -7
- package/lib/utils.js +17 -9
- package/package.json +5 -5
package/README.md
CHANGED
package/lib/manifest.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { parseXml } = require('./xml');
|
|
4
4
|
const { processManifest } = require('./processor');
|
|
5
|
-
const { getQualityLabel } = require('./utils');
|
|
5
|
+
const { getQualityLabel, getHeightByWidth, getClosest } = require('./utils');
|
|
6
6
|
const { CONTENT_TYPE, KEY_SYSTEMS } = require('./constants');
|
|
7
7
|
|
|
8
8
|
const isUrl = (value) => {
|
|
@@ -18,6 +18,11 @@ class Manifest {
|
|
|
18
18
|
for (const key of Object.keys(manifest)) this[key] = manifest[key];
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
addBaseUrl(value) {
|
|
22
|
+
if (Array.isArray(this.baseUrls)) this.baseUrls.push({ value });
|
|
23
|
+
else this.baseUrls = [{ value }];
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
getVideoTrack(height) {
|
|
22
27
|
const isVideoAdaptationSet = (adaptationSet) =>
|
|
23
28
|
adaptationSet.contentType === CONTENT_TYPE.video ||
|
|
@@ -29,11 +34,31 @@ class Manifest {
|
|
|
29
34
|
.flat(1)
|
|
30
35
|
.filter(isVideoAdaptationSet);
|
|
31
36
|
const representations = adaptationSets.map((a) => a.representations).flat(2);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
|
|
38
|
+
let suitableRepresentations = [];
|
|
39
|
+
if (height) {
|
|
40
|
+
const resolutions = representations.map((r) => ({
|
|
41
|
+
height: getHeightByWidth(r.width),
|
|
42
|
+
width: r.width,
|
|
43
|
+
}));
|
|
44
|
+
const heights = resolutions.map((r) => r.height);
|
|
45
|
+
const matchedHeight = height ? getClosest(height, heights) : Math.max(...heights);
|
|
46
|
+
const matchedResolution = resolutions.find((r) => r.height === matchedHeight);
|
|
47
|
+
const matchesInHeight = representations.filter((r) => matchedResolution.width === r.width);
|
|
48
|
+
const matchesInId = representations.filter((r) => r.id.includes(height.toString()));
|
|
49
|
+
suitableRepresentations = matchesInHeight?.length ? matchesInHeight : matchesInId;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const representation = this.findBestRepresentation(
|
|
53
|
+
suitableRepresentations.length ? suitableRepresentations : representations
|
|
54
|
+
);
|
|
36
55
|
const adaptationSet = adaptationSets.find((a) => a.representations.includes(representation));
|
|
56
|
+
let codec = 'x264';
|
|
57
|
+
if (representation.codecs.includes('hvc') || representation.codecs.includes('hev'))
|
|
58
|
+
codec = 'x265';
|
|
59
|
+
let bitDepth = '8bit';
|
|
60
|
+
if (representation.codecs.includes('.2.4.')) bitDepth = '10bit';
|
|
61
|
+
if (representation.codecs.includes('.4.16.')) bitDepth = '12bit';
|
|
37
62
|
return {
|
|
38
63
|
id: 0,
|
|
39
64
|
type: CONTENT_TYPE.video,
|
|
@@ -44,7 +69,11 @@ class Manifest {
|
|
|
44
69
|
size: Math.ceil((representation.bandwidth / 8e6) * this.mediaPresentationDuration), // MB
|
|
45
70
|
width: representation.width,
|
|
46
71
|
height: representation.height,
|
|
47
|
-
|
|
72
|
+
qualityLabel: getQualityLabel(representation.width),
|
|
73
|
+
hevc: representation.codecs.includes('hvc') || representation.codecs.includes('hev'),
|
|
74
|
+
codec,
|
|
75
|
+
codecs: representation.codecs,
|
|
76
|
+
bitDepth,
|
|
48
77
|
};
|
|
49
78
|
}
|
|
50
79
|
|
|
@@ -65,6 +94,7 @@ class Manifest {
|
|
|
65
94
|
const tracks = [];
|
|
66
95
|
for (const adaptationSet of adaptationSets) {
|
|
67
96
|
const representation = this.findBestRepresentation(adaptationSet.representations);
|
|
97
|
+
let codec = '';
|
|
68
98
|
const track = {
|
|
69
99
|
id: tracks.length,
|
|
70
100
|
type: CONTENT_TYPE.audio,
|
|
@@ -75,7 +105,8 @@ class Manifest {
|
|
|
75
105
|
segments: this.getSegments(adaptationSet, representation),
|
|
76
106
|
bitrate: Math.round(representation.bandwidth / 1000), // Kbps
|
|
77
107
|
size: Math.ceil((representation.bandwidth / 8e6) * this.mediaPresentationDuration), // MB
|
|
78
|
-
|
|
108
|
+
audioSamplingRate: representation.audioSamplingRate / 1000,
|
|
109
|
+
codecs: representation.codecs,
|
|
79
110
|
};
|
|
80
111
|
tracks.push(track);
|
|
81
112
|
}
|
package/lib/utils.js
CHANGED
|
@@ -34,16 +34,24 @@ const parseDuration = (durationString) => {
|
|
|
34
34
|
return isFinite(d) ? d : null;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
const
|
|
37
|
+
const getHeightByWidth = (videoWidth) => {
|
|
38
38
|
const width = typeof videoWidth === 'number' ? videoWidth : parseInt(videoWidth);
|
|
39
39
|
if (isNaN(width)) return;
|
|
40
|
-
let
|
|
41
|
-
if (width >=
|
|
42
|
-
if (width >=
|
|
43
|
-
if (width >=
|
|
44
|
-
if (width >=
|
|
45
|
-
if (width >=
|
|
46
|
-
|
|
40
|
+
let height = 144;
|
|
41
|
+
if (width >= 426) height = 240;
|
|
42
|
+
if (width >= 640) height = 360;
|
|
43
|
+
if (width >= 854) height = 480;
|
|
44
|
+
if (width >= 1024) height = 576;
|
|
45
|
+
if (width >= 1280) height = 720;
|
|
46
|
+
if (width >= 1920) height = 1080;
|
|
47
|
+
if (width >= 3840) height = 2160;
|
|
48
|
+
if (width >= 7680) height = 4320;
|
|
49
|
+
return height;
|
|
47
50
|
};
|
|
48
51
|
|
|
49
|
-
|
|
52
|
+
const getClosest = (value, array) =>
|
|
53
|
+
array.reduce((prev, curr) => (Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev));
|
|
54
|
+
|
|
55
|
+
const getQualityLabel = (videoWidth) => getHeightByWidth(videoWidth) + 'p';
|
|
56
|
+
|
|
57
|
+
module.exports = { parseDuration, getHeightByWidth, getQualityLabel, getClosest };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dasha",
|
|
3
|
-
"version": "2.2
|
|
4
|
-
"author": "
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "2.3.2",
|
|
4
|
+
"author": "Vitaly Gashkov <vitalygashkov@bk.ru>",
|
|
5
|
+
"description": "MPD-manifest parser for MPEG DASH",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"mpeg",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
],
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/
|
|
22
|
+
"url": "git+https://github.com/vitalygashkov/dasha.git"
|
|
23
23
|
},
|
|
24
24
|
"funding": {
|
|
25
25
|
"type": "individual",
|
|
26
|
-
"url": "https://boosty.to/
|
|
26
|
+
"url": "https://boosty.to/vitalygashkov"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"test": "jest",
|