xgplayer-transmuxer 3.0.0-alpha.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/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/es/codec/aac.d.ts +34 -0
- package/es/codec/aac.js +242 -0
- package/es/codec/avc.d.ts +35 -0
- package/es/codec/avc.js +250 -0
- package/es/codec/hevc.d.ts +38 -0
- package/es/codec/hevc.js +202 -0
- package/es/codec/index.d.ts +4 -0
- package/es/codec/nalu.d.ts +11 -0
- package/es/codec/nalu.js +194 -0
- package/es/flv/amf.d.ts +16 -0
- package/es/flv/amf.js +247 -0
- package/es/flv/fixer.d.ts +31 -0
- package/es/flv/fixer.js +437 -0
- package/es/flv/index.d.ts +65 -0
- package/es/flv/index.js +441 -0
- package/es/index.d.ts +5 -0
- package/es/index.js +13 -0
- package/es/model/audio-sample.d.ts +18 -0
- package/es/model/audio-sample.js +26 -0
- package/es/model/audio-track.d.ts +38 -0
- package/es/model/audio-track.js +94 -0
- package/es/model/index.d.ts +6 -0
- package/es/model/metadata-track.d.ts +36 -0
- package/es/model/metadata-track.js +100 -0
- package/es/model/types.d.ts +26 -0
- package/es/model/types.js +31 -0
- package/es/model/video-sample.d.ts +44 -0
- package/es/model/video-sample.js +66 -0
- package/es/model/video-track.d.ts +45 -0
- package/es/model/video-track.js +99 -0
- package/es/mp4/fmp4-remuxer.d.ts +32 -0
- package/es/mp4/fmp4-remuxer.js +172 -0
- package/es/mp4/index.d.ts +4 -0
- package/es/mp4/logger.d.ts +13 -0
- package/es/mp4/logger.js +97 -0
- package/es/mp4/mp4-demuxer.d.ts +24 -0
- package/es/mp4/mp4-demuxer.js +268 -0
- package/es/mp4/mp4-parser.d.ts +161 -0
- package/es/mp4/mp4-parser.js +776 -0
- package/es/mp4/mp4-remuxer.d.ts +23 -0
- package/es/mp4/mp4-remuxer.js +273 -0
- package/es/mp4/mp4.d.ts +56 -0
- package/es/mp4/mp4.js +574 -0
- package/es/mpeg-ts/fixer.d.ts +23 -0
- package/es/mpeg-ts/fixer.js +383 -0
- package/es/mpeg-ts/index.d.ts +60 -0
- package/es/mpeg-ts/index.js +480 -0
- package/es/utils/env.d.ts +4 -0
- package/es/utils/env.js +10 -0
- package/es/utils/exp-golomb.d.ts +17 -0
- package/es/utils/exp-golomb.js +172 -0
- package/es/utils/index.d.ts +11 -0
- package/es/utils/index.js +77 -0
- package/es/utils/logger.d.ts +9 -0
- package/es/utils/logger.js +45 -0
- package/es/utils/utf8.d.ts +9 -0
- package/es/utils/utf8.js +91 -0
- package/package.json +25 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export class AAC {
|
|
2
|
+
static FREQ: number[];
|
|
3
|
+
static getRateIndexByRate(rate: any): number;
|
|
4
|
+
static parseADTS(data: any, pts: any): {
|
|
5
|
+
skip: number;
|
|
6
|
+
remaining: any;
|
|
7
|
+
frames: {
|
|
8
|
+
pts: any;
|
|
9
|
+
data: any;
|
|
10
|
+
}[];
|
|
11
|
+
samplingFrequencyIndex: number;
|
|
12
|
+
sampleRate: number;
|
|
13
|
+
objectType: number;
|
|
14
|
+
channelCount: number;
|
|
15
|
+
codec: string;
|
|
16
|
+
config: number[];
|
|
17
|
+
originCodec: string;
|
|
18
|
+
};
|
|
19
|
+
static parseAudioSpecificConfig(data: any): {
|
|
20
|
+
samplingFrequencyIndex: number;
|
|
21
|
+
sampleRate: number;
|
|
22
|
+
objectType: number;
|
|
23
|
+
channelCount: number;
|
|
24
|
+
config: number[];
|
|
25
|
+
codec: string;
|
|
26
|
+
originCodec: string;
|
|
27
|
+
};
|
|
28
|
+
static getFrameDuration(rate: any, timescale?: number): number;
|
|
29
|
+
static _getConfig(samplingIndex: any, channelCount: any, originObjectType: any): {
|
|
30
|
+
config: number[];
|
|
31
|
+
codec: string;
|
|
32
|
+
};
|
|
33
|
+
static getSilentFrame(codec: any, channelCount: any): Uint8Array;
|
|
34
|
+
}
|
package/es/codec/aac.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
2
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import 'core-js/modules/es.array.iterator.js';
|
|
5
|
+
import 'core-js/modules/es.object.to-string.js';
|
|
6
|
+
import 'core-js/modules/es.typed-array.uint8-array.js';
|
|
7
|
+
import 'core-js/modules/es.typed-array.copy-within.js';
|
|
8
|
+
import 'core-js/modules/es.typed-array.every.js';
|
|
9
|
+
import 'core-js/modules/es.typed-array.fill.js';
|
|
10
|
+
import 'core-js/modules/es.typed-array.filter.js';
|
|
11
|
+
import 'core-js/modules/es.typed-array.find.js';
|
|
12
|
+
import 'core-js/modules/es.typed-array.find-index.js';
|
|
13
|
+
import 'core-js/modules/es.typed-array.for-each.js';
|
|
14
|
+
import 'core-js/modules/es.typed-array.includes.js';
|
|
15
|
+
import 'core-js/modules/es.typed-array.index-of.js';
|
|
16
|
+
import 'core-js/modules/es.typed-array.iterator.js';
|
|
17
|
+
import 'core-js/modules/es.typed-array.join.js';
|
|
18
|
+
import 'core-js/modules/es.typed-array.last-index-of.js';
|
|
19
|
+
import 'core-js/modules/es.typed-array.map.js';
|
|
20
|
+
import 'core-js/modules/es.typed-array.reduce.js';
|
|
21
|
+
import 'core-js/modules/es.typed-array.reduce-right.js';
|
|
22
|
+
import 'core-js/modules/es.typed-array.reverse.js';
|
|
23
|
+
import 'core-js/modules/es.typed-array.set.js';
|
|
24
|
+
import 'core-js/modules/es.typed-array.slice.js';
|
|
25
|
+
import 'core-js/modules/es.typed-array.some.js';
|
|
26
|
+
import 'core-js/modules/es.typed-array.sort.js';
|
|
27
|
+
import 'core-js/modules/es.typed-array.subarray.js';
|
|
28
|
+
import 'core-js/modules/es.typed-array.to-locale-string.js';
|
|
29
|
+
import 'core-js/modules/es.typed-array.to-string.js';
|
|
30
|
+
import { isFirefox, isAndroid } from '../utils/env.js';
|
|
31
|
+
|
|
32
|
+
var AAC = /*#__PURE__*/function () {
|
|
33
|
+
function AAC() {
|
|
34
|
+
_classCallCheck(this, AAC);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
_createClass(AAC, null, [{
|
|
38
|
+
key: "getRateIndexByRate",
|
|
39
|
+
value: function getRateIndexByRate(rate) {
|
|
40
|
+
return AAC.FREQ.indexOf(rate);
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
key: "parseADTS",
|
|
44
|
+
value: function parseADTS(data, pts) {
|
|
45
|
+
var len = data.length;
|
|
46
|
+
var i = 0;
|
|
47
|
+
|
|
48
|
+
while (i + 2 < len) {
|
|
49
|
+
if (data[i] === 0xff && (data[i + 1] & 0xf6) === 0xf0) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
i++;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (i >= len) return;
|
|
57
|
+
var skip = i;
|
|
58
|
+
var frames = [];
|
|
59
|
+
var samplingFrequencyIndex = (data[i + 2] & 0x3c) >>> 2;
|
|
60
|
+
var sampleRate = AAC.FREQ[samplingFrequencyIndex];
|
|
61
|
+
if (!sampleRate) throw new Error("Invalid sampling index: ".concat(samplingFrequencyIndex));
|
|
62
|
+
var objectType = ((data[i + 2] & 0xc0) >>> 6) + 1;
|
|
63
|
+
var channelCount = (data[i + 2] & 1) << 2 | (data[i + 3] & 0xc0) >>> 6;
|
|
64
|
+
|
|
65
|
+
var _AAC$_getConfig = AAC._getConfig(samplingFrequencyIndex, channelCount, objectType),
|
|
66
|
+
config = _AAC$_getConfig.config,
|
|
67
|
+
codec = _AAC$_getConfig.codec;
|
|
68
|
+
|
|
69
|
+
var protectionSkipBytes;
|
|
70
|
+
var frameLength;
|
|
71
|
+
var frameIndex = 0;
|
|
72
|
+
var duration = AAC.getFrameDuration(sampleRate);
|
|
73
|
+
|
|
74
|
+
while (i + 7 < len) {
|
|
75
|
+
if (data[i] !== 0xff || (data[i + 1] & 0xF6) !== 0xf0) {
|
|
76
|
+
i++;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
frameLength = (data[i + 3] & 0x03) << 11 | data[i + 4] << 3 | (data[i + 5] & 0xe0) >> 5;
|
|
81
|
+
if (len - i < frameLength) break;
|
|
82
|
+
protectionSkipBytes = (~data[i + 1] & 0x01) * 2;
|
|
83
|
+
frames.push({
|
|
84
|
+
pts: pts + frameIndex * duration,
|
|
85
|
+
data: data.subarray(i + 7 + protectionSkipBytes, i + frameLength)
|
|
86
|
+
});
|
|
87
|
+
frameIndex++;
|
|
88
|
+
i += frameLength;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
skip: skip,
|
|
93
|
+
remaining: i >= len ? undefined : data.subarray(i),
|
|
94
|
+
frames: frames,
|
|
95
|
+
samplingFrequencyIndex: samplingFrequencyIndex,
|
|
96
|
+
sampleRate: sampleRate,
|
|
97
|
+
objectType: objectType,
|
|
98
|
+
channelCount: channelCount,
|
|
99
|
+
codec: codec,
|
|
100
|
+
config: config,
|
|
101
|
+
originCodec: "mp4a.40.".concat(objectType)
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}, {
|
|
105
|
+
key: "parseAudioSpecificConfig",
|
|
106
|
+
value: function parseAudioSpecificConfig(data) {
|
|
107
|
+
if (!data.length) return;
|
|
108
|
+
var objectType = data[0] >>> 3;
|
|
109
|
+
var samplingFrequencyIndex = (data[0] & 0x07) << 1 | data[1] >>> 7;
|
|
110
|
+
var channelCount = (data[1] & 0x78) >>> 3;
|
|
111
|
+
var sampleRate = AAC.FREQ[samplingFrequencyIndex];
|
|
112
|
+
if (!sampleRate) throw new Error("Invalid sampling index: ".concat(samplingFrequencyIndex));
|
|
113
|
+
|
|
114
|
+
var _AAC$_getConfig2 = AAC._getConfig(samplingFrequencyIndex, channelCount, objectType),
|
|
115
|
+
config = _AAC$_getConfig2.config,
|
|
116
|
+
codec = _AAC$_getConfig2.codec;
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
samplingFrequencyIndex: samplingFrequencyIndex,
|
|
120
|
+
sampleRate: sampleRate,
|
|
121
|
+
objectType: objectType,
|
|
122
|
+
channelCount: channelCount,
|
|
123
|
+
config: config,
|
|
124
|
+
codec: codec,
|
|
125
|
+
originCodec: "mp4a.40.".concat(objectType)
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}, {
|
|
129
|
+
key: "getFrameDuration",
|
|
130
|
+
value: function getFrameDuration(rate) {
|
|
131
|
+
var timescale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 90000;
|
|
132
|
+
return 1024 * timescale / rate;
|
|
133
|
+
}
|
|
134
|
+
}, {
|
|
135
|
+
key: "_getConfig",
|
|
136
|
+
value: function _getConfig(samplingIndex, channelCount, originObjectType) {
|
|
137
|
+
var config = [];
|
|
138
|
+
var objectType;
|
|
139
|
+
var extensionSamplingIndex;
|
|
140
|
+
|
|
141
|
+
if (isFirefox) {
|
|
142
|
+
if (samplingIndex >= 6) {
|
|
143
|
+
// use SBR (HE-AAC)
|
|
144
|
+
objectType = 5;
|
|
145
|
+
extensionSamplingIndex = samplingIndex - 3;
|
|
146
|
+
} else {
|
|
147
|
+
// use LC-AAC
|
|
148
|
+
objectType = 2;
|
|
149
|
+
extensionSamplingIndex = samplingIndex;
|
|
150
|
+
}
|
|
151
|
+
} else if (isAndroid) {
|
|
152
|
+
// use LC-AAC
|
|
153
|
+
objectType = 2;
|
|
154
|
+
extensionSamplingIndex = samplingIndex;
|
|
155
|
+
} else {
|
|
156
|
+
// use HE-AAC
|
|
157
|
+
objectType = originObjectType;
|
|
158
|
+
extensionSamplingIndex = samplingIndex;
|
|
159
|
+
|
|
160
|
+
if (samplingIndex >= 6) {
|
|
161
|
+
extensionSamplingIndex = samplingIndex - 3;
|
|
162
|
+
} else if (channelCount === 1) {
|
|
163
|
+
// Mono channel, use LC-AAC
|
|
164
|
+
objectType = 2;
|
|
165
|
+
extensionSamplingIndex = samplingIndex;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
config[0] = objectType << 3;
|
|
170
|
+
config[0] |= (samplingIndex & 0x0e) >> 1;
|
|
171
|
+
config[1] = (samplingIndex & 0x01) << 7;
|
|
172
|
+
config[1] |= channelCount << 3;
|
|
173
|
+
|
|
174
|
+
if (objectType === 5) {
|
|
175
|
+
config[1] |= (extensionSamplingIndex & 0x0e) >> 1;
|
|
176
|
+
config[2] = (extensionSamplingIndex & 0x01) << 7;
|
|
177
|
+
config[2] |= 2 << 2;
|
|
178
|
+
config[3] = 0;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
config: config,
|
|
183
|
+
codec: "mp4a.40.".concat(objectType)
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/* c8 ignore next 65 */
|
|
187
|
+
|
|
188
|
+
}, {
|
|
189
|
+
key: "getSilentFrame",
|
|
190
|
+
value: function getSilentFrame(codec, channelCount) {
|
|
191
|
+
switch (codec) {
|
|
192
|
+
case 'mp4a.40.2':
|
|
193
|
+
if (channelCount === 1) {
|
|
194
|
+
return new Uint8Array([0x00, 0xc8, 0x00, 0x80, 0x23, 0x80]);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (channelCount === 2) {
|
|
198
|
+
return new Uint8Array([0x21, 0x00, 0x49, 0x90, 0x02, 0x19, 0x00, 0x23, 0x80]);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (channelCount === 3) {
|
|
202
|
+
return new Uint8Array([0x00, 0xc8, 0x00, 0x80, 0x20, 0x84, 0x01, 0x26, 0x40, 0x08, 0x64, 0x00, 0x8e]);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (channelCount === 4) {
|
|
206
|
+
return new Uint8Array([0x00, 0xc8, 0x00, 0x80, 0x20, 0x84, 0x01, 0x26, 0x40, 0x08, 0x64, 0x00, 0x80, 0x2c, 0x80, 0x08, 0x02, 0x38]);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (channelCount === 5) {
|
|
210
|
+
return new Uint8Array([0x00, 0xc8, 0x00, 0x80, 0x20, 0x84, 0x01, 0x26, 0x40, 0x08, 0x64, 0x00, 0x82, 0x30, 0x04, 0x99, 0x00, 0x21, 0x90, 0x02, 0x38]);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (channelCount === 6) {
|
|
214
|
+
return new Uint8Array([0x00, 0xc8, 0x00, 0x80, 0x20, 0x84, 0x01, 0x26, 0x40, 0x08, 0x64, 0x00, 0x82, 0x30, 0x04, 0x99, 0x00, 0x21, 0x90, 0x02, 0x00, 0xb2, 0x00, 0x20, 0x08, 0xe0]);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
break;
|
|
218
|
+
|
|
219
|
+
default:
|
|
220
|
+
if (channelCount === 1) {
|
|
221
|
+
return new Uint8Array([0x1, 0x40, 0x22, 0x80, 0xa3, 0x4e, 0xe6, 0x80, 0xba, 0x8, 0x0, 0x0, 0x0, 0x1c, 0x6, 0xf1, 0xc1, 0xa, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e]);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (channelCount === 2) {
|
|
225
|
+
return new Uint8Array([0x1, 0x40, 0x22, 0x80, 0xa3, 0x5e, 0xe6, 0x80, 0xba, 0x8, 0x0, 0x0, 0x0, 0x0, 0x95, 0x0, 0x6, 0xf1, 0xa1, 0xa, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e]);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (channelCount === 3) {
|
|
229
|
+
return new Uint8Array([0x1, 0x40, 0x22, 0x80, 0xa3, 0x5e, 0xe6, 0x80, 0xba, 0x8, 0x0, 0x0, 0x0, 0x0, 0x95, 0x0, 0x6, 0xf1, 0xa1, 0xa, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e]);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}]);
|
|
236
|
+
|
|
237
|
+
return AAC;
|
|
238
|
+
}();
|
|
239
|
+
|
|
240
|
+
_defineProperty(AAC, "FREQ", [96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350]);
|
|
241
|
+
|
|
242
|
+
export { AAC };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export class AVC {
|
|
2
|
+
static parseAVCDecoderConfigurationRecord(data: any): {
|
|
3
|
+
sps: {
|
|
4
|
+
codec: string;
|
|
5
|
+
profileIdc: any;
|
|
6
|
+
profileCompatibility: any;
|
|
7
|
+
levelIdc: any;
|
|
8
|
+
chromaFormat: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
sarRatio: number[];
|
|
12
|
+
fpsNum: any;
|
|
13
|
+
fpsDen: number;
|
|
14
|
+
fps: number;
|
|
15
|
+
fixedFrame: boolean;
|
|
16
|
+
};
|
|
17
|
+
spsArr: any[];
|
|
18
|
+
ppsArr: any[];
|
|
19
|
+
nalUnitSize: number;
|
|
20
|
+
};
|
|
21
|
+
static parseSPS(unit: any): {
|
|
22
|
+
codec: string;
|
|
23
|
+
profileIdc: any;
|
|
24
|
+
profileCompatibility: any;
|
|
25
|
+
levelIdc: any;
|
|
26
|
+
chromaFormat: number;
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
sarRatio: number[];
|
|
30
|
+
fpsNum: any;
|
|
31
|
+
fpsDen: number;
|
|
32
|
+
fps: number;
|
|
33
|
+
fixedFrame: boolean;
|
|
34
|
+
};
|
|
35
|
+
}
|
package/es/codec/avc.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
2
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
3
|
+
import { NALu } from './nalu.js';
|
|
4
|
+
import { getAvcCodec } from '../utils/index.js';
|
|
5
|
+
import { ExpGolomb } from '../utils/exp-golomb.js';
|
|
6
|
+
|
|
7
|
+
var AVC = /*#__PURE__*/function () {
|
|
8
|
+
function AVC() {
|
|
9
|
+
_classCallCheck(this, AVC);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
_createClass(AVC, null, [{
|
|
13
|
+
key: "parseAVCDecoderConfigurationRecord",
|
|
14
|
+
value: function parseAVCDecoderConfigurationRecord(data) {
|
|
15
|
+
if (data.length < 7) return;
|
|
16
|
+
var nalUnitSize = (data[4] & 3) + 1;
|
|
17
|
+
var spsParsed;
|
|
18
|
+
var spsArr = [];
|
|
19
|
+
var ppsArr = [];
|
|
20
|
+
var offset = 6;
|
|
21
|
+
var spsCount = data[5] & 0x1f;
|
|
22
|
+
var spsSize;
|
|
23
|
+
|
|
24
|
+
for (var i = 0; i < spsCount; i++) {
|
|
25
|
+
spsSize = data[offset] << 8 | data[offset + 1];
|
|
26
|
+
offset += 2;
|
|
27
|
+
if (!spsSize) continue;
|
|
28
|
+
var sps = data.subarray(offset, offset + spsSize);
|
|
29
|
+
offset += spsSize;
|
|
30
|
+
spsArr.push(sps);
|
|
31
|
+
|
|
32
|
+
if (!spsParsed) {
|
|
33
|
+
spsParsed = AVC.parseSPS(NALu.removeEPB(sps));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var ppsCount = data[offset];
|
|
38
|
+
offset++;
|
|
39
|
+
var ppsSize;
|
|
40
|
+
|
|
41
|
+
for (var _i = 0; _i < ppsCount; _i++) {
|
|
42
|
+
ppsSize = data[offset] << 8 | data[offset + 1];
|
|
43
|
+
offset += 2;
|
|
44
|
+
if (!ppsSize) continue;
|
|
45
|
+
ppsArr.push(data.subarray(offset, offset + ppsSize));
|
|
46
|
+
offset += ppsSize;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
sps: spsParsed,
|
|
51
|
+
spsArr: spsArr,
|
|
52
|
+
ppsArr: ppsArr,
|
|
53
|
+
nalUnitSize: nalUnitSize
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}, {
|
|
57
|
+
key: "parseSPS",
|
|
58
|
+
value: function parseSPS(unit) {
|
|
59
|
+
var eg = new ExpGolomb(unit);
|
|
60
|
+
eg.readUByte();
|
|
61
|
+
var profileIdc = eg.readUByte();
|
|
62
|
+
var profileCompatibility = eg.readUByte();
|
|
63
|
+
var levelIdc = eg.readUByte();
|
|
64
|
+
eg.skipUEG();
|
|
65
|
+
var chromaFormat = 420;
|
|
66
|
+
|
|
67
|
+
if (profileIdc === 100 || profileIdc === 110 || profileIdc === 122 || profileIdc === 244 || profileIdc === 44 || profileIdc === 83 || profileIdc === 86 || profileIdc === 118 || profileIdc === 128 || profileIdc === 138 || profileIdc === 144) {
|
|
68
|
+
var chromaFormatIdc = eg.readUEG();
|
|
69
|
+
if (chromaFormatIdc <= 3) chromaFormat = [0, 420, 422, 444][chromaFormatIdc];
|
|
70
|
+
if (chromaFormatIdc === 3) eg.skipBits(1);
|
|
71
|
+
eg.skipUEG();
|
|
72
|
+
eg.skipUEG();
|
|
73
|
+
eg.skipBits(1);
|
|
74
|
+
|
|
75
|
+
if (eg.readBool()) {
|
|
76
|
+
var scalingListCount = chromaFormatIdc !== 3 ? 8 : 12;
|
|
77
|
+
|
|
78
|
+
for (var i = 0; i < scalingListCount; i++) {
|
|
79
|
+
if (eg.readBool()) {
|
|
80
|
+
if (i < 6) {
|
|
81
|
+
eg.skipScalingList(16);
|
|
82
|
+
} else {
|
|
83
|
+
eg.skipScalingList(64);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
eg.skipUEG();
|
|
91
|
+
var picOrderCntType = eg.readUEG();
|
|
92
|
+
|
|
93
|
+
if (picOrderCntType === 0) {
|
|
94
|
+
eg.readUEG();
|
|
95
|
+
} else if (picOrderCntType === 1) {
|
|
96
|
+
eg.skipBits(1);
|
|
97
|
+
eg.skipUEG();
|
|
98
|
+
eg.skipUEG();
|
|
99
|
+
var numRefFramesInPicOrderCntCycle = eg.readUEG();
|
|
100
|
+
|
|
101
|
+
for (var _i2 = 0; _i2 < numRefFramesInPicOrderCntCycle; _i2++) {
|
|
102
|
+
eg.skipUEG();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
eg.skipUEG();
|
|
107
|
+
eg.skipBits(1);
|
|
108
|
+
var picWidthInMbsMinus1 = eg.readUEG();
|
|
109
|
+
var picHeightInMapUnitsMinus1 = eg.readUEG();
|
|
110
|
+
var frameMbsOnlyFlag = eg.readBits(1);
|
|
111
|
+
if (frameMbsOnlyFlag === 0) eg.skipBits(1);
|
|
112
|
+
eg.skipBits(1);
|
|
113
|
+
var frameCropLeftOffset = 0;
|
|
114
|
+
var frameCropRightOffset = 0;
|
|
115
|
+
var frameCropTopOffset = 0;
|
|
116
|
+
var frameCropBottomOffset = 0;
|
|
117
|
+
|
|
118
|
+
if (eg.readBool()) {
|
|
119
|
+
frameCropLeftOffset = eg.readUEG();
|
|
120
|
+
frameCropRightOffset = eg.readUEG();
|
|
121
|
+
frameCropTopOffset = eg.readUEG();
|
|
122
|
+
frameCropBottomOffset = eg.readUEG();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
var sarRatio;
|
|
126
|
+
var fixedFrame;
|
|
127
|
+
var fpsNum;
|
|
128
|
+
var fpsDen;
|
|
129
|
+
var fps;
|
|
130
|
+
|
|
131
|
+
if (eg.readBool()) {
|
|
132
|
+
if (eg.readBool()) {
|
|
133
|
+
var aspectRatioIdc = eg.readUByte();
|
|
134
|
+
|
|
135
|
+
switch (aspectRatioIdc) {
|
|
136
|
+
case 1:
|
|
137
|
+
sarRatio = [1, 1];
|
|
138
|
+
break;
|
|
139
|
+
|
|
140
|
+
case 2:
|
|
141
|
+
sarRatio = [12, 11];
|
|
142
|
+
break;
|
|
143
|
+
|
|
144
|
+
case 3:
|
|
145
|
+
sarRatio = [10, 11];
|
|
146
|
+
break;
|
|
147
|
+
|
|
148
|
+
case 4:
|
|
149
|
+
sarRatio = [16, 11];
|
|
150
|
+
break;
|
|
151
|
+
|
|
152
|
+
case 5:
|
|
153
|
+
sarRatio = [40, 33];
|
|
154
|
+
break;
|
|
155
|
+
|
|
156
|
+
case 6:
|
|
157
|
+
sarRatio = [24, 11];
|
|
158
|
+
break;
|
|
159
|
+
|
|
160
|
+
case 7:
|
|
161
|
+
sarRatio = [20, 11];
|
|
162
|
+
break;
|
|
163
|
+
|
|
164
|
+
case 8:
|
|
165
|
+
sarRatio = [32, 11];
|
|
166
|
+
break;
|
|
167
|
+
|
|
168
|
+
case 9:
|
|
169
|
+
sarRatio = [80, 33];
|
|
170
|
+
break;
|
|
171
|
+
|
|
172
|
+
case 10:
|
|
173
|
+
sarRatio = [18, 11];
|
|
174
|
+
break;
|
|
175
|
+
|
|
176
|
+
case 11:
|
|
177
|
+
sarRatio = [15, 11];
|
|
178
|
+
break;
|
|
179
|
+
|
|
180
|
+
case 12:
|
|
181
|
+
sarRatio = [64, 33];
|
|
182
|
+
break;
|
|
183
|
+
|
|
184
|
+
case 13:
|
|
185
|
+
sarRatio = [160, 99];
|
|
186
|
+
break;
|
|
187
|
+
|
|
188
|
+
case 14:
|
|
189
|
+
sarRatio = [4, 3];
|
|
190
|
+
break;
|
|
191
|
+
|
|
192
|
+
case 15:
|
|
193
|
+
sarRatio = [3, 2];
|
|
194
|
+
break;
|
|
195
|
+
|
|
196
|
+
case 16:
|
|
197
|
+
sarRatio = [2, 1];
|
|
198
|
+
break;
|
|
199
|
+
|
|
200
|
+
case 255:
|
|
201
|
+
{
|
|
202
|
+
sarRatio = [eg.readUByte() << 8 | eg.readUByte(), eg.readUByte() << 8 | eg.readUByte()];
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (eg.readBool()) eg.readBool();
|
|
209
|
+
|
|
210
|
+
if (eg.readBool()) {
|
|
211
|
+
eg.readBits(4);
|
|
212
|
+
if (eg.readBool()) eg.readBits(24);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (eg.readBool()) {
|
|
216
|
+
eg.readUEG();
|
|
217
|
+
eg.readUEG();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (eg.readBool()) {
|
|
221
|
+
var numUnitsInTick = eg.readBits(32);
|
|
222
|
+
var timeScale = eg.readBits(32);
|
|
223
|
+
fixedFrame = eg.readBool();
|
|
224
|
+
fpsNum = timeScale;
|
|
225
|
+
fpsDen = numUnitsInTick * 2;
|
|
226
|
+
fps = fpsNum / fpsDen;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
codec: getAvcCodec(unit.subarray(1, 4)),
|
|
232
|
+
profileIdc: profileIdc,
|
|
233
|
+
profileCompatibility: profileCompatibility,
|
|
234
|
+
levelIdc: levelIdc,
|
|
235
|
+
chromaFormat: chromaFormat,
|
|
236
|
+
width: Math.ceil((picWidthInMbsMinus1 + 1) * 16 - 2 * (frameCropLeftOffset + frameCropRightOffset)),
|
|
237
|
+
height: (2 - frameMbsOnlyFlag) * (picHeightInMapUnitsMinus1 + 1) * 16 - (frameMbsOnlyFlag ? 2 : 4) * (frameCropTopOffset + frameCropBottomOffset),
|
|
238
|
+
sarRatio: sarRatio,
|
|
239
|
+
fpsNum: fpsNum,
|
|
240
|
+
fpsDen: fpsDen,
|
|
241
|
+
fps: fps,
|
|
242
|
+
fixedFrame: fixedFrame
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}]);
|
|
246
|
+
|
|
247
|
+
return AVC;
|
|
248
|
+
}();
|
|
249
|
+
|
|
250
|
+
export { AVC };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class HEVC {
|
|
2
|
+
static parseHEVCDecoderConfigurationRecord(data: any): {
|
|
3
|
+
sps: {
|
|
4
|
+
codec: string;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
chromaFormat: number;
|
|
8
|
+
bitDepthLumaMinus8: number;
|
|
9
|
+
bitDepthChromaMinus8: number;
|
|
10
|
+
generalProfileSpace: any;
|
|
11
|
+
generalTierFlag: any;
|
|
12
|
+
generalProfileIdc: any;
|
|
13
|
+
generalLevelIdc: any;
|
|
14
|
+
};
|
|
15
|
+
spsArr: any[];
|
|
16
|
+
ppsArr: any[];
|
|
17
|
+
vpsArr: any[];
|
|
18
|
+
nalUnitSize: number;
|
|
19
|
+
};
|
|
20
|
+
static parseSPS(unit: any): {
|
|
21
|
+
codec: string;
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
chromaFormat: number;
|
|
25
|
+
bitDepthLumaMinus8: number;
|
|
26
|
+
bitDepthChromaMinus8: number;
|
|
27
|
+
generalProfileSpace: any;
|
|
28
|
+
generalTierFlag: any;
|
|
29
|
+
generalProfileIdc: any;
|
|
30
|
+
generalLevelIdc: any;
|
|
31
|
+
};
|
|
32
|
+
static _parseProfileTierLevel(eg: any, maxSubLayersMinus1: any, profilePresentFlag?: number): {
|
|
33
|
+
generalProfileSpace: any;
|
|
34
|
+
generalTierFlag: any;
|
|
35
|
+
generalProfileIdc: any;
|
|
36
|
+
generalLevelIdc: any;
|
|
37
|
+
};
|
|
38
|
+
}
|