@sentinel-ac/sentinel-webm 1.0.0

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.
Files changed (2) hide show
  1. package/package.json +22 -0
  2. package/src/index.js +431 -0
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@sentinel-ac/sentinel-webm",
3
+ "version": "1.0.0",
4
+ "description": "Recorder for Sentinel-AC",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "exports": {
8
+ ".": "./src/index.js"
9
+ },
10
+ "files": [
11
+ "src"
12
+ ],
13
+ "keywords": [
14
+ "webm",
15
+ "video",
16
+ "duration",
17
+ "mediarecorder",
18
+ "fix-webm-duration"
19
+ ],
20
+ "author": "clxsx",
21
+ "license": "MIT"
22
+ }
package/src/index.js ADDED
@@ -0,0 +1,431 @@
1
+ var sections = {
2
+ 0xa45dfa3: { name: 'EBML', type: 'Container' },
3
+ 0x286: { name: 'EBMLVersion', type: 'Uint' },
4
+ 0x2f7: { name: 'EBMLReadVersion', type: 'Uint' },
5
+ 0x2f2: { name: 'EBMLMaxIDLength', type: 'Uint' },
6
+ 0x2f3: { name: 'EBMLMaxSizeLength', type: 'Uint' },
7
+ 0x282: { name: 'DocType', type: 'String' },
8
+ 0x287: { name: 'DocTypeVersion', type: 'Uint' },
9
+ 0x285: { name: 'DocTypeReadVersion', type: 'Uint' },
10
+ 0x6c: { name: 'Void', type: 'Binary' },
11
+ 0x3f: { name: 'CRC-32', type: 'Binary' },
12
+ 0xb538667: { name: 'SignatureSlot', type: 'Container' },
13
+ 0x3e8a: { name: 'SignatureAlgo', type: 'Uint' },
14
+ 0x3e9a: { name: 'SignatureHash', type: 'Uint' },
15
+ 0x3ea5: { name: 'SignaturePublicKey', type: 'Binary' },
16
+ 0x3eb5: { name: 'Signature', type: 'Binary' },
17
+ 0x3e5b: { name: 'SignatureElements', type: 'Container' },
18
+ 0x3e7b: { name: 'SignatureElementList', type: 'Container' },
19
+ 0x2532: { name: 'SignedElement', type: 'Binary' },
20
+ 0x8538067: { name: 'Segment', type: 'Container' },
21
+ 0x14d9b74: { name: 'SeekHead', type: 'Container' },
22
+ 0xdbb: { name: 'Seek', type: 'Container' },
23
+ 0x13ab: { name: 'SeekID', type: 'Binary' },
24
+ 0x13ac: { name: 'SeekPosition', type: 'Uint' },
25
+ 0x549a966: { name: 'Info', type: 'Container' },
26
+ 0x33a4: { name: 'SegmentUID', type: 'Binary' },
27
+ 0x3384: { name: 'SegmentFilename', type: 'String' },
28
+ 0x1cb923: { name: 'PrevUID', type: 'Binary' },
29
+ 0x1c83ab: { name: 'PrevFilename', type: 'String' },
30
+ 0x1eb923: { name: 'NextUID', type: 'Binary' },
31
+ 0x1e83bb: { name: 'NextFilename', type: 'String' },
32
+ 0x444: { name: 'SegmentFamily', type: 'Binary' },
33
+ 0x2924: { name: 'ChapterTranslate', type: 'Container' },
34
+ 0x29fc: { name: 'ChapterTranslateEditionUID', type: 'Uint' },
35
+ 0x29bf: { name: 'ChapterTranslateCodec', type: 'Uint' },
36
+ 0x29a5: { name: 'ChapterTranslateID', type: 'Binary' },
37
+ 0xad7b1: { name: 'TimecodeScale', type: 'Uint' },
38
+ 0x489: { name: 'Duration', type: 'Float' },
39
+ 0x461: { name: 'DateUTC', type: 'Date' },
40
+ 0x3ba9: { name: 'Title', type: 'String' },
41
+ 0xd80: { name: 'MuxingApp', type: 'String' },
42
+ 0x1741: { name: 'WritingApp', type: 'String' },
43
+ 0x67: { name: 'Timecode', type: 'Uint' },
44
+ 0x1854: { name: 'SilentTracks', type: 'Container' },
45
+ 0x18d7: { name: 'SilentTrackNumber', type: 'Uint' },
46
+ 0x27: { name: 'Position', type: 'Uint' },
47
+ 0x2b: { name: 'PrevSize', type: 'Uint' },
48
+ 0x23: { name: 'SimpleBlock', type: 'Binary' },
49
+ 0x20: { name: 'BlockGroup', type: 'Container' },
50
+ 0x21: { name: 'Block', type: 'Binary' },
51
+ 0x22: { name: 'BlockVirtual', type: 'Binary' },
52
+ 0x35a1: { name: 'BlockAdditions', type: 'Container' },
53
+ 0x26: { name: 'BlockMore', type: 'Container' },
54
+ 0x6e: { name: 'BlockAddID', type: 'Uint' },
55
+ 0x25: { name: 'BlockAdditional', type: 'Binary' },
56
+ 0x1b: { name: 'BlockDuration', type: 'Uint' },
57
+ 0x7a: { name: 'ReferencePriority', type: 'Uint' },
58
+ 0x7b: { name: 'ReferenceBlock', type: 'Int' },
59
+ 0x7d: { name: 'ReferenceVirtual', type: 'Int' },
60
+ 0x24: { name: 'CodecState', type: 'Binary' },
61
+ 0x35a2: { name: 'DiscardPadding', type: 'Int' },
62
+ 0xe: { name: 'Slices', type: 'Container' },
63
+ 0x68: { name: 'TimeSlice', type: 'Container' },
64
+ 0x4c: { name: 'LaceNumber', type: 'Uint' },
65
+ 0x4d: { name: 'FrameNumber', type: 'Uint' },
66
+ 0x4b: { name: 'BlockAdditionID', type: 'Uint' },
67
+ 0x4e: { name: 'Delay', type: 'Uint' },
68
+ 0x4f: { name: 'SliceDuration', type: 'Uint' },
69
+ 0x48: { name: 'ReferenceFrame', type: 'Container' },
70
+ 0x49: { name: 'ReferenceOffset', type: 'Uint' },
71
+ 0x4a: { name: 'ReferenceTimeCode', type: 'Uint' },
72
+ 0x2f: { name: 'EncryptedBlock', type: 'Binary' },
73
+ 0x654ae6b: { name: 'Tracks', type: 'Container' },
74
+ 0x2e: { name: 'TrackEntry', type: 'Container' },
75
+ 0x57: { name: 'TrackNumber', type: 'Uint' },
76
+ 0x33c5: { name: 'TrackUID', type: 'Uint' },
77
+ 0x3: { name: 'TrackType', type: 'Uint' },
78
+ 0x39: { name: 'FlagEnabled', type: 'Uint' },
79
+ 0x8: { name: 'FlagDefault', type: 'Uint' },
80
+ 0x15aa: { name: 'FlagForced', type: 'Uint' },
81
+ 0x1c: { name: 'FlagLacing', type: 'Uint' },
82
+ 0x2de7: { name: 'MinCache', type: 'Uint' },
83
+ 0x2df8: { name: 'MaxCache', type: 'Uint' },
84
+ 0x3e383: { name: 'DefaultDuration', type: 'Uint' },
85
+ 0x34e7a: { name: 'DefaultDecodedFieldDuration', type: 'Uint' },
86
+ 0x3314f: { name: 'TrackTimecodeScale', type: 'Float' },
87
+ 0x137f: { name: 'TrackOffset', type: 'Int' },
88
+ 0x15ee: { name: 'MaxBlockAdditionID', type: 'Uint' },
89
+ 0x136e: { name: 'Name', type: 'String' },
90
+ 0x2b59c: { name: 'Language', type: 'String' },
91
+ 0x6: { name: 'CodecID', type: 'String' },
92
+ 0x23a2: { name: 'CodecPrivate', type: 'Binary' },
93
+ 0x58688: { name: 'CodecName', type: 'String' },
94
+ 0x3446: { name: 'AttachmentLink', type: 'Uint' },
95
+ 0x1a9697: { name: 'CodecSettings', type: 'String' },
96
+ 0x1b4040: { name: 'CodecInfoURL', type: 'String' },
97
+ 0x6b240: { name: 'CodecDownloadURL', type: 'String' },
98
+ 0x2a: { name: 'CodecDecodeAll', type: 'Uint' },
99
+ 0x2fab: { name: 'TrackOverlay', type: 'Uint' },
100
+ 0x16aa: { name: 'CodecDelay', type: 'Uint' },
101
+ 0x16bb: { name: 'SeekPreRoll', type: 'Uint' },
102
+ 0x2624: { name: 'TrackTranslate', type: 'Container' },
103
+ 0x26fc: { name: 'TrackTranslateEditionUID', type: 'Uint' },
104
+ 0x26bf: { name: 'TrackTranslateCodec', type: 'Uint' },
105
+ 0x26a5: { name: 'TrackTranslateTrackID', type: 'Binary' },
106
+ 0x60: { name: 'Video', type: 'Container' },
107
+ 0x1a: { name: 'FlagInterlaced', type: 'Uint' },
108
+ 0x13b8: { name: 'StereoMode', type: 'Uint' },
109
+ 0x13c0: { name: 'AlphaMode', type: 'Uint' },
110
+ 0x13b9: { name: 'OldStereoMode', type: 'Uint' },
111
+ 0x30: { name: 'PixelWidth', type: 'Uint' },
112
+ 0x3a: { name: 'PixelHeight', type: 'Uint' },
113
+ 0x14aa: { name: 'PixelCropBottom', type: 'Uint' },
114
+ 0x14bb: { name: 'PixelCropTop', type: 'Uint' },
115
+ 0x14cc: { name: 'PixelCropLeft', type: 'Uint' },
116
+ 0x14dd: { name: 'PixelCropRight', type: 'Uint' },
117
+ 0x14b0: { name: 'DisplayWidth', type: 'Uint' },
118
+ 0x14ba: { name: 'DisplayHeight', type: 'Uint' },
119
+ 0x14b2: { name: 'DisplayUnit', type: 'Uint' },
120
+ 0x14b3: { name: 'AspectRatioType', type: 'Uint' },
121
+ 0xeb524: { name: 'ColourSpace', type: 'Binary' },
122
+ 0xfb523: { name: 'GammaValue', type: 'Float' },
123
+ 0x383e3: { name: 'FrameRate', type: 'Float' },
124
+ 0x61: { name: 'Audio', type: 'Container' },
125
+ 0x35: { name: 'SamplingFrequency', type: 'Float' },
126
+ 0x38b5: { name: 'OutputSamplingFrequency', type: 'Float' },
127
+ 0x1f: { name: 'Channels', type: 'Uint' },
128
+ 0x3d7b: { name: 'ChannelPositions', type: 'Binary' },
129
+ 0x2264: { name: 'BitDepth', type: 'Uint' },
130
+ 0x62: { name: 'TrackOperation', type: 'Container' },
131
+ 0x63: { name: 'TrackCombinePlanes', type: 'Container' },
132
+ 0x64: { name: 'TrackPlane', type: 'Container' },
133
+ 0x65: { name: 'TrackPlaneUID', type: 'Uint' },
134
+ 0x66: { name: 'TrackPlaneType', type: 'Uint' },
135
+ 0x69: { name: 'TrackJoinBlocks', type: 'Container' },
136
+ 0x6d: { name: 'TrackJoinUID', type: 'Uint' },
137
+ 0x40: { name: 'TrickTrackUID', type: 'Uint' },
138
+ 0x41: { name: 'TrickTrackSegmentUID', type: 'Binary' },
139
+ 0x46: { name: 'TrickTrackFlag', type: 'Uint' },
140
+ 0x47: { name: 'TrickMasterTrackUID', type: 'Uint' },
141
+ 0x44: { name: 'TrickMasterTrackSegmentUID', type: 'Binary' },
142
+ 0x2d80: { name: 'ContentEncodings', type: 'Container' },
143
+ 0x2240: { name: 'ContentEncoding', type: 'Container' },
144
+ 0x1031: { name: 'ContentEncodingOrder', type: 'Uint' },
145
+ 0x1032: { name: 'ContentEncodingScope', type: 'Uint' },
146
+ 0x1033: { name: 'ContentEncodingType', type: 'Uint' },
147
+ 0x1034: { name: 'ContentCompression', type: 'Container' },
148
+ 0x254: { name: 'ContentCompAlgo', type: 'Uint' },
149
+ 0x255: { name: 'ContentCompSettings', type: 'Binary' },
150
+ 0x1035: { name: 'ContentEncryption', type: 'Container' },
151
+ 0x7e1: { name: 'ContentEncAlgo', type: 'Uint' },
152
+ 0x7e2: { name: 'ContentEncKeyID', type: 'Binary' },
153
+ 0x7e3: { name: 'ContentSignature', type: 'Binary' },
154
+ 0x7e4: { name: 'ContentSigKeyID', type: 'Binary' },
155
+ 0x7e5: { name: 'ContentSigAlgo', type: 'Uint' },
156
+ 0x7e6: { name: 'ContentSigHashAlgo', type: 'Uint' },
157
+ 0xc53bb6b: { name: 'Cues', type: 'Container' },
158
+ 0x3b: { name: 'CuePoint', type: 'Container' },
159
+ 0x33: { name: 'CueTime', type: 'Uint' },
160
+ 0x37: { name: 'CueTrackPositions', type: 'Container' },
161
+ 0x77: { name: 'CueTrack', type: 'Uint' },
162
+ 0x71: { name: 'CueClusterPosition', type: 'Uint' },
163
+ 0x70: { name: 'CueRelativePosition', type: 'Uint' },
164
+ 0x32: { name: 'CueDuration', type: 'Uint' },
165
+ 0x1378: { name: 'CueBlockNumber', type: 'Uint' },
166
+ 0x6a: { name: 'CueCodecState', type: 'Uint' },
167
+ 0x5b: { name: 'CueReference', type: 'Container' },
168
+ 0x16: { name: 'CueRefTime', type: 'Uint' },
169
+ 0x17: { name: 'CueRefCluster', type: 'Uint' },
170
+ 0x135f: { name: 'CueRefNumber', type: 'Uint' },
171
+ 0x6b: { name: 'CueRefCodecState', type: 'Uint' },
172
+ 0x941a469: { name: 'Attachments', type: 'Container' },
173
+ 0x21a7: { name: 'AttachedFile', type: 'Container' },
174
+ 0x67e: { name: 'FileDescription', type: 'String' },
175
+ 0x66e: { name: 'FileName', type: 'String' },
176
+ 0x660: { name: 'FileMimeType', type: 'String' },
177
+ 0x65c: { name: 'FileData', type: 'Binary' },
178
+ 0x6ae: { name: 'FileUID', type: 'Uint' },
179
+ 0x675: { name: 'FileReferral', type: 'Binary' },
180
+ 0x661: { name: 'FileUsedStartTime', type: 'Uint' },
181
+ 0x662: { name: 'FileUsedEndTime', type: 'Uint' },
182
+ 0x43a770: { name: 'Chapters', type: 'Container' },
183
+ 0x5b9: { name: 'EditionEntry', type: 'Container' },
184
+ 0x5bc: { name: 'EditionUID', type: 'Uint' },
185
+ 0x5bd: { name: 'EditionFlagHidden', type: 'Uint' },
186
+ 0x5db: { name: 'EditionFlagDefault', type: 'Uint' },
187
+ 0x5dd: { name: 'EditionFlagOrdered', type: 'Uint' },
188
+ 0x36: { name: 'ChapterAtom', type: 'Container' },
189
+ 0x33c4: { name: 'ChapterUID', type: 'Uint' },
190
+ 0x1654: { name: 'ChapterStringUID', type: 'String' },
191
+ 0x11: { name: 'ChapterTimeStart', type: 'Uint' },
192
+ 0x12: { name: 'ChapterTimeEnd', type: 'Uint' },
193
+ 0x18: { name: 'ChapterFlagHidden', type: 'Uint' },
194
+ 0x598: { name: 'ChapterFlagEnabled', type: 'Uint' },
195
+ 0x2e67: { name: 'ChapterSegmentUID', type: 'Binary' },
196
+ 0x2ebc: { name: 'ChapterSegmentEditionUID', type: 'Uint' },
197
+ 0x23c3: { name: 'ChapterPhysicalEquiv', type: 'Uint' },
198
+ 0xf: { name: 'ChapterTrack', type: 'Container' },
199
+ 0x9: { name: 'ChapterTrackNumber', type: 'Uint' },
200
+ 0x0: { name: 'ChapterDisplay', type: 'Container' },
201
+ 0x5: { name: 'ChapString', type: 'String' },
202
+ 0x37c: { name: 'ChapLanguage', type: 'String' },
203
+ 0x37e: { name: 'ChapCountry', type: 'String' },
204
+ 0x2944: { name: 'ChapProcess', type: 'Container' },
205
+ 0x2955: { name: 'ChapProcessCodecID', type: 'Uint' },
206
+ 0x50d: { name: 'ChapProcessPrivate', type: 'Binary' },
207
+ 0x2911: { name: 'ChapProcessCommand', type: 'Container' },
208
+ 0x2922: { name: 'ChapProcessTime', type: 'Uint' },
209
+ 0x2933: { name: 'ChapProcessData', type: 'Binary' },
210
+ 0x254c367: { name: 'Tags', type: 'Container' },
211
+ 0x3373: { name: 'Tag', type: 'Container' },
212
+ 0x23c0: { name: 'Targets', type: 'Container' },
213
+ 0x28ca: { name: 'TargetTypeValue', type: 'Uint' },
214
+ 0x23ca: { name: 'TargetType', type: 'String' },
215
+ 0x23c5: { name: 'TagTrackUID', type: 'Uint' },
216
+ 0x23c9: { name: 'TagEditionUID', type: 'Uint' },
217
+ 0x23c4: { name: 'TagChapterUID', type: 'Uint' },
218
+ 0x23c6: { name: 'TagAttachmentUID', type: 'Uint' },
219
+ 0x27c8: { name: 'SimpleTag', type: 'Container' },
220
+ 0x5a3: { name: 'TagName', type: 'String' },
221
+ 0x47a: { name: 'TagLanguage', type: 'String' },
222
+ 0x484: { name: 'TagDefault', type: 'Uint' },
223
+ 0x487: { name: 'TagString', type: 'String' },
224
+ 0x485: { name: 'TagBinary', type: 'Binary' },
225
+ };
226
+ function doInherit(newClass, baseClass) {
227
+ newClass.prototype = Object.create(baseClass.prototype);
228
+ newClass.prototype.constructor = newClass;
229
+ }
230
+ function WebmBase(name, type) {
231
+ this.name = name || 'Unknown';
232
+ this.type = type || 'Unknown';
233
+ }
234
+ WebmBase.prototype.updateBySource = function () {};
235
+ WebmBase.prototype.setSource = function (source) {
236
+ this.source = source;
237
+ this.updateBySource();
238
+ };
239
+ WebmBase.prototype.updateByData = function () {};
240
+ WebmBase.prototype.setData = function (data) {
241
+ this.data = data;
242
+ this.updateByData();
243
+ };
244
+ function WebmUint(name, type) {
245
+ WebmBase.call(this, name, type || 'Uint');
246
+ }
247
+ doInherit(WebmUint, WebmBase);
248
+ function padHex(hex) {
249
+ return hex.length % 2 === 1 ? '0' + hex : hex;
250
+ }
251
+ WebmUint.prototype.updateBySource = function () {
252
+ this.data = '';
253
+ for (var i = 0; i < this.source.length; i++) {
254
+ var hex = this.source[i].toString(16);
255
+ this.data += padHex(hex);
256
+ }
257
+ };
258
+ WebmUint.prototype.updateByData = function () {
259
+ var length = this.data.length / 2;
260
+ this.source = new Uint8Array(length);
261
+ for (var i = 0; i < length; i++) {
262
+ var hex = this.data.substr(i * 2, 2);
263
+ this.source[i] = parseInt(hex, 16);
264
+ }
265
+ };
266
+ WebmUint.prototype.getValue = function () {
267
+ return parseInt(this.data, 16);
268
+ };
269
+ WebmUint.prototype.setValue = function (value) {
270
+ this.setData(padHex(value.toString(16)));
271
+ };
272
+ function WebmFloat(name, type) {
273
+ WebmBase.call(this, name, type || 'Float');
274
+ }
275
+ doInherit(WebmFloat, WebmBase);
276
+ WebmFloat.prototype.getFloatArrayType = function () {
277
+ return this.source && this.source.length === 4 ? Float32Array : Float64Array;
278
+ };
279
+ WebmFloat.prototype.updateBySource = function () {
280
+ var byteArray = this.source.reverse();
281
+ var floatArrayType = this.getFloatArrayType();
282
+ var floatArray = new floatArrayType(byteArray.buffer);
283
+ this.data = floatArray[0];
284
+ };
285
+ WebmFloat.prototype.updateByData = function () {
286
+ var floatArrayType = this.getFloatArrayType();
287
+ var floatArray = new floatArrayType([this.data]);
288
+ var byteArray = new Uint8Array(floatArray.buffer);
289
+ this.source = byteArray.reverse();
290
+ };
291
+ WebmFloat.prototype.getValue = function () {
292
+ return this.data;
293
+ };
294
+ WebmFloat.prototype.setValue = function (value) {
295
+ this.setData(value);
296
+ };
297
+ function WebmContainer(name, type) {
298
+ WebmBase.call(this, name, type || 'Container');
299
+ }
300
+ doInherit(WebmContainer, WebmBase);
301
+ WebmContainer.prototype.readByte = function () {
302
+ return this.source[this.offset++];
303
+ };
304
+ WebmContainer.prototype.readUint = function () {
305
+ var firstByte = this.readByte();
306
+ var bytes = 8 - firstByte.toString(2).length;
307
+ var value = firstByte - (1 << (7 - bytes));
308
+ for (var i = 0; i < bytes; i++) {
309
+ value *= 256;
310
+ value += this.readByte();
311
+ }
312
+ return value;
313
+ };
314
+ WebmContainer.prototype.updateBySource = function () {
315
+ this.data = [];
316
+ for (this.offset = 0; this.offset < this.source.length; this.offset = end) {
317
+ var id = this.readUint();
318
+ var len = this.readUint();
319
+ var end = Math.min(this.offset + len, this.source.length);
320
+ var data = this.source.slice(this.offset, end);
321
+ var info = sections[id] || { name: 'Unknown', type: 'Unknown' };
322
+ var ctr = WebmBase;
323
+ switch (info.type) {
324
+ case 'Container': ctr = WebmContainer; break;
325
+ case 'Uint': ctr = WebmUint; break;
326
+ case 'Float': ctr = WebmFloat; break;
327
+ }
328
+ var section = new ctr(info.name, info.type);
329
+ section.setSource(data);
330
+ this.data.push({ id: id, idHex: id.toString(16), data: section });
331
+ }
332
+ };
333
+ WebmContainer.prototype.writeUint = function (x, draft) {
334
+ for (var bytes = 1, flag = 0x80; x >= flag && bytes < 8; bytes++, flag *= 0x80) {}
335
+ if (!draft) {
336
+ var value = flag + x;
337
+ for (var i = bytes - 1; i >= 0; i--) {
338
+ var c = value % 256;
339
+ this.source[this.offset + i] = c;
340
+ value = (value - c) / 256;
341
+ }
342
+ }
343
+ this.offset += bytes;
344
+ };
345
+ WebmContainer.prototype.writeSections = function (draft) {
346
+ this.offset = 0;
347
+ for (var i = 0; i < this.data.length; i++) {
348
+ var section = this.data[i], content = section.data.source, contentLength = content.length;
349
+ this.writeUint(section.id, draft);
350
+ this.writeUint(contentLength, draft);
351
+ if (!draft) { this.source.set(content, this.offset); }
352
+ this.offset += contentLength;
353
+ }
354
+ return this.offset;
355
+ };
356
+ WebmContainer.prototype.updateByData = function () {
357
+ var length = this.writeSections('draft');
358
+ this.source = new Uint8Array(length);
359
+ this.writeSections();
360
+ };
361
+ WebmContainer.prototype.getSectionById = function (id) {
362
+ for (var i = 0; i < this.data.length; i++) {
363
+ var section = this.data[i];
364
+ if (section.id === id) { return section.data; }
365
+ }
366
+ return null;
367
+ };
368
+ function WebmFile(source) {
369
+ WebmContainer.call(this, 'File', 'File');
370
+ this.setSource(source);
371
+ }
372
+ doInherit(WebmFile, WebmContainer);
373
+ WebmFile.prototype.fixDuration = function (duration, options) {
374
+ var logger = options && options.logger;
375
+ if (logger === undefined) {
376
+ logger = function (message) { console.log(message); };
377
+ } else if (!logger) {
378
+ logger = function () {};
379
+ }
380
+ var segmentSection = this.getSectionById(0x8538067);
381
+ if (!segmentSection) { logger('[sentinel-webm] Segment section is missing'); return false; }
382
+ var infoSection = segmentSection.getSectionById(0x549a966);
383
+ if (!infoSection) { logger('[sentinel-webm] Info section is missing'); return false; }
384
+ var timeScaleSection = infoSection.getSectionById(0xad7b1);
385
+ if (!timeScaleSection) { logger('[sentinel-webm] TimecodeScale section is missing'); return false; }
386
+ var durationSection = infoSection.getSectionById(0x489);
387
+ if (durationSection) {
388
+ if (durationSection.getValue() <= 0) {
389
+ logger('[sentinel-webm] Duration section is present, but the value is empty');
390
+ durationSection.setValue(duration);
391
+ } else {
392
+ logger('[sentinel-webm] Duration section is present');
393
+ return false;
394
+ }
395
+ } else {
396
+ logger('[sentinel-webm] Duration section is missing');
397
+ durationSection = new WebmFloat('Duration', 'Float');
398
+ durationSection.setValue(duration);
399
+ infoSection.data.push({ id: 0x489, data: durationSection });
400
+ }
401
+ timeScaleSection.setValue(1000000);
402
+ infoSection.updateByData();
403
+ segmentSection.updateByData();
404
+ this.updateByData();
405
+ return true;
406
+ };
407
+ WebmFile.prototype.toBlob = function (mimeType) {
408
+ return new Blob([this.source.buffer], { type: mimeType || 'video/webm' });
409
+ };
410
+ function fixWebmDuration(blob, duration, callback, options) {
411
+ if (typeof callback === 'object') { options = callback; callback = undefined; }
412
+ if (!callback) {
413
+ return new Promise(function (resolve) { fixWebmDuration(blob, duration, resolve, options); });
414
+ }
415
+ try {
416
+ var reader = new FileReader();
417
+ reader.onloadend = function () {
418
+ try {
419
+ var file = new WebmFile(new Uint8Array(reader.result));
420
+ if (file.fixDuration(duration, options)) { blob = file.toBlob(blob.type); }
421
+ } catch (ex) {}
422
+ callback(blob);
423
+ };
424
+ reader.readAsArrayBuffer(blob);
425
+ } catch (ex) { callback(blob); }
426
+ }
427
+
428
+ fixWebmDuration.default = fixWebmDuration;
429
+
430
+ export default fixWebmDuration;
431
+ export { fixWebmDuration };