nodejs-audio-visualizer 5.1.0 → 5.3.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.
- package/LICENSE +21 -21
- package/README.md +81 -80
- package/dist/audio.d.ts +13 -13
- package/dist/audio.js +128 -128
- package/dist/beats.d.ts +39 -39
- package/dist/beats.js +220 -220
- package/dist/bpmEncoder.d.ts +14 -14
- package/dist/bpmEncoder.js +97 -97
- package/dist/config.d.ts +78 -77
- package/dist/config.js +377 -369
- package/dist/config.js.map +1 -1
- package/dist/dsp.d.ts +16 -16
- package/dist/dsp.js +76 -76
- package/dist/highlight.d.ts +66 -34
- package/dist/highlight.js +471 -334
- package/dist/highlight.js.map +1 -1
- package/dist/image.d.ts +97 -92
- package/dist/image.js +545 -538
- package/dist/image.js.map +1 -1
- package/dist/index.d.ts +87 -79
- package/dist/index.js +598 -566
- package/dist/index.js.map +1 -1
- package/dist/subtitleConvert.d.ts +3 -3
- package/dist/subtitleConvert.js +61 -61
- package/dist/video.d.ts +150 -120
- package/dist/video.js +677 -582
- package/dist/video.js.map +1 -1
- package/dist/waitForEventLoop.d.ts +1 -1
- package/dist/waitForEventLoop.js +5 -5
- package/package.json +62 -62
- package/src/audio.ts +129 -129
- package/src/beats.ts +279 -279
- package/src/bpmEncoder.ts +97 -97
- package/src/config.ts +487 -476
- package/src/dsp.ts +95 -95
- package/src/highlight.ts +451 -291
- package/src/image.ts +707 -700
- package/src/index.ts +813 -769
- package/src/subtitleConvert.ts +63 -63
- package/src/tests/audio.test.ts +102 -102
- package/src/tests/beats.test.ts +134 -134
- package/src/tests/config.test.ts +534 -496
- package/src/tests/dsp.test.ts +24 -24
- package/src/tests/highlight.test.ts +261 -178
- package/src/tests/image.test.ts +319 -308
- package/src/tests/index.test.ts +180 -180
- package/src/tests/subtitleConvert.test.ts +23 -23
- package/src/tests/video.test.ts +535 -447
- package/src/typings.d.ts +28 -28
- package/src/video.ts +856 -722
- package/src/waitForEventLoop.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -1,567 +1,599 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
var path_1 = __importDefault(require("path"));
|
|
54
|
-
var fs_1 = require("fs");
|
|
55
|
-
var config_1 = require("./config");
|
|
56
|
-
var audio_1 = require("./audio");
|
|
57
|
-
var image_1 = require("./image");
|
|
58
|
-
var subtitleConvert_1 = require("./subtitleConvert");
|
|
59
|
-
var video_1 = require("./video");
|
|
60
|
-
var bpmEncoder_1 = require("./bpmEncoder");
|
|
61
|
-
var beats_1 = require("./beats");
|
|
62
|
-
var beats_2 = require("./beats");
|
|
63
|
-
exports.estimateTempo = beats_2.estimateTempo;
|
|
64
|
-
exports.beatGridFrameIndices = beats_2.beatGridFrameIndices;
|
|
65
|
-
exports.shiftTempoPhase = beats_2.shiftTempoPhase;
|
|
66
|
-
exports.tempoForWindow = beats_2.tempoForWindow;
|
|
67
|
-
var highlight_1 = require("./highlight");
|
|
68
|
-
var waitForEventLoop_1 = require("./waitForEventLoop");
|
|
69
|
-
var highlight_2 = require("./highlight");
|
|
70
|
-
exports.computeHighlightSlice = highlight_2.computeHighlightSlice;
|
|
71
|
-
exports.HIGHLIGHT_DURATION_SEC = highlight_2.HIGHLIGHT_DURATION_SEC;
|
|
72
|
-
exports.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
var
|
|
79
|
-
var
|
|
80
|
-
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var
|
|
86
|
-
var
|
|
87
|
-
var
|
|
88
|
-
var
|
|
89
|
-
var
|
|
90
|
-
var
|
|
91
|
-
var
|
|
92
|
-
var
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
-
var
|
|
102
|
-
var
|
|
103
|
-
var
|
|
104
|
-
var
|
|
105
|
-
var
|
|
106
|
-
var
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
var
|
|
115
|
-
var
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
var
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
processingBuffer.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
_c.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return [
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
})));
|
|
208
|
-
|
|
209
|
-
case
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
var path_1 = __importDefault(require("path"));
|
|
54
|
+
var fs_1 = require("fs");
|
|
55
|
+
var config_1 = require("./config");
|
|
56
|
+
var audio_1 = require("./audio");
|
|
57
|
+
var image_1 = require("./image");
|
|
58
|
+
var subtitleConvert_1 = require("./subtitleConvert");
|
|
59
|
+
var video_1 = require("./video");
|
|
60
|
+
var bpmEncoder_1 = require("./bpmEncoder");
|
|
61
|
+
var beats_1 = require("./beats");
|
|
62
|
+
var beats_2 = require("./beats");
|
|
63
|
+
exports.estimateTempo = beats_2.estimateTempo;
|
|
64
|
+
exports.beatGridFrameIndices = beats_2.beatGridFrameIndices;
|
|
65
|
+
exports.shiftTempoPhase = beats_2.shiftTempoPhase;
|
|
66
|
+
exports.tempoForWindow = beats_2.tempoForWindow;
|
|
67
|
+
var highlight_1 = require("./highlight");
|
|
68
|
+
var waitForEventLoop_1 = require("./waitForEventLoop");
|
|
69
|
+
var highlight_2 = require("./highlight");
|
|
70
|
+
exports.computeHighlightSlice = highlight_2.computeHighlightSlice;
|
|
71
|
+
exports.HIGHLIGHT_DURATION_SEC = highlight_2.HIGHLIGHT_DURATION_SEC;
|
|
72
|
+
exports.MAX_BEAT_SNAP_SEC = highlight_2.MAX_BEAT_SNAP_SEC;
|
|
73
|
+
exports.PCM_FORMAT = {
|
|
74
|
+
bit: 8,
|
|
75
|
+
sign: 'u',
|
|
76
|
+
parseFunction: audio_1.bufferToUInt8
|
|
77
|
+
};
|
|
78
|
+
var FFMPEG_FORMAT = "" + exports.PCM_FORMAT.sign + exports.PCM_FORMAT.bit;
|
|
79
|
+
var PROCESSING_BUFFER_SIZE = Math.pow(2, 12);
|
|
80
|
+
var sleep = function (timeout) {
|
|
81
|
+
return new Promise(function (resolve) { return setTimeout(resolve, timeout); });
|
|
82
|
+
};
|
|
83
|
+
var createVisualizerFrameGenerator = function (config, backgroundWidth, backgroundHeight, defaultColor, spectrumBusMargin) {
|
|
84
|
+
if (config.outVideo.spectrum) {
|
|
85
|
+
var createSpectrumVisualizerFrame_1 = image_1.createSpectrumVisualizerFrameGenerator();
|
|
86
|
+
var spectrumWidth_1 = config_1.getSpectrumWidthAbsolute(config, backgroundWidth);
|
|
87
|
+
var spectrumHeight_1 = config_1.getSpectrumHeightAbsolute(config, backgroundHeight);
|
|
88
|
+
var spectrumX_1 = config_1.getSpectrumXAbsolute(config, spectrumWidth_1, backgroundWidth);
|
|
89
|
+
var spectrumY_1 = config_1.getSpectrumYAbsolute(config, spectrumHeight_1, backgroundHeight);
|
|
90
|
+
var spectrumRotation_1 = config_1.getSpectrumRotation(config);
|
|
91
|
+
var spectrumColor_1 = config_1.getSpectrumColor(config) || image_1.invertColor(defaultColor);
|
|
92
|
+
var spectrumEffect_1 = config_1.getSpectrumEffect(config);
|
|
93
|
+
var spectrumOpacity_1 = config_1.getSpectrumOpacityParsed(config);
|
|
94
|
+
return function (params) {
|
|
95
|
+
return createSpectrumVisualizerFrame_1(__assign(__assign({}, params), { size: { width: spectrumWidth_1, height: spectrumHeight_1 }, position: { x: spectrumX_1, y: spectrumY_1 }, rotation: spectrumRotation_1, margin: spectrumBusMargin, color: spectrumColor_1, opacity: spectrumOpacity_1, spectrumEffect: spectrumEffect_1 }));
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (config.outVideo.polar) {
|
|
99
|
+
var createPolarVisualizerFrame_1 = image_1.createPolarVisualizerFrameGenerator();
|
|
100
|
+
var polarX_1 = config_1.getPolarXAbsolute(config, backgroundWidth);
|
|
101
|
+
var polarY_1 = config_1.getPolarYAbsolute(config, backgroundHeight);
|
|
102
|
+
var polarInnerRadius_1 = config_1.getPolarInnerRadius(config);
|
|
103
|
+
var polarMaxBarLength_1 = config_1.getPolarMaxBarLength(config);
|
|
104
|
+
var polarBarWidth_1 = config_1.getPolarBarWidth(config);
|
|
105
|
+
var polarColor_1 = config_1.getPolarColor(config) || image_1.invertColor(defaultColor);
|
|
106
|
+
var polarEffect_1 = config_1.getPolarEffect(config);
|
|
107
|
+
var polarOpacity_1 = config_1.getPolarOpacityParsed(config);
|
|
108
|
+
return function (params) {
|
|
109
|
+
return createPolarVisualizerFrame_1(__assign(__assign({}, params), { centerX: polarX_1, centerY: polarY_1, innerRadius: polarInnerRadius_1, maxBarLength: polarMaxBarLength_1, barWidth: polarBarWidth_1, color: polarColor_1, opacity: polarOpacity_1, spectrumEffect: polarEffect_1 }));
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return function (params) { return params.backgroundImageBuffer; };
|
|
113
|
+
};
|
|
114
|
+
var PRE_PROCESS_PROGRESS_SHARE = 60;
|
|
115
|
+
var POST_AUDIO_PROGRESS_SHARE = 10;
|
|
116
|
+
var RENDER_PROGRESS_SHARE = 30;
|
|
117
|
+
var preProcessAudio = function (audioBuffer, sampleRate, fps, framesCount, onPreProcessProgress) { return __awaiter(void 0, void 0, void 0, function () {
|
|
118
|
+
var t, audioDataStep, processingBuffer, skipFramesCount, processSpectrum, detectBeat, spectrums, beatFrameIndices, beatEvents, nextPreProcessMilestone, i, currentFrameData, frameDataLength, frameDataTailStart, frameDataToProcess, audioDataParser, spectrum, beat, p;
|
|
119
|
+
var _a, _b;
|
|
120
|
+
return __generator(this, function (_c) {
|
|
121
|
+
switch (_c.label) {
|
|
122
|
+
case 0:
|
|
123
|
+
if (framesCount === 0) {
|
|
124
|
+
for (t = 1; t <= PRE_PROCESS_PROGRESS_SHARE; t += 1) {
|
|
125
|
+
(_a = onPreProcessProgress) === null || _a === void 0 ? void 0 : _a(t);
|
|
126
|
+
}
|
|
127
|
+
return [2 /*return*/, { spectrums: [], beatFrameIndices: [], beatEvents: [] }];
|
|
128
|
+
}
|
|
129
|
+
audioDataStep = Math.trunc(audioBuffer.length / framesCount);
|
|
130
|
+
processingBuffer = new Float32Array(PROCESSING_BUFFER_SIZE).fill(0);
|
|
131
|
+
skipFramesCount = fps < 45 ? 1 : 2;
|
|
132
|
+
processSpectrum = audio_1.createSpectrumsProcessor(sampleRate, skipFramesCount);
|
|
133
|
+
detectBeat = beats_1.createBeatDetector(fps);
|
|
134
|
+
spectrums = [];
|
|
135
|
+
beatFrameIndices = [];
|
|
136
|
+
beatEvents = [];
|
|
137
|
+
nextPreProcessMilestone = 1;
|
|
138
|
+
i = 0;
|
|
139
|
+
_c.label = 1;
|
|
140
|
+
case 1:
|
|
141
|
+
if (!(i < framesCount)) return [3 /*break*/, 4];
|
|
142
|
+
currentFrameData = exports.PCM_FORMAT.parseFunction(audioBuffer, i * audioDataStep, i * audioDataStep + audioDataStep);
|
|
143
|
+
frameDataLength = Math.min(currentFrameData.length, PROCESSING_BUFFER_SIZE);
|
|
144
|
+
frameDataTailStart = currentFrameData.length - frameDataLength;
|
|
145
|
+
frameDataToProcess = currentFrameData.slice(frameDataTailStart);
|
|
146
|
+
processingBuffer.copyWithin(0, frameDataLength);
|
|
147
|
+
processingBuffer.set(frameDataToProcess, PROCESSING_BUFFER_SIZE - frameDataLength);
|
|
148
|
+
audioDataParser = function () { return Array.from(processingBuffer); };
|
|
149
|
+
spectrum = processSpectrum(audioDataParser);
|
|
150
|
+
beat = detectBeat(spectrum);
|
|
151
|
+
spectrums.push(spectrum);
|
|
152
|
+
if (beat.isBeat) {
|
|
153
|
+
beatFrameIndices.push(i);
|
|
154
|
+
beatEvents.push({ frameIndex: i, intensity: beat.intensity });
|
|
155
|
+
}
|
|
156
|
+
p = PRE_PROCESS_PROGRESS_SHARE * (i + 1) / framesCount;
|
|
157
|
+
while (nextPreProcessMilestone <= PRE_PROCESS_PROGRESS_SHARE
|
|
158
|
+
&& p >= nextPreProcessMilestone) {
|
|
159
|
+
(_b = onPreProcessProgress) === null || _b === void 0 ? void 0 : _b(nextPreProcessMilestone);
|
|
160
|
+
nextPreProcessMilestone += 1;
|
|
161
|
+
}
|
|
162
|
+
return [4 /*yield*/, waitForEventLoop_1.waitForEventLoop()];
|
|
163
|
+
case 2:
|
|
164
|
+
_c.sent();
|
|
165
|
+
_c.label = 3;
|
|
166
|
+
case 3:
|
|
167
|
+
i++;
|
|
168
|
+
return [3 /*break*/, 1];
|
|
169
|
+
case 4: return [2 /*return*/, { spectrums: spectrums, beatFrameIndices: beatFrameIndices, beatEvents: beatEvents }];
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}); };
|
|
173
|
+
function prepareBackgroundForRender(params) {
|
|
174
|
+
var _a, _b, _c, _d, _e, _f;
|
|
175
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
176
|
+
var useVideoBackground, backgroundVideoPaths, backgroundImagePath, beatFrameIndices, beatIntensities, framesCount, outputResolution, fps, autoEditVideo, readVideoFrameTimeout, tempo, _g, startVideoIndex, videoInfos, primaryVideoInfo, backgroundWidth_1, backgroundHeight_1, videoFrameSize, encodeVideoFrame, segments, sceneChanges, _h, videoSources, concatFilePath, cutFrameIndices, videoFrameReader, firstFrame, defaultColor_1, staticBackgroundBuffer_1, backgroundImageBmpBuffer, backgroundImage, backgroundWidth, backgroundHeight, defaultColor, bpmEncoder, staticBackgroundBuffer;
|
|
177
|
+
return __generator(this, function (_j) {
|
|
178
|
+
switch (_j.label) {
|
|
179
|
+
case 0:
|
|
180
|
+
useVideoBackground = params.useVideoBackground, backgroundVideoPaths = params.backgroundVideoPaths, backgroundImagePath = params.backgroundImagePath, beatFrameIndices = params.beatFrameIndices, beatIntensities = params.beatIntensities, framesCount = params.framesCount, outputResolution = params.outputResolution, fps = params.fps, autoEditVideo = params.autoEditVideo, readVideoFrameTimeout = params.readVideoFrameTimeout, tempo = params.tempo, _g = params.startVideoIndex, startVideoIndex = _g === void 0 ? 0 : _g;
|
|
181
|
+
if (!(useVideoBackground && backgroundVideoPaths && backgroundVideoPaths.length > 0)) return [3 /*break*/, 8];
|
|
182
|
+
return [4 /*yield*/, Promise.all(backgroundVideoPaths.map(function (videoPath) { return video_1.getVideoInfo(videoPath); }))];
|
|
183
|
+
case 1:
|
|
184
|
+
videoInfos = _j.sent();
|
|
185
|
+
primaryVideoInfo = videoInfos[0];
|
|
186
|
+
backgroundWidth_1 = (_b = (_a = outputResolution) === null || _a === void 0 ? void 0 : _a.width, (_b !== null && _b !== void 0 ? _b : primaryVideoInfo.width));
|
|
187
|
+
backgroundHeight_1 = (_d = (_c = outputResolution) === null || _c === void 0 ? void 0 : _c.height, (_d !== null && _d !== void 0 ? _d : primaryVideoInfo.height));
|
|
188
|
+
videoFrameSize = backgroundWidth_1 * backgroundHeight_1 * 3;
|
|
189
|
+
encodeVideoFrame = bpmEncoder_1.createBgrFrameEncoder({ width: backgroundWidth_1, height: backgroundHeight_1 });
|
|
190
|
+
segments = void 0;
|
|
191
|
+
if (!(backgroundVideoPaths.length > 1)) return [3 /*break*/, 2];
|
|
192
|
+
segments = autoEditVideo
|
|
193
|
+
? video_1.buildShuffledVideoSegments(beatFrameIndices, framesCount, backgroundVideoPaths.length, fps, __assign({ beatIntensities: beatIntensities }, (tempo ? { tempo: tempo } : {})))
|
|
194
|
+
: video_1.buildSequentialVideoSegments(framesCount, videoInfos.map(function (info) { return info.duration; }), fps, startVideoIndex % backgroundVideoPaths.length);
|
|
195
|
+
return [3 /*break*/, 6];
|
|
196
|
+
case 2:
|
|
197
|
+
if (!autoEditVideo) return [3 /*break*/, 4];
|
|
198
|
+
return [4 /*yield*/, video_1.detectSceneChanges(backgroundVideoPaths[0])];
|
|
199
|
+
case 3:
|
|
200
|
+
_h = _j.sent();
|
|
201
|
+
return [3 /*break*/, 5];
|
|
202
|
+
case 4:
|
|
203
|
+
_h = [];
|
|
204
|
+
_j.label = 5;
|
|
205
|
+
case 5:
|
|
206
|
+
sceneChanges = _h;
|
|
207
|
+
segments = video_1.buildBeatSyncedSegments(beatFrameIndices, framesCount, sceneChanges, primaryVideoInfo.duration, fps, __assign({ beatIntensities: beatIntensities }, (autoEditVideo && tempo ? { tempo: tempo } : {})));
|
|
208
|
+
_j.label = 6;
|
|
209
|
+
case 6:
|
|
210
|
+
videoSources = videoInfos.map(function (info, i) { return ({ path: backgroundVideoPaths[i], duration: info.duration }); });
|
|
211
|
+
concatFilePath = video_1.writeConcatFile(segments, videoSources, fps);
|
|
212
|
+
cutFrameIndices = autoEditVideo ? video_1.getCutFrameIndices(segments) : [];
|
|
213
|
+
videoFrameReader = video_1.spawnConcatVideoFrameReader(__assign({ concatFilePath: concatFilePath,
|
|
214
|
+
fps: fps, totalFrames: framesCount }, (outputResolution && {
|
|
215
|
+
width: backgroundWidth_1,
|
|
216
|
+
height: backgroundHeight_1,
|
|
217
|
+
sourceWidth: primaryVideoInfo.width,
|
|
218
|
+
sourceHeight: primaryVideoInfo.height,
|
|
219
|
+
})));
|
|
220
|
+
return [4 /*yield*/, video_1.readVideoFrame(videoFrameReader.stdout, videoFrameSize, readVideoFrameTimeout)];
|
|
221
|
+
case 7:
|
|
222
|
+
firstFrame = _j.sent();
|
|
223
|
+
if (!firstFrame) {
|
|
224
|
+
throw new Error("Could not read frames from video: " + backgroundVideoPaths.join(', '));
|
|
225
|
+
}
|
|
226
|
+
defaultColor_1 = image_1.getVideoFrameColor(firstFrame, backgroundWidth_1, backgroundHeight_1);
|
|
227
|
+
staticBackgroundBuffer_1 = encodeVideoFrame(firstFrame);
|
|
228
|
+
return [2 /*return*/, {
|
|
229
|
+
backgroundWidth: backgroundWidth_1,
|
|
230
|
+
backgroundHeight: backgroundHeight_1,
|
|
231
|
+
defaultColor: defaultColor_1,
|
|
232
|
+
staticBackgroundBuffer: staticBackgroundBuffer_1,
|
|
233
|
+
videoFrameReader: videoFrameReader,
|
|
234
|
+
videoFrameSize: videoFrameSize,
|
|
235
|
+
encodeVideoFrame: encodeVideoFrame,
|
|
236
|
+
concatFilePath: concatFilePath,
|
|
237
|
+
cutFrameIndices: cutFrameIndices,
|
|
238
|
+
}];
|
|
239
|
+
case 8:
|
|
240
|
+
if (!backgroundImagePath) {
|
|
241
|
+
throw new Error('Background image path is required when not using video background.');
|
|
242
|
+
}
|
|
243
|
+
return [4 /*yield*/, image_1.convertToBmp(backgroundImagePath, (_e = outputResolution) === null || _e === void 0 ? void 0 : _e.width, (_f = outputResolution) === null || _f === void 0 ? void 0 : _f.height)];
|
|
244
|
+
case 9:
|
|
245
|
+
backgroundImageBmpBuffer = _j.sent();
|
|
246
|
+
backgroundImage = image_1.parseImage(backgroundImageBmpBuffer);
|
|
247
|
+
backgroundWidth = backgroundImage.width;
|
|
248
|
+
backgroundHeight = backgroundImage.height;
|
|
249
|
+
defaultColor = image_1.getImageColor(backgroundImage);
|
|
250
|
+
bpmEncoder = bpmEncoder_1.createBpmEncoder({ width: backgroundWidth, height: backgroundHeight });
|
|
251
|
+
staticBackgroundBuffer = bpmEncoder(backgroundImage.data);
|
|
252
|
+
return [2 /*return*/, {
|
|
253
|
+
backgroundWidth: backgroundWidth,
|
|
254
|
+
backgroundHeight: backgroundHeight,
|
|
255
|
+
defaultColor: defaultColor,
|
|
256
|
+
staticBackgroundBuffer: staticBackgroundBuffer,
|
|
257
|
+
videoFrameSize: 0,
|
|
258
|
+
cutFrameIndices: [],
|
|
259
|
+
}];
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
function resolveBackgroundFrameBuffer(params) {
|
|
265
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
266
|
+
var frameIndex, useVideoBackground, videoFrameReader, videoFrameSize, encodeVideoFrame, staticBackgroundBuffer, readVideoFrameTimeout, videoFrame;
|
|
267
|
+
return __generator(this, function (_a) {
|
|
268
|
+
switch (_a.label) {
|
|
269
|
+
case 0:
|
|
270
|
+
frameIndex = params.frameIndex, useVideoBackground = params.useVideoBackground, videoFrameReader = params.videoFrameReader, videoFrameSize = params.videoFrameSize, encodeVideoFrame = params.encodeVideoFrame, staticBackgroundBuffer = params.staticBackgroundBuffer, readVideoFrameTimeout = params.readVideoFrameTimeout;
|
|
271
|
+
if (!(useVideoBackground && videoFrameReader && encodeVideoFrame)) return [3 /*break*/, 2];
|
|
272
|
+
if (frameIndex === 0) {
|
|
273
|
+
return [2 /*return*/, { frameBuffer: staticBackgroundBuffer, frameReadFailed: false }];
|
|
274
|
+
}
|
|
275
|
+
return [4 /*yield*/, video_1.readVideoFrame(videoFrameReader.stdout, videoFrameSize, readVideoFrameTimeout)];
|
|
276
|
+
case 1:
|
|
277
|
+
videoFrame = _a.sent();
|
|
278
|
+
if (videoFrame) {
|
|
279
|
+
return [2 /*return*/, { frameBuffer: encodeVideoFrame(videoFrame), frameReadFailed: false }];
|
|
280
|
+
}
|
|
281
|
+
return [2 /*return*/, { frameBuffer: staticBackgroundBuffer, frameReadFailed: false }];
|
|
282
|
+
case 2: return [2 /*return*/, { frameBuffer: staticBackgroundBuffer, frameReadFailed: false }];
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
exports.renderAudioVisualizer = function (config, onProgress, shouldStop) {
|
|
288
|
+
return new Promise(function (resolve) { return __awaiter(void 0, void 0, void 0, function () {
|
|
289
|
+
var audioFilePath, outVideoPath, subtitleSpec, subtitleFilePath, subtitleFileIsTemporary, subtitleAlignmentAss, absPath, ext, raw, backgroundVideoPaths, backgroundImagePath, useVideoBackground, audioReader, audioBuffer, sampleRate, spectrumBusMargin, FPS, ffmpeg_cfr, ffmpeg_preset, frame_processing_delay, videoTimeouts, audioDuration, framesCount, outputResolution, maxProgressReported, reportProgress, preprocessed, autoHighlight, autoEditVideo, trackTempo, sampleRateNum, maxSamples, tempoBuffer, spectrumsForRender, beatIndicesForRender, beatIntensitiesForRender, framesCountForRender, highlightSlice, cameraShakeEnabled, shakeDelayFrames, separateHighlightFiles, passes, totalPassFrames, totalRenderMilestones, renderMilestonesCompleted, reportRenderProgress, lastExitCode, exitReason, outputVideoFiles, _loop_1, passIndex, state_1;
|
|
290
|
+
var _a, _b;
|
|
291
|
+
return __generator(this, function (_c) {
|
|
292
|
+
switch (_c.label) {
|
|
293
|
+
case 0:
|
|
294
|
+
if (config.outVideo.spectrum && config.outVideo.polar) {
|
|
295
|
+
throw new Error('Cannot use both "spectrum" and "polar" options. Please specify only one visualizer type.');
|
|
296
|
+
}
|
|
297
|
+
if (!config.image && !config.video) {
|
|
298
|
+
throw new Error('Either "image" or "video" must be specified as the background source.');
|
|
299
|
+
}
|
|
300
|
+
if (config.image && config.video) {
|
|
301
|
+
throw new Error('Cannot use both "image" and "video" options. Please specify only one background source.');
|
|
302
|
+
}
|
|
303
|
+
audioFilePath = config_1.getAudioFilePath(config);
|
|
304
|
+
outVideoPath = config_1.getOutVideoPath(config);
|
|
305
|
+
subtitleSpec = config_1.getSubtitleRenderSpec(config);
|
|
306
|
+
subtitleFileIsTemporary = false;
|
|
307
|
+
subtitleAlignmentAss = 2;
|
|
308
|
+
if (subtitleSpec) {
|
|
309
|
+
subtitleAlignmentAss = config_1.subtitleAlignmentToAss(subtitleSpec.alignment);
|
|
310
|
+
if (subtitleSpec.source.kind === 'file') {
|
|
311
|
+
absPath = subtitleSpec.source.path;
|
|
312
|
+
ext = path_1.default.extname(absPath).toLowerCase();
|
|
313
|
+
if (ext === '.lrc') {
|
|
314
|
+
raw = fs_1.readFileSync(absPath, 'utf-8');
|
|
315
|
+
subtitleFilePath = video_1.writeSubtitlesFile(subtitleConvert_1.lrcToSrt(raw));
|
|
316
|
+
subtitleFileIsTemporary = true;
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
subtitleFilePath = absPath;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
subtitleFilePath = video_1.writeSubtitlesFile(subtitleConvert_1.normalizeInlineSubtitlesToSrt(subtitleSpec.source.text));
|
|
324
|
+
subtitleFileIsTemporary = true;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
backgroundVideoPaths = config_1.getBackgroundVideoPaths(config);
|
|
328
|
+
backgroundImagePath = config_1.getBackgroundImagePath(config);
|
|
329
|
+
useVideoBackground = !!backgroundVideoPaths && backgroundVideoPaths.length > 0;
|
|
330
|
+
return [4 /*yield*/, audio_1.createAudioBuffer(audioFilePath, FFMPEG_FORMAT)];
|
|
331
|
+
case 1:
|
|
332
|
+
audioReader = _c.sent();
|
|
333
|
+
audioBuffer = audioReader.audioBuffer;
|
|
334
|
+
sampleRate = audioReader.sampleRate;
|
|
335
|
+
if (!sampleRate) {
|
|
336
|
+
throw new Error('ffmpeg didn\'t show audio sample rate');
|
|
337
|
+
}
|
|
338
|
+
spectrumBusMargin = config_1.getSpectrumBusMargin();
|
|
339
|
+
FPS = config_1.getFPS(config);
|
|
340
|
+
ffmpeg_cfr = config_1.getFfmpeg_cfr(config);
|
|
341
|
+
ffmpeg_preset = config_1.getFfmpeg_preset(config);
|
|
342
|
+
frame_processing_delay = config_1.getFrame_processing_delay(config);
|
|
343
|
+
videoTimeouts = config_1.getVideoTimeouts(config);
|
|
344
|
+
audioDuration = audioBuffer.length / sampleRate;
|
|
345
|
+
framesCount = Math.trunc(audioDuration * FPS);
|
|
346
|
+
outputResolution = config_1.getOutputResolution(config);
|
|
347
|
+
maxProgressReported = -1;
|
|
348
|
+
reportProgress = function (progress) {
|
|
349
|
+
if (!onProgress) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
var normalized = +Math.min(100, Math.max(0, progress)).toFixed(2);
|
|
353
|
+
if (normalized <= maxProgressReported) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
maxProgressReported = normalized;
|
|
357
|
+
onProgress(normalized);
|
|
358
|
+
};
|
|
359
|
+
reportProgress(0);
|
|
360
|
+
return [4 /*yield*/, preProcessAudio(audioBuffer, sampleRate, FPS, framesCount, function (progress) {
|
|
361
|
+
reportProgress(progress);
|
|
362
|
+
})];
|
|
363
|
+
case 2:
|
|
364
|
+
preprocessed = _c.sent();
|
|
365
|
+
reportProgress(PRE_PROCESS_PROGRESS_SHARE);
|
|
366
|
+
autoHighlight = config_1.getAudioAutoHighlight(config);
|
|
367
|
+
autoEditVideo = config_1.getAutoEditVideo(config);
|
|
368
|
+
trackTempo = null;
|
|
369
|
+
if (autoEditVideo || autoHighlight) {
|
|
370
|
+
sampleRateNum = Number(sampleRate);
|
|
371
|
+
maxSamples = Math.floor(sampleRateNum * beats_1.MAX_TEMPO_ANALYSIS_SECONDS);
|
|
372
|
+
tempoBuffer = audioBuffer.length > maxSamples
|
|
373
|
+
? audioBuffer.slice(0, maxSamples)
|
|
374
|
+
: audioBuffer;
|
|
375
|
+
trackTempo = beats_1.estimateTempo(audio_1.pcmU8ToFloatSamples(tempoBuffer), sampleRateNum, FPS);
|
|
376
|
+
}
|
|
377
|
+
spectrumsForRender = preprocessed.spectrums;
|
|
378
|
+
beatIndicesForRender = preprocessed.beatFrameIndices;
|
|
379
|
+
beatIntensitiesForRender = preprocessed.beatEvents.map(function (event) { return event.intensity; });
|
|
380
|
+
framesCountForRender = framesCount;
|
|
381
|
+
if (!autoHighlight) return [3 /*break*/, 4];
|
|
382
|
+
reportProgress(PRE_PROCESS_PROGRESS_SHARE + 1);
|
|
383
|
+
return [4 /*yield*/, highlight_1.computeHighlightSlice(FPS, framesCount, preprocessed.spectrums, preprocessed.beatEvents, config_1.getAudioAutoHighlightCount(config), trackTempo)];
|
|
384
|
+
case 3:
|
|
385
|
+
highlightSlice = _c.sent();
|
|
386
|
+
spectrumsForRender = highlightSlice.spectrums;
|
|
387
|
+
beatIndicesForRender = highlightSlice.beatFrameIndices;
|
|
388
|
+
beatIntensitiesForRender = highlightSlice.beatIntensities;
|
|
389
|
+
framesCountForRender = highlightSlice.highlightFrames;
|
|
390
|
+
reportProgress(PRE_PROCESS_PROGRESS_SHARE + POST_AUDIO_PROGRESS_SHARE);
|
|
391
|
+
return [3 /*break*/, 5];
|
|
392
|
+
case 4:
|
|
393
|
+
reportProgress(PRE_PROCESS_PROGRESS_SHARE + POST_AUDIO_PROGRESS_SHARE);
|
|
394
|
+
_c.label = 5;
|
|
395
|
+
case 5:
|
|
396
|
+
cameraShakeEnabled = config_1.getCameraShakeEnabled(config);
|
|
397
|
+
shakeDelayFrames = Math.round(FPS * image_1.CAMERA_SHAKE_DELAY_SECONDS);
|
|
398
|
+
separateHighlightFiles = autoHighlight &&
|
|
399
|
+
highlightSlice &&
|
|
400
|
+
highlightSlice.runs.length > 1;
|
|
401
|
+
passes = separateHighlightFiles && highlightSlice
|
|
402
|
+
? highlightSlice.runs.map(function (run, i) {
|
|
403
|
+
var dir = path_1.default.dirname(outVideoPath);
|
|
404
|
+
var ext = path_1.default.extname(outVideoPath);
|
|
405
|
+
var base = path_1.default.basename(outVideoPath, ext);
|
|
406
|
+
var numberedPath = path_1.default.resolve(dir, base + "-" + (i + 1) + ext);
|
|
407
|
+
return {
|
|
408
|
+
outPath: numberedPath,
|
|
409
|
+
spectrums: run.spectrums,
|
|
410
|
+
beatIndices: run.beatFrameIndices,
|
|
411
|
+
beatIntensities: run.beatIntensities,
|
|
412
|
+
frameCount: run.highlightFrames,
|
|
413
|
+
startFrame: run.startFrame,
|
|
414
|
+
audioSegment: run.audioSegment,
|
|
415
|
+
};
|
|
416
|
+
})
|
|
417
|
+
: [
|
|
418
|
+
{
|
|
419
|
+
outPath: outVideoPath,
|
|
420
|
+
spectrums: spectrumsForRender,
|
|
421
|
+
beatIndices: beatIndicesForRender,
|
|
422
|
+
beatIntensities: beatIntensitiesForRender,
|
|
423
|
+
frameCount: framesCountForRender,
|
|
424
|
+
startFrame: (_b = (_a = highlightSlice) === null || _a === void 0 ? void 0 : _a.startFrame, (_b !== null && _b !== void 0 ? _b : 0)),
|
|
425
|
+
audioSegment: autoHighlight &&
|
|
426
|
+
highlightSlice &&
|
|
427
|
+
highlightSlice.audioSegments.length > 0
|
|
428
|
+
? highlightSlice.audioSegments[0]
|
|
429
|
+
: undefined,
|
|
430
|
+
},
|
|
431
|
+
];
|
|
432
|
+
totalPassFrames = passes.reduce(function (sum, pass) { return sum + pass.frameCount; }, 0);
|
|
433
|
+
totalRenderMilestones = totalPassFrames + (passes.length * 2);
|
|
434
|
+
renderMilestonesCompleted = 0;
|
|
435
|
+
reportRenderProgress = function (milestoneIncrement) {
|
|
436
|
+
if (milestoneIncrement === void 0) { milestoneIncrement = 1; }
|
|
437
|
+
renderMilestonesCompleted += milestoneIncrement;
|
|
438
|
+
reportProgress(PRE_PROCESS_PROGRESS_SHARE
|
|
439
|
+
+ POST_AUDIO_PROGRESS_SHARE
|
|
440
|
+
+ (RENDER_PROGRESS_SHARE * renderMilestonesCompleted / Math.max(1, totalRenderMilestones)));
|
|
441
|
+
};
|
|
442
|
+
lastExitCode = 0;
|
|
443
|
+
outputVideoFiles = [];
|
|
444
|
+
_c.label = 6;
|
|
445
|
+
case 6:
|
|
446
|
+
_c.trys.push([6, , 11, 12]);
|
|
447
|
+
_loop_1 = function (passIndex) {
|
|
448
|
+
var pass, tempo, shakeAmplitudes, _a, backgroundWidth, backgroundHeight, defaultColor, staticBackgroundBuffer, videoFrameReader, videoFrameSize, encodeVideoFrame, concatFilePath, cutFrameIndices, beatShakeFrames, shakeFrames, createVisualizerFrame, ffmpegVideoWriter, exitPromise, stoppedEarly, i, spectrum, _b, backgroundImageBuffer, frameReadFailed, commonVisualizerFrameProps, frameImage, shakeOffset, isFrameProcessed, isDrained, _c, exitCode, ffmpegExitReason;
|
|
449
|
+
return __generator(this, function (_d) {
|
|
450
|
+
switch (_d.label) {
|
|
451
|
+
case 0:
|
|
452
|
+
pass = passes[passIndex];
|
|
453
|
+
tempo = autoEditVideo && trackTempo
|
|
454
|
+
? beats_1.tempoForWindow(trackTempo, pass.startFrame, FPS, pass.frameCount, pass.beatIndices)
|
|
455
|
+
: null;
|
|
456
|
+
shakeAmplitudes = tempo
|
|
457
|
+
? image_1.buildCutShakeAmplitudes(tempo.periodFrames)
|
|
458
|
+
: undefined;
|
|
459
|
+
return [4 /*yield*/, prepareBackgroundForRender(__assign(__assign({ useVideoBackground: useVideoBackground,
|
|
460
|
+
backgroundVideoPaths: backgroundVideoPaths,
|
|
461
|
+
backgroundImagePath: backgroundImagePath, beatFrameIndices: pass.beatIndices, beatIntensities: pass.beatIntensities, framesCount: pass.frameCount, outputResolution: outputResolution, fps: FPS, autoEditVideo: autoEditVideo, readVideoFrameTimeout: videoTimeouts.readVideoFrame }, (tempo ? { tempo: tempo } : {})), {
|
|
462
|
+
// Each separate highlight output opens with a different video from the array.
|
|
463
|
+
startVideoIndex: passIndex }))];
|
|
464
|
+
case 1:
|
|
465
|
+
_a = _d.sent(), backgroundWidth = _a.backgroundWidth, backgroundHeight = _a.backgroundHeight, defaultColor = _a.defaultColor, staticBackgroundBuffer = _a.staticBackgroundBuffer, videoFrameReader = _a.videoFrameReader, videoFrameSize = _a.videoFrameSize, encodeVideoFrame = _a.encodeVideoFrame, concatFilePath = _a.concatFilePath, cutFrameIndices = _a.cutFrameIndices;
|
|
466
|
+
reportRenderProgress();
|
|
467
|
+
beatShakeFrames = function () { return (tempo
|
|
468
|
+
? beats_1.beatGridFrameIndices(tempo, pass.frameCount, image_1.CAMERA_SHAKE_EVERY_BEATS)
|
|
469
|
+
: pass.beatIndices.filter(function (frameIndex) { return frameIndex > 0; }).filter(function (_, i) { return i % image_1.CAMERA_SHAKE_EVERY_BEATS === 0; })); };
|
|
470
|
+
shakeFrames = new Set(autoEditVideo && cameraShakeEnabled
|
|
471
|
+
? (cutFrameIndices.length > 0 ? cutFrameIndices : beatShakeFrames())
|
|
472
|
+
: []);
|
|
473
|
+
createVisualizerFrame = createVisualizerFrameGenerator(config, backgroundWidth, backgroundHeight, defaultColor, spectrumBusMargin);
|
|
474
|
+
ffmpegVideoWriter = video_1.spawnFfmpegVideoWriter(__assign(__assign(__assign(__assign(__assign({ audioFilename: audioFilePath, videoFileName: pass.outPath }, (subtitleFilePath && {
|
|
475
|
+
subtitleFilename: subtitleFilePath,
|
|
476
|
+
subtitleAlignmentAss: subtitleAlignmentAss,
|
|
477
|
+
})), { fps: FPS }), (pass.audioSegment && { audioSegment: pass.audioSegment })), (ffmpeg_cfr && { crf: ffmpeg_cfr })), (ffmpeg_preset && { preset: ffmpeg_preset })));
|
|
478
|
+
exitPromise = video_1.waitForProcessExit(ffmpegVideoWriter, videoTimeouts.waitForProcessExit);
|
|
479
|
+
stoppedEarly = false;
|
|
480
|
+
i = 0;
|
|
481
|
+
_d.label = 2;
|
|
482
|
+
case 2:
|
|
483
|
+
if (!(i < pass.frameCount)) return [3 /*break*/, 10];
|
|
484
|
+
spectrum = pass.spectrums[i];
|
|
485
|
+
return [4 /*yield*/, resolveBackgroundFrameBuffer({
|
|
486
|
+
frameIndex: i,
|
|
487
|
+
useVideoBackground: useVideoBackground,
|
|
488
|
+
videoFrameReader: videoFrameReader,
|
|
489
|
+
videoFrameSize: videoFrameSize,
|
|
490
|
+
encodeVideoFrame: encodeVideoFrame,
|
|
491
|
+
staticBackgroundBuffer: staticBackgroundBuffer,
|
|
492
|
+
readVideoFrameTimeout: videoTimeouts.readVideoFrame,
|
|
493
|
+
})];
|
|
494
|
+
case 3:
|
|
495
|
+
_b = _d.sent(), backgroundImageBuffer = _b.frameBuffer, frameReadFailed = _b.frameReadFailed;
|
|
496
|
+
commonVisualizerFrameProps = {
|
|
497
|
+
backgroundImageBuffer: backgroundImageBuffer,
|
|
498
|
+
spectrum: spectrum,
|
|
499
|
+
};
|
|
500
|
+
frameImage = createVisualizerFrame(commonVisualizerFrameProps);
|
|
501
|
+
shakeOffset = image_1.getCutShakeOffset(i, shakeFrames, shakeAmplitudes, shakeDelayFrames);
|
|
502
|
+
if (shakeOffset.x !== 0 || shakeOffset.y !== 0) {
|
|
503
|
+
image_1.applyCameraShake(frameImage, backgroundWidth, backgroundHeight, shakeOffset.x, shakeOffset.y);
|
|
504
|
+
}
|
|
505
|
+
isFrameProcessed = ffmpegVideoWriter.stdin.write(frameImage.data);
|
|
506
|
+
if (!!isFrameProcessed) return [3 /*break*/, 5];
|
|
507
|
+
return [4 /*yield*/, video_1.waitDrain(ffmpegVideoWriter.stdin, ffmpegVideoWriter, videoTimeouts.waitDrain)];
|
|
508
|
+
case 4:
|
|
509
|
+
isDrained = _d.sent();
|
|
510
|
+
if (!isDrained) {
|
|
511
|
+
stoppedEarly = true;
|
|
512
|
+
exitReason = 'ffmpeg stdin drain failed';
|
|
513
|
+
return [3 /*break*/, 10];
|
|
514
|
+
}
|
|
515
|
+
_d.label = 5;
|
|
516
|
+
case 5:
|
|
517
|
+
if (shouldStop && shouldStop()) {
|
|
518
|
+
stoppedEarly = true;
|
|
519
|
+
exitReason = 'render stopped by shouldStop callback';
|
|
520
|
+
return [3 /*break*/, 10];
|
|
521
|
+
}
|
|
522
|
+
if (!frame_processing_delay) return [3 /*break*/, 7];
|
|
523
|
+
return [4 /*yield*/, sleep(frame_processing_delay)];
|
|
524
|
+
case 6:
|
|
525
|
+
_d.sent();
|
|
526
|
+
_d.label = 7;
|
|
527
|
+
case 7: return [4 /*yield*/, waitForEventLoop_1.waitForEventLoop()];
|
|
528
|
+
case 8:
|
|
529
|
+
_d.sent();
|
|
530
|
+
reportRenderProgress();
|
|
531
|
+
_d.label = 9;
|
|
532
|
+
case 9:
|
|
533
|
+
i++;
|
|
534
|
+
return [3 /*break*/, 2];
|
|
535
|
+
case 10:
|
|
536
|
+
if (videoFrameReader) {
|
|
537
|
+
videoFrameReader.kill();
|
|
538
|
+
}
|
|
539
|
+
if (concatFilePath) {
|
|
540
|
+
video_1.cleanupConcatFile(concatFilePath);
|
|
541
|
+
}
|
|
542
|
+
ffmpegVideoWriter.stdin.end();
|
|
543
|
+
return [4 /*yield*/, exitPromise];
|
|
544
|
+
case 11:
|
|
545
|
+
_c = _d.sent(), exitCode = _c.exitCode, ffmpegExitReason = _c.reason;
|
|
546
|
+
lastExitCode = exitCode;
|
|
547
|
+
if (!exitReason && ffmpegExitReason) {
|
|
548
|
+
exitReason = ffmpegExitReason;
|
|
549
|
+
}
|
|
550
|
+
if (lastExitCode === 0 && !stoppedEarly) {
|
|
551
|
+
reportRenderProgress();
|
|
552
|
+
}
|
|
553
|
+
if (lastExitCode === 0 && !stoppedEarly) {
|
|
554
|
+
outputVideoFiles.push(pass.outPath);
|
|
555
|
+
}
|
|
556
|
+
if (stoppedEarly || lastExitCode !== 0) {
|
|
557
|
+
if (exitReason && lastExitCode === 0) {
|
|
558
|
+
lastExitCode = 1;
|
|
559
|
+
}
|
|
560
|
+
return [2 /*return*/, "break-passLoop"];
|
|
561
|
+
}
|
|
562
|
+
return [2 /*return*/];
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
};
|
|
566
|
+
passIndex = 0;
|
|
567
|
+
_c.label = 7;
|
|
568
|
+
case 7:
|
|
569
|
+
if (!(passIndex < passes.length)) return [3 /*break*/, 10];
|
|
570
|
+
return [5 /*yield**/, _loop_1(passIndex)];
|
|
571
|
+
case 8:
|
|
572
|
+
state_1 = _c.sent();
|
|
573
|
+
switch (state_1) {
|
|
574
|
+
case "break-passLoop": return [3 /*break*/, 10];
|
|
575
|
+
}
|
|
576
|
+
_c.label = 9;
|
|
577
|
+
case 9:
|
|
578
|
+
passIndex++;
|
|
579
|
+
return [3 /*break*/, 7];
|
|
580
|
+
case 10:
|
|
581
|
+
if (lastExitCode === 0 && outputVideoFiles.length === passes.length) {
|
|
582
|
+
reportProgress(100);
|
|
583
|
+
}
|
|
584
|
+
if (exitReason) {
|
|
585
|
+
console.error(exitReason);
|
|
586
|
+
}
|
|
587
|
+
resolve({ exitCode: lastExitCode, reason: exitReason, outputVideoFiles: outputVideoFiles });
|
|
588
|
+
return [3 /*break*/, 12];
|
|
589
|
+
case 11:
|
|
590
|
+
if (subtitleFilePath && subtitleFileIsTemporary) {
|
|
591
|
+
video_1.cleanupTempFile(subtitleFilePath);
|
|
592
|
+
}
|
|
593
|
+
return [7 /*endfinally*/];
|
|
594
|
+
case 12: return [2 /*return*/];
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
}); });
|
|
598
|
+
};
|
|
567
599
|
//# sourceMappingURL=index.js.map
|