dasha 2.3.1 → 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/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, getHeightByWidth } = 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) => {
@@ -34,11 +34,31 @@ class Manifest {
34
34
  .flat(1)
35
35
  .filter(isVideoAdaptationSet);
36
36
  const representations = adaptationSets.map((a) => a.representations).flat(2);
37
- const matchesInHeight = representations.filter((r) => getHeightByWidth(r.width) === height);
38
- const matchesInId = representations.filter((r) => r.id.includes(height));
39
- const matches = matchesInHeight?.length ? matchesInHeight : matchesInId;
40
- const representation = this.findBestRepresentation(matches.length ? matches : representations);
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
+ );
41
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';
42
62
  return {
43
63
  id: 0,
44
64
  type: CONTENT_TYPE.video,
@@ -50,6 +70,10 @@ class Manifest {
50
70
  width: representation.width,
51
71
  height: representation.height,
52
72
  qualityLabel: getQualityLabel(representation.width),
73
+ hevc: representation.codecs.includes('hvc') || representation.codecs.includes('hev'),
74
+ codec,
75
+ codecs: representation.codecs,
76
+ bitDepth,
53
77
  };
54
78
  }
55
79
 
@@ -70,6 +94,7 @@ class Manifest {
70
94
  const tracks = [];
71
95
  for (const adaptationSet of adaptationSets) {
72
96
  const representation = this.findBestRepresentation(adaptationSet.representations);
97
+ let codec = '';
73
98
  const track = {
74
99
  id: tracks.length,
75
100
  type: CONTENT_TYPE.audio,
@@ -80,7 +105,8 @@ class Manifest {
80
105
  segments: this.getSegments(adaptationSet, representation),
81
106
  bitrate: Math.round(representation.bandwidth / 1000), // Kbps
82
107
  size: Math.ceil((representation.bandwidth / 8e6) * this.mediaPresentationDuration), // MB
83
- audioSampleRate: representation.audioSamplingRate / 1000,
108
+ audioSamplingRate: representation.audioSamplingRate / 1000,
109
+ codecs: representation.codecs,
84
110
  };
85
111
  tracks.push(track);
86
112
  }
package/lib/utils.js CHANGED
@@ -49,6 +49,9 @@ const getHeightByWidth = (videoWidth) => {
49
49
  return height;
50
50
  };
51
51
 
52
+ const getClosest = (value, array) =>
53
+ array.reduce((prev, curr) => (Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev));
54
+
52
55
  const getQualityLabel = (videoWidth) => getHeightByWidth(videoWidth) + 'p';
53
56
 
54
- module.exports = { parseDuration, getHeightByWidth, getQualityLabel };
57
+ module.exports = { parseDuration, getHeightByWidth, getQualityLabel, getClosest };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dasha",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "author": "Vitaly Gashkov <vitalygashkov@bk.ru>",
5
5
  "description": "MPD-manifest parser for MPEG DASH",
6
6
  "license": "Apache-2.0",