nodejs-audio-visualizer 5.5.3 → 5.6.4

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 (49) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +84 -83
  3. package/dist/audio.d.ts +13 -13
  4. package/dist/audio.js +128 -128
  5. package/dist/beats.d.ts +39 -39
  6. package/dist/beats.js +220 -220
  7. package/dist/bpmEncoder.d.ts +14 -14
  8. package/dist/bpmEncoder.js +97 -97
  9. package/dist/config.d.ts +81 -80
  10. package/dist/config.js +392 -391
  11. package/dist/config.js.map +1 -1
  12. package/dist/dsp.d.ts +16 -16
  13. package/dist/dsp.js +76 -76
  14. package/dist/highlight.d.ts +91 -91
  15. package/dist/highlight.js +606 -606
  16. package/dist/image.d.ts +107 -97
  17. package/dist/image.js +614 -545
  18. package/dist/image.js.map +1 -1
  19. package/dist/index.d.ts +98 -96
  20. package/dist/index.js +673 -667
  21. package/dist/index.js.map +1 -1
  22. package/dist/subtitleConvert.d.ts +3 -3
  23. package/dist/subtitleConvert.js +61 -61
  24. package/dist/video.d.ts +171 -171
  25. package/dist/video.js +743 -743
  26. package/dist/waitForEventLoop.d.ts +1 -1
  27. package/dist/waitForEventLoop.js +5 -5
  28. package/package.json +62 -62
  29. package/src/audio.ts +129 -129
  30. package/src/beats.ts +279 -279
  31. package/src/bpmEncoder.ts +97 -97
  32. package/src/config.ts +504 -501
  33. package/src/dsp.ts +95 -95
  34. package/src/highlight.ts +617 -617
  35. package/src/image.ts +791 -707
  36. package/src/index.ts +896 -885
  37. package/src/subtitleConvert.ts +63 -63
  38. package/src/tests/audio.test.ts +102 -102
  39. package/src/tests/beats.test.ts +134 -134
  40. package/src/tests/config.test.ts +568 -553
  41. package/src/tests/dsp.test.ts +24 -24
  42. package/src/tests/highlight.test.ts +397 -397
  43. package/src/tests/image.test.ts +371 -319
  44. package/src/tests/index.test.ts +180 -180
  45. package/src/tests/subtitleConvert.test.ts +23 -23
  46. package/src/tests/video.test.ts +652 -652
  47. package/src/typings.d.ts +28 -28
  48. package/src/video.ts +947 -947
  49. package/src/waitForEventLoop.ts +2 -2
@@ -1,553 +1,568 @@
1
- import path from 'path';
2
- import { expect } from 'chai';
3
- import { Config } from '../index';
4
- import {
5
- defaults,
6
- getAudioFilePath,
7
- getAudioAutoHighlight,
8
- getAudioAutoHighlightCount,
9
- getBackgroundImagePath,
10
- getBackgroundVideoPaths,
11
- getHookVideoPath,
12
- getCameraShakeEnabled,
13
- getOutVideoPath,
14
- getSubtitleRenderSpec,
15
- subtitleAlignmentToAss,
16
- getFPS,
17
- getSpectrumWidthAbsolute,
18
- getSpectrumHeightAbsolute,
19
- getSpectrumXAbsolute,
20
- getSpectrumYAbsolute,
21
- getSpectrumColor,
22
- getSpectrumOpacity,
23
- getSpectrumOpacityParsed,
24
- getFfmpeg_cfr,
25
- getFfmpeg_preset,
26
- getFrame_processing_delay,
27
- getVideoTimeouts,
28
- checkIsValidRotationAlias,
29
- checkIsPercentValue
30
- } from '../config';
31
-
32
- describe('config', function() {
33
- it('getAudioFilePath', function() {
34
- const result = getAudioFilePath({
35
- audio: { path: 'test/path' }
36
- } as Config);
37
- const expected = path.resolve('test/path');
38
- expect(result).equal(expected);
39
- });
40
-
41
- it('getAudioAutoHighlight', function() {
42
- expect(
43
- getAudioAutoHighlight({ audio: { path: 'a.wav' } } as Config)
44
- ).equal(false);
45
- expect(
46
- getAudioAutoHighlight({ audio: { path: 'a.wav', autoHighlight: false } } as Config)
47
- ).equal(false);
48
- expect(
49
- getAudioAutoHighlight({ audio: { path: 'a.wav', autoHighlight: true } } as Config)
50
- ).equal(true);
51
- });
52
-
53
- it('getAudioAutoHighlightCount', function() {
54
- expect(
55
- getAudioAutoHighlightCount({ audio: { path: 'a.wav' } } as Config)
56
- ).equal(1);
57
- expect(
58
- getAudioAutoHighlightCount({ audio: { path: 'a.wav', autoHighlightCount: 3 } } as Config)
59
- ).equal(3);
60
- expect(
61
- getAudioAutoHighlightCount.bind(undefined, { audio: { path: 'a.wav', autoHighlightCount: 0 } } as Config)
62
- ).to.throw('Invalid audio.autoHighlightCount');
63
- expect(
64
- getAudioAutoHighlightCount.bind(undefined, { audio: { path: 'a.wav', autoHighlightCount: 1.5 } } as Config)
65
- ).to.throw('Invalid audio.autoHighlightCount');
66
- expect(
67
- getAudioAutoHighlightCount.bind(undefined, { audio: { path: 'a.wav', autoHighlightCount: NaN } } as Config)
68
- ).to.throw('Invalid audio.autoHighlightCount');
69
- });
70
-
71
- it('getBackgroundImagePath', function() {
72
- const result = getBackgroundImagePath({
73
- image: { path: 'test/path' }
74
- } as Config);
75
- const expected = path.resolve('test/path');
76
- expect(result).equal(expected);
77
- });
78
-
79
- it('getBackgroundVideoPaths', function() {
80
- expect(
81
- getBackgroundVideoPaths({ audio: { path: 'a.wav' } } as Config)
82
- ).equal(undefined);
83
-
84
- expect(
85
- getBackgroundVideoPaths({ video: { path: 'test/path' } } as Config)
86
- ).deep.equal([path.resolve('test/path')]);
87
-
88
- expect(
89
- getBackgroundVideoPaths({ video: { path: ['a.mp4', 'b.mp4'] } } as Config)
90
- ).deep.equal([path.resolve('a.mp4'), path.resolve('b.mp4')]);
91
-
92
- expect(
93
- getBackgroundVideoPaths.bind(undefined, { video: { path: [] } } as unknown as Config)
94
- ).to.throw('Invalid video.path');
95
- });
96
-
97
- it('getHookVideoPath', function() {
98
- expect(
99
- getHookVideoPath({ audio: { path: 'a.wav' } } as Config)
100
- ).equal(undefined);
101
-
102
- expect(
103
- getHookVideoPath({ video: { path: 'a.mp4' } } as Config)
104
- ).equal(undefined);
105
-
106
- expect(
107
- getHookVideoPath({ video: { path: 'a.mp4', hookPath: 'hook.mp4' } } as Config)
108
- ).equal(path.resolve('hook.mp4'));
109
-
110
- expect(
111
- getHookVideoPath.bind(undefined, { video: { path: 'a.mp4', hookPath: '' } } as Config)
112
- ).to.throw('Invalid video.hookPath');
113
- });
114
-
115
- it('getCameraShakeEnabled', function() {
116
- expect(
117
- getCameraShakeEnabled({ audio: { path: 'a.wav' } } as Config)
118
- ).equal(true);
119
-
120
- expect(
121
- getCameraShakeEnabled({ video: { path: 'test/path' } } as Config)
122
- ).equal(true);
123
-
124
- expect(
125
- getCameraShakeEnabled({ video: { path: 'test/path', cameraShake: true } } as Config)
126
- ).equal(true);
127
-
128
- expect(
129
- getCameraShakeEnabled({ video: { path: 'test/path', cameraShake: false } } as Config)
130
- ).equal(false);
131
- });
132
-
133
- it('getOutVideoPath', function() {
134
- const result = getOutVideoPath({
135
- outVideo: { path: 'test/path' }
136
- } as Config);
137
- const expected = path.resolve('test/path');
138
- expect(result).equal(expected);
139
- });
140
-
141
- it('getSubtitleRenderSpec', function() {
142
- expect(
143
- getSubtitleRenderSpec({ outVideo: {} } as Config)
144
- ).equal(undefined);
145
-
146
- expect(
147
- getSubtitleRenderSpec({
148
- outVideo: { subtitles: '1\n00:00:00,000 --> 00:00:01,000\nTest' }
149
- } as Config)
150
- ).deep.equal({
151
- source: { kind: 'inline', text: '1\n00:00:00,000 --> 00:00:01,000\nTest' },
152
- alignment: 'bottom',
153
- });
154
-
155
- expect(
156
- getSubtitleRenderSpec({
157
- outVideo: {
158
- subtitles: { rawContent: '1\n00:00:00,000 --> 00:00:01,000\nHi', alignment: 'top' }
159
- }
160
- } as Config)
161
- ).deep.equal({
162
- source: { kind: 'inline', text: '1\n00:00:00,000 --> 00:00:01,000\nHi' },
163
- alignment: 'top',
164
- });
165
-
166
- expect(
167
- getSubtitleRenderSpec({
168
- outVideo: { subtitles: { path: 'media/sub.srt' } }
169
- } as Config)
170
- ).deep.equal({
171
- source: { kind: 'file', path: path.resolve('media/sub.srt') },
172
- alignment: 'bottom',
173
- });
174
-
175
- expect(
176
- getSubtitleRenderSpec({ outVideo: { subtitles: {} } } as Config)
177
- ).equal(undefined);
178
-
179
- expect(
180
- getSubtitleRenderSpec.bind(undefined, {
181
- outVideo: { subtitles: '' }
182
- } as unknown as Config)
183
- ).to.throw('Invalid outVideo.subtitles: expected non-empty string content');
184
-
185
- expect(
186
- getSubtitleRenderSpec.bind(undefined, {
187
- outVideo: {
188
- subtitles: { path: 'a.lrc', rawContent: 'x' }
189
- }
190
- } as Config)
191
- ).to.throw(
192
- 'Invalid outVideo.subtitles: specify only one of "path" or "rawContent", not both.',
193
- );
194
-
195
- expect(
196
- getSubtitleRenderSpec.bind(undefined, {
197
- outVideo: { subtitles: { alignment: 'center' as any } }
198
- } as Config)
199
- ).to.throw('Invalid outVideo.subtitles.alignment');
200
- });
201
-
202
- it('subtitleAlignmentToAss', function() {
203
- expect(subtitleAlignmentToAss('bottom')).equal(2);
204
- expect(subtitleAlignmentToAss('middle')).equal(10);
205
- expect(subtitleAlignmentToAss('top')).equal(6);
206
- });
207
-
208
- it('getFPS', function() {
209
- const result1 = getFPS({
210
- outVideo: {}
211
- } as Config);
212
- expect(result1).equal(defaults.fps);
213
-
214
- const result2 = getFPS({
215
- outVideo: { fps: 15 }
216
- } as Config);
217
- expect(result2).equal(15);
218
- });
219
-
220
- it('checkIsPercentValue', function() {
221
- const result1 = checkIsPercentValue('69%');
222
- expect(result1).equal(true);
223
-
224
- const result2 = checkIsPercentValue('69');
225
- expect(result2).equal(false);
226
-
227
- const result3 = checkIsPercentValue('fake value');
228
- expect(result3).equal(false);
229
- });
230
-
231
- it('getSpectrumWidthAbsolute', function() {
232
- const backgroundImageWidth = 1366;
233
- const result1 = getSpectrumWidthAbsolute({
234
- outVideo: {}
235
- } as Config, backgroundImageWidth);
236
- expect(result1).equal(
237
- backgroundImageWidth * (parseInt(defaults.spectrumWidth) / 100)
238
- );
239
-
240
- const result2 = getSpectrumWidthAbsolute({
241
- outVideo: { spectrum: { width: 600 }}
242
- } as Config, backgroundImageWidth);
243
- expect(result2).equal(600);
244
-
245
- const result3 = getSpectrumWidthAbsolute({
246
- outVideo: { spectrum: { width: '69%' }}
247
- } as Config, backgroundImageWidth);
248
- expect(result3).equal(backgroundImageWidth * 0.69);
249
-
250
- const result4 = getSpectrumWidthAbsolute.bind(
251
- undefined,
252
- {
253
- outVideo: { spectrum: { width: '69' }}
254
- } as Config,
255
- backgroundImageWidth
256
- );
257
- expect(result4).to.throw('Invalid spectrum width value: \'69\'. Use number value or percent value in string, for example: \'30%\'.');
258
-
259
- const result5 = getSpectrumWidthAbsolute.bind(
260
- undefined,
261
- {
262
- outVideo: { spectrum: { width: 1 }}
263
- } as Config,
264
- backgroundImageWidth
265
- );
266
- expect(result5).to.throw('Spectrum width \'1\' is too small.');
267
-
268
- const result6 = getSpectrumWidthAbsolute.bind(
269
- undefined,
270
- {
271
- outVideo: { spectrum: { width: '1%' }}
272
- } as Config,
273
- backgroundImageWidth
274
- );
275
- expect(result6).to.throw('Spectrum width \'1%\' is too small.');
276
- });
277
-
278
- it('getSpectrumHeightAbsolute', function() {
279
- const backgroundImageHeight = 720;
280
- const result1 = getSpectrumHeightAbsolute({
281
- outVideo: {}
282
- } as Config, backgroundImageHeight);
283
- expect(result1).equal(160);
284
-
285
- const result2 = getSpectrumHeightAbsolute({
286
- outVideo: { spectrum: { height: 420 }}
287
- } as Config, backgroundImageHeight);
288
- expect(result2).equal(420);
289
-
290
- const result3 = getSpectrumHeightAbsolute({
291
- outVideo: { spectrum: { height: '69%' }}
292
- } as Config, backgroundImageHeight);
293
- expect(result3).equal(backgroundImageHeight * 0.69);
294
-
295
- const result4 = getSpectrumHeightAbsolute.bind(
296
- undefined,
297
- {
298
- outVideo: { spectrum: { height: '69' }}
299
- } as Config,
300
- backgroundImageHeight
301
- );
302
- expect(result4).to.throw('Invalid spectrum height value: \'69\'. Use number value or percent value in string, for example: \'30%\'.');
303
- });
304
-
305
- it('getSpectrumXAbsolute', function() {
306
- const spectrumWidth = 420;
307
- const backgroundImageWidth = 1366;
308
- const result1 = getSpectrumXAbsolute(
309
- {
310
- outVideo: {},
311
- } as Config,
312
- spectrumWidth,
313
- backgroundImageWidth
314
- );
315
- expect(result1).equal(
316
- 0.5 * backgroundImageWidth - spectrumWidth / 2
317
- );
318
-
319
- const result2 = getSpectrumXAbsolute(
320
- {
321
- outVideo: { spectrum: { x: 420 } }
322
- } as Config,
323
- spectrumWidth,
324
- backgroundImageWidth
325
- );
326
- expect(result2).equal(420);
327
-
328
- const result3 = getSpectrumXAbsolute(
329
- {
330
- outVideo: { spectrum: { x: 'left' } }
331
- } as Config,
332
- spectrumWidth,
333
- backgroundImageWidth
334
- );
335
- expect(result3).equal(0);
336
-
337
- const result4 = getSpectrumXAbsolute(
338
- {
339
- outVideo: { spectrum: { x: 'center' } }
340
- } as Config,
341
- spectrumWidth,
342
- backgroundImageWidth
343
- );
344
- expect(result4).equal(
345
- 0.5 * backgroundImageWidth - spectrumWidth / 2
346
- );
347
-
348
- const result5 = getSpectrumXAbsolute(
349
- {
350
- outVideo: { spectrum: { x: 'right' } }
351
- } as Config,
352
- spectrumWidth,
353
- backgroundImageWidth
354
- );
355
- expect(result5).equal(
356
- 1 * backgroundImageWidth - spectrumWidth
357
- );
358
-
359
- const result6 = getSpectrumXAbsolute.bind(
360
- undefined,
361
- {
362
- outVideo: { spectrum: { x: 'sagewklkg' } }
363
- } as unknown as Config,
364
- spectrumWidth,
365
- backgroundImageWidth
366
- );
367
- expect(result6).to.throw('Invalid spectrum x value: sagewklkg. Valid values: left, center, right, top, middle, bottom.');
368
- });
369
-
370
- it('getSpectrumYAbsolute', function() {
371
- const spectrumHeight = 125;
372
- const backgroundImageHeight = 721;
373
- const result1 = getSpectrumYAbsolute(
374
- {
375
- outVideo: {},
376
- } as Config,
377
- spectrumHeight,
378
- backgroundImageHeight
379
- );
380
- expect(result1).equal(
381
- 298
382
- );
383
-
384
- const result2 = getSpectrumYAbsolute(
385
- {
386
- outVideo: { spectrum: { y: 69 } }
387
- } as Config,
388
- spectrumHeight,
389
- backgroundImageHeight
390
- );
391
- expect(result2).equal(69);
392
-
393
- const result3 = getSpectrumYAbsolute(
394
- {
395
- outVideo: { spectrum: { y: 'top' } }
396
- } as Config,
397
- spectrumHeight,
398
- backgroundImageHeight
399
- );
400
- expect(result3).equal(0);
401
-
402
- const result4 = getSpectrumYAbsolute(
403
- {
404
- outVideo: { spectrum: { y: 'middle' } }
405
- } as Config,
406
- spectrumHeight,
407
- backgroundImageHeight
408
- );
409
- expect(result4).equal(
410
- 0.5 * backgroundImageHeight - spectrumHeight / 2
411
- );
412
-
413
- const result5 = getSpectrumYAbsolute(
414
- {
415
- outVideo: { spectrum: { y: 'bottom' } }
416
- } as Config,
417
- spectrumHeight,
418
- backgroundImageHeight
419
- );
420
- expect(result5).equal(
421
- 1 * backgroundImageHeight - spectrumHeight
422
- );
423
-
424
- const result6 = getSpectrumYAbsolute.bind(
425
- undefined,
426
- {
427
- outVideo: { spectrum: { y: 'asokosckm' } }
428
- } as unknown as Config,
429
- spectrumHeight,
430
- backgroundImageHeight
431
- );
432
- expect(result6).to.throw('Invalid spectrum y value: asokosckm. Valid values: left, center, right, top, middle, bottom.');
433
- });
434
-
435
- it('getSpectrumColor', function() {
436
- const result1 = getSpectrumColor({
437
- outVideo: {}
438
- } as Config);
439
- expect(result1).equal(undefined);
440
-
441
- const result2 = getSpectrumColor({
442
- outVideo: { spectrum: { color: '#cccc99' } }
443
- } as Config);
444
- expect(result2).equal('#cccc99');
445
- });
446
-
447
- it('getSpectrumOpacity', function() {
448
- const result1 = getSpectrumOpacity({
449
- outVideo: {}
450
- } as Config);
451
- expect(result1).equal(defaults.spectrumOpacity);
452
-
453
- const result2 = getSpectrumOpacity({
454
- outVideo: { spectrum: { opacity: '69%' } }
455
- } as Config);
456
- expect(result2).equal('69%');
457
- });
458
-
459
- it('getSpectrumOpacityParsed', function() {
460
- const result1 = getSpectrumOpacityParsed({
461
- outVideo: {}
462
- } as Config);
463
- expect(result1).equal(parseInt(defaults.spectrumOpacity) / 100);
464
-
465
- const result2 = getSpectrumOpacityParsed({
466
- outVideo: { spectrum: { opacity: '69%' } }
467
- } as Config);
468
- expect(result2).equal(0.69);
469
-
470
- const result3 = getSpectrumOpacityParsed.bind(
471
- undefined,
472
- {
473
- outVideo: { spectrum: { opacity: 'fake value' } }
474
- } as Config
475
- );
476
- expect(result3).to.throw('Invalid spectrum opacity value: \'fake value\'. Use string percent value, for example \'80%\'.');
477
-
478
- const result4 = getSpectrumOpacityParsed.bind(
479
- undefined,
480
- {
481
- outVideo: { spectrum: { opacity: '103%' } }
482
- } as Config
483
- );
484
- expect(result4).to.throw('Invalid spectrum opacity value: \'103%\'. Percent values must be in range from \'0%\' to \'100%\'.');
485
- });
486
-
487
- it('getFfmpeg_cfr', function() {
488
- const result1 = getFfmpeg_cfr({
489
- tweaks: {}
490
- } as Config);
491
- expect(result1).equal(undefined);
492
-
493
- const result2 = getFfmpeg_cfr({
494
- tweaks: { ffmpeg_cfr: '69' }
495
- } as Config);
496
- expect(result2).equal('69');
497
- });
498
-
499
- it('getFfmpeg_preset', function() {
500
- const result1 = getFfmpeg_preset({
501
- tweaks: {}
502
- } as Config);
503
- expect(result1).equal(undefined);
504
-
505
- const result2 = getFfmpeg_preset({
506
- tweaks: { ffmpeg_preset: 'quality' }
507
- } as Config);
508
- expect(result2).equal('quality');
509
- });
510
-
511
- it('getFrame_processing_delay', function() {
512
- const result1 = getFrame_processing_delay({
513
- tweaks: {}
514
- } as Config);
515
- expect(result1).equal(undefined);
516
-
517
- const result2 = getFrame_processing_delay({
518
- tweaks: { frame_processing_delay: 420 }
519
- } as Config);
520
- expect(result2).equal(420);
521
- });
522
-
523
- it('getVideoTimeouts', function() {
524
- const result1 = getVideoTimeouts({ tweaks: {} } as Config);
525
- expect(result1).deep.equal(defaults.timeouts);
526
-
527
- const result2 = getVideoTimeouts({
528
- tweaks: {
529
- timeouts: {
530
- readVideoFrame: 1000,
531
- waitDrain: 2000,
532
- waitForProcessExit: 3000,
533
- },
534
- },
535
- } as Config);
536
- expect(result2).deep.equal({
537
- readVideoFrame: 1000,
538
- waitDrain: 2000,
539
- waitForProcessExit: 3000,
540
- });
541
- });
542
-
543
- it('checkIsValidRotationAlias', function() {
544
- const result1 = checkIsValidRotationAlias('up');
545
- expect(result1).equal(true);
546
-
547
- const result2 = checkIsValidRotationAlias('down');
548
- expect(result2).equal(true);
549
-
550
- const result3 = checkIsValidRotationAlias('fake value');
551
- expect(result3).equal(false);
552
- });
553
- });
1
+ import path from 'path';
2
+ import { expect } from 'chai';
3
+ import { Config } from '../index';
4
+ import {
5
+ defaults,
6
+ getAudioFilePath,
7
+ getAudioAutoHighlight,
8
+ getAudioAutoHighlightCount,
9
+ getBackgroundImagePath,
10
+ getBackgroundVideoPaths,
11
+ getHookVideoPath,
12
+ getCameraShakeEnabled,
13
+ getCutZoomEnabled,
14
+ getOutVideoPath,
15
+ getSubtitleRenderSpec,
16
+ subtitleAlignmentToAss,
17
+ getFPS,
18
+ getSpectrumWidthAbsolute,
19
+ getSpectrumHeightAbsolute,
20
+ getSpectrumXAbsolute,
21
+ getSpectrumYAbsolute,
22
+ getSpectrumColor,
23
+ getSpectrumOpacity,
24
+ getSpectrumOpacityParsed,
25
+ getFfmpeg_cfr,
26
+ getFfmpeg_preset,
27
+ getFrame_processing_delay,
28
+ getVideoTimeouts,
29
+ checkIsValidRotationAlias,
30
+ checkIsPercentValue
31
+ } from '../config';
32
+
33
+ describe('config', function() {
34
+ it('getAudioFilePath', function() {
35
+ const result = getAudioFilePath({
36
+ audio: { path: 'test/path' }
37
+ } as Config);
38
+ const expected = path.resolve('test/path');
39
+ expect(result).equal(expected);
40
+ });
41
+
42
+ it('getAudioAutoHighlight', function() {
43
+ expect(
44
+ getAudioAutoHighlight({ audio: { path: 'a.wav' } } as Config)
45
+ ).equal(false);
46
+ expect(
47
+ getAudioAutoHighlight({ audio: { path: 'a.wav', autoHighlight: false } } as Config)
48
+ ).equal(false);
49
+ expect(
50
+ getAudioAutoHighlight({ audio: { path: 'a.wav', autoHighlight: true } } as Config)
51
+ ).equal(true);
52
+ });
53
+
54
+ it('getAudioAutoHighlightCount', function() {
55
+ expect(
56
+ getAudioAutoHighlightCount({ audio: { path: 'a.wav' } } as Config)
57
+ ).equal(1);
58
+ expect(
59
+ getAudioAutoHighlightCount({ audio: { path: 'a.wav', autoHighlightCount: 3 } } as Config)
60
+ ).equal(3);
61
+ expect(
62
+ getAudioAutoHighlightCount.bind(undefined, { audio: { path: 'a.wav', autoHighlightCount: 0 } } as Config)
63
+ ).to.throw('Invalid audio.autoHighlightCount');
64
+ expect(
65
+ getAudioAutoHighlightCount.bind(undefined, { audio: { path: 'a.wav', autoHighlightCount: 1.5 } } as Config)
66
+ ).to.throw('Invalid audio.autoHighlightCount');
67
+ expect(
68
+ getAudioAutoHighlightCount.bind(undefined, { audio: { path: 'a.wav', autoHighlightCount: NaN } } as Config)
69
+ ).to.throw('Invalid audio.autoHighlightCount');
70
+ });
71
+
72
+ it('getBackgroundImagePath', function() {
73
+ const result = getBackgroundImagePath({
74
+ image: { path: 'test/path' }
75
+ } as Config);
76
+ const expected = path.resolve('test/path');
77
+ expect(result).equal(expected);
78
+ });
79
+
80
+ it('getBackgroundVideoPaths', function() {
81
+ expect(
82
+ getBackgroundVideoPaths({ audio: { path: 'a.wav' } } as Config)
83
+ ).equal(undefined);
84
+
85
+ expect(
86
+ getBackgroundVideoPaths({ video: { path: 'test/path' } } as Config)
87
+ ).deep.equal([path.resolve('test/path')]);
88
+
89
+ expect(
90
+ getBackgroundVideoPaths({ video: { path: ['a.mp4', 'b.mp4'] } } as Config)
91
+ ).deep.equal([path.resolve('a.mp4'), path.resolve('b.mp4')]);
92
+
93
+ expect(
94
+ getBackgroundVideoPaths.bind(undefined, { video: { path: [] } } as unknown as Config)
95
+ ).to.throw('Invalid video.path');
96
+ });
97
+
98
+ it('getHookVideoPath', function() {
99
+ expect(
100
+ getHookVideoPath({ audio: { path: 'a.wav' } } as Config)
101
+ ).equal(undefined);
102
+
103
+ expect(
104
+ getHookVideoPath({ video: { path: 'a.mp4' } } as Config)
105
+ ).equal(undefined);
106
+
107
+ expect(
108
+ getHookVideoPath({ video: { path: 'a.mp4', hookPath: 'hook.mp4' } } as Config)
109
+ ).equal(path.resolve('hook.mp4'));
110
+
111
+ expect(
112
+ getHookVideoPath.bind(undefined, { video: { path: 'a.mp4', hookPath: '' } } as Config)
113
+ ).to.throw('Invalid video.hookPath');
114
+ });
115
+
116
+ it('getCameraShakeEnabled', function() {
117
+ expect(
118
+ getCameraShakeEnabled({ audio: { path: 'a.wav' } } as Config)
119
+ ).equal(true);
120
+
121
+ expect(
122
+ getCameraShakeEnabled({ video: { path: 'test/path' } } as Config)
123
+ ).equal(true);
124
+
125
+ expect(
126
+ getCameraShakeEnabled({ video: { path: 'test/path', cameraShake: true } } as Config)
127
+ ).equal(true);
128
+
129
+ expect(
130
+ getCameraShakeEnabled({ video: { path: 'test/path', cameraShake: false } } as Config)
131
+ ).equal(false);
132
+ });
133
+
134
+ it('getCutZoomEnabled', function() {
135
+ expect(
136
+ getCutZoomEnabled({ video: { path: 'test/path' } } as Config)
137
+ ).equal(false);
138
+
139
+ expect(
140
+ getCutZoomEnabled({ video: { path: 'test/path', cutZoom: true } } as Config)
141
+ ).equal(true);
142
+
143
+ expect(
144
+ getCutZoomEnabled({ video: { path: 'test/path', cutZoom: false } } as Config)
145
+ ).equal(false);
146
+ });
147
+
148
+ it('getOutVideoPath', function() {
149
+ const result = getOutVideoPath({
150
+ outVideo: { path: 'test/path' }
151
+ } as Config);
152
+ const expected = path.resolve('test/path');
153
+ expect(result).equal(expected);
154
+ });
155
+
156
+ it('getSubtitleRenderSpec', function() {
157
+ expect(
158
+ getSubtitleRenderSpec({ outVideo: {} } as Config)
159
+ ).equal(undefined);
160
+
161
+ expect(
162
+ getSubtitleRenderSpec({
163
+ outVideo: { subtitles: '1\n00:00:00,000 --> 00:00:01,000\nTest' }
164
+ } as Config)
165
+ ).deep.equal({
166
+ source: { kind: 'inline', text: '1\n00:00:00,000 --> 00:00:01,000\nTest' },
167
+ alignment: 'bottom',
168
+ });
169
+
170
+ expect(
171
+ getSubtitleRenderSpec({
172
+ outVideo: {
173
+ subtitles: { rawContent: '1\n00:00:00,000 --> 00:00:01,000\nHi', alignment: 'top' }
174
+ }
175
+ } as Config)
176
+ ).deep.equal({
177
+ source: { kind: 'inline', text: '1\n00:00:00,000 --> 00:00:01,000\nHi' },
178
+ alignment: 'top',
179
+ });
180
+
181
+ expect(
182
+ getSubtitleRenderSpec({
183
+ outVideo: { subtitles: { path: 'media/sub.srt' } }
184
+ } as Config)
185
+ ).deep.equal({
186
+ source: { kind: 'file', path: path.resolve('media/sub.srt') },
187
+ alignment: 'bottom',
188
+ });
189
+
190
+ expect(
191
+ getSubtitleRenderSpec({ outVideo: { subtitles: {} } } as Config)
192
+ ).equal(undefined);
193
+
194
+ expect(
195
+ getSubtitleRenderSpec.bind(undefined, {
196
+ outVideo: { subtitles: '' }
197
+ } as unknown as Config)
198
+ ).to.throw('Invalid outVideo.subtitles: expected non-empty string content');
199
+
200
+ expect(
201
+ getSubtitleRenderSpec.bind(undefined, {
202
+ outVideo: {
203
+ subtitles: { path: 'a.lrc', rawContent: 'x' }
204
+ }
205
+ } as Config)
206
+ ).to.throw(
207
+ 'Invalid outVideo.subtitles: specify only one of "path" or "rawContent", not both.',
208
+ );
209
+
210
+ expect(
211
+ getSubtitleRenderSpec.bind(undefined, {
212
+ outVideo: { subtitles: { alignment: 'center' as any } }
213
+ } as Config)
214
+ ).to.throw('Invalid outVideo.subtitles.alignment');
215
+ });
216
+
217
+ it('subtitleAlignmentToAss', function() {
218
+ expect(subtitleAlignmentToAss('bottom')).equal(2);
219
+ expect(subtitleAlignmentToAss('middle')).equal(10);
220
+ expect(subtitleAlignmentToAss('top')).equal(6);
221
+ });
222
+
223
+ it('getFPS', function() {
224
+ const result1 = getFPS({
225
+ outVideo: {}
226
+ } as Config);
227
+ expect(result1).equal(defaults.fps);
228
+
229
+ const result2 = getFPS({
230
+ outVideo: { fps: 15 }
231
+ } as Config);
232
+ expect(result2).equal(15);
233
+ });
234
+
235
+ it('checkIsPercentValue', function() {
236
+ const result1 = checkIsPercentValue('69%');
237
+ expect(result1).equal(true);
238
+
239
+ const result2 = checkIsPercentValue('69');
240
+ expect(result2).equal(false);
241
+
242
+ const result3 = checkIsPercentValue('fake value');
243
+ expect(result3).equal(false);
244
+ });
245
+
246
+ it('getSpectrumWidthAbsolute', function() {
247
+ const backgroundImageWidth = 1366;
248
+ const result1 = getSpectrumWidthAbsolute({
249
+ outVideo: {}
250
+ } as Config, backgroundImageWidth);
251
+ expect(result1).equal(
252
+ backgroundImageWidth * (parseInt(defaults.spectrumWidth) / 100)
253
+ );
254
+
255
+ const result2 = getSpectrumWidthAbsolute({
256
+ outVideo: { spectrum: { width: 600 }}
257
+ } as Config, backgroundImageWidth);
258
+ expect(result2).equal(600);
259
+
260
+ const result3 = getSpectrumWidthAbsolute({
261
+ outVideo: { spectrum: { width: '69%' }}
262
+ } as Config, backgroundImageWidth);
263
+ expect(result3).equal(backgroundImageWidth * 0.69);
264
+
265
+ const result4 = getSpectrumWidthAbsolute.bind(
266
+ undefined,
267
+ {
268
+ outVideo: { spectrum: { width: '69' }}
269
+ } as Config,
270
+ backgroundImageWidth
271
+ );
272
+ expect(result4).to.throw('Invalid spectrum width value: \'69\'. Use number value or percent value in string, for example: \'30%\'.');
273
+
274
+ const result5 = getSpectrumWidthAbsolute.bind(
275
+ undefined,
276
+ {
277
+ outVideo: { spectrum: { width: 1 }}
278
+ } as Config,
279
+ backgroundImageWidth
280
+ );
281
+ expect(result5).to.throw('Spectrum width \'1\' is too small.');
282
+
283
+ const result6 = getSpectrumWidthAbsolute.bind(
284
+ undefined,
285
+ {
286
+ outVideo: { spectrum: { width: '1%' }}
287
+ } as Config,
288
+ backgroundImageWidth
289
+ );
290
+ expect(result6).to.throw('Spectrum width \'1%\' is too small.');
291
+ });
292
+
293
+ it('getSpectrumHeightAbsolute', function() {
294
+ const backgroundImageHeight = 720;
295
+ const result1 = getSpectrumHeightAbsolute({
296
+ outVideo: {}
297
+ } as Config, backgroundImageHeight);
298
+ expect(result1).equal(160);
299
+
300
+ const result2 = getSpectrumHeightAbsolute({
301
+ outVideo: { spectrum: { height: 420 }}
302
+ } as Config, backgroundImageHeight);
303
+ expect(result2).equal(420);
304
+
305
+ const result3 = getSpectrumHeightAbsolute({
306
+ outVideo: { spectrum: { height: '69%' }}
307
+ } as Config, backgroundImageHeight);
308
+ expect(result3).equal(backgroundImageHeight * 0.69);
309
+
310
+ const result4 = getSpectrumHeightAbsolute.bind(
311
+ undefined,
312
+ {
313
+ outVideo: { spectrum: { height: '69' }}
314
+ } as Config,
315
+ backgroundImageHeight
316
+ );
317
+ expect(result4).to.throw('Invalid spectrum height value: \'69\'. Use number value or percent value in string, for example: \'30%\'.');
318
+ });
319
+
320
+ it('getSpectrumXAbsolute', function() {
321
+ const spectrumWidth = 420;
322
+ const backgroundImageWidth = 1366;
323
+ const result1 = getSpectrumXAbsolute(
324
+ {
325
+ outVideo: {},
326
+ } as Config,
327
+ spectrumWidth,
328
+ backgroundImageWidth
329
+ );
330
+ expect(result1).equal(
331
+ 0.5 * backgroundImageWidth - spectrumWidth / 2
332
+ );
333
+
334
+ const result2 = getSpectrumXAbsolute(
335
+ {
336
+ outVideo: { spectrum: { x: 420 } }
337
+ } as Config,
338
+ spectrumWidth,
339
+ backgroundImageWidth
340
+ );
341
+ expect(result2).equal(420);
342
+
343
+ const result3 = getSpectrumXAbsolute(
344
+ {
345
+ outVideo: { spectrum: { x: 'left' } }
346
+ } as Config,
347
+ spectrumWidth,
348
+ backgroundImageWidth
349
+ );
350
+ expect(result3).equal(0);
351
+
352
+ const result4 = getSpectrumXAbsolute(
353
+ {
354
+ outVideo: { spectrum: { x: 'center' } }
355
+ } as Config,
356
+ spectrumWidth,
357
+ backgroundImageWidth
358
+ );
359
+ expect(result4).equal(
360
+ 0.5 * backgroundImageWidth - spectrumWidth / 2
361
+ );
362
+
363
+ const result5 = getSpectrumXAbsolute(
364
+ {
365
+ outVideo: { spectrum: { x: 'right' } }
366
+ } as Config,
367
+ spectrumWidth,
368
+ backgroundImageWidth
369
+ );
370
+ expect(result5).equal(
371
+ 1 * backgroundImageWidth - spectrumWidth
372
+ );
373
+
374
+ const result6 = getSpectrumXAbsolute.bind(
375
+ undefined,
376
+ {
377
+ outVideo: { spectrum: { x: 'sagewklkg' } }
378
+ } as unknown as Config,
379
+ spectrumWidth,
380
+ backgroundImageWidth
381
+ );
382
+ expect(result6).to.throw('Invalid spectrum x value: sagewklkg. Valid values: left, center, right, top, middle, bottom.');
383
+ });
384
+
385
+ it('getSpectrumYAbsolute', function() {
386
+ const spectrumHeight = 125;
387
+ const backgroundImageHeight = 721;
388
+ const result1 = getSpectrumYAbsolute(
389
+ {
390
+ outVideo: {},
391
+ } as Config,
392
+ spectrumHeight,
393
+ backgroundImageHeight
394
+ );
395
+ expect(result1).equal(
396
+ 298
397
+ );
398
+
399
+ const result2 = getSpectrumYAbsolute(
400
+ {
401
+ outVideo: { spectrum: { y: 69 } }
402
+ } as Config,
403
+ spectrumHeight,
404
+ backgroundImageHeight
405
+ );
406
+ expect(result2).equal(69);
407
+
408
+ const result3 = getSpectrumYAbsolute(
409
+ {
410
+ outVideo: { spectrum: { y: 'top' } }
411
+ } as Config,
412
+ spectrumHeight,
413
+ backgroundImageHeight
414
+ );
415
+ expect(result3).equal(0);
416
+
417
+ const result4 = getSpectrumYAbsolute(
418
+ {
419
+ outVideo: { spectrum: { y: 'middle' } }
420
+ } as Config,
421
+ spectrumHeight,
422
+ backgroundImageHeight
423
+ );
424
+ expect(result4).equal(
425
+ 0.5 * backgroundImageHeight - spectrumHeight / 2
426
+ );
427
+
428
+ const result5 = getSpectrumYAbsolute(
429
+ {
430
+ outVideo: { spectrum: { y: 'bottom' } }
431
+ } as Config,
432
+ spectrumHeight,
433
+ backgroundImageHeight
434
+ );
435
+ expect(result5).equal(
436
+ 1 * backgroundImageHeight - spectrumHeight
437
+ );
438
+
439
+ const result6 = getSpectrumYAbsolute.bind(
440
+ undefined,
441
+ {
442
+ outVideo: { spectrum: { y: 'asokosckm' } }
443
+ } as unknown as Config,
444
+ spectrumHeight,
445
+ backgroundImageHeight
446
+ );
447
+ expect(result6).to.throw('Invalid spectrum y value: asokosckm. Valid values: left, center, right, top, middle, bottom.');
448
+ });
449
+
450
+ it('getSpectrumColor', function() {
451
+ const result1 = getSpectrumColor({
452
+ outVideo: {}
453
+ } as Config);
454
+ expect(result1).equal(undefined);
455
+
456
+ const result2 = getSpectrumColor({
457
+ outVideo: { spectrum: { color: '#cccc99' } }
458
+ } as Config);
459
+ expect(result2).equal('#cccc99');
460
+ });
461
+
462
+ it('getSpectrumOpacity', function() {
463
+ const result1 = getSpectrumOpacity({
464
+ outVideo: {}
465
+ } as Config);
466
+ expect(result1).equal(defaults.spectrumOpacity);
467
+
468
+ const result2 = getSpectrumOpacity({
469
+ outVideo: { spectrum: { opacity: '69%' } }
470
+ } as Config);
471
+ expect(result2).equal('69%');
472
+ });
473
+
474
+ it('getSpectrumOpacityParsed', function() {
475
+ const result1 = getSpectrumOpacityParsed({
476
+ outVideo: {}
477
+ } as Config);
478
+ expect(result1).equal(parseInt(defaults.spectrumOpacity) / 100);
479
+
480
+ const result2 = getSpectrumOpacityParsed({
481
+ outVideo: { spectrum: { opacity: '69%' } }
482
+ } as Config);
483
+ expect(result2).equal(0.69);
484
+
485
+ const result3 = getSpectrumOpacityParsed.bind(
486
+ undefined,
487
+ {
488
+ outVideo: { spectrum: { opacity: 'fake value' } }
489
+ } as Config
490
+ );
491
+ expect(result3).to.throw('Invalid spectrum opacity value: \'fake value\'. Use string percent value, for example \'80%\'.');
492
+
493
+ const result4 = getSpectrumOpacityParsed.bind(
494
+ undefined,
495
+ {
496
+ outVideo: { spectrum: { opacity: '103%' } }
497
+ } as Config
498
+ );
499
+ expect(result4).to.throw('Invalid spectrum opacity value: \'103%\'. Percent values must be in range from \'0%\' to \'100%\'.');
500
+ });
501
+
502
+ it('getFfmpeg_cfr', function() {
503
+ const result1 = getFfmpeg_cfr({
504
+ tweaks: {}
505
+ } as Config);
506
+ expect(result1).equal(undefined);
507
+
508
+ const result2 = getFfmpeg_cfr({
509
+ tweaks: { ffmpeg_cfr: '69' }
510
+ } as Config);
511
+ expect(result2).equal('69');
512
+ });
513
+
514
+ it('getFfmpeg_preset', function() {
515
+ const result1 = getFfmpeg_preset({
516
+ tweaks: {}
517
+ } as Config);
518
+ expect(result1).equal(undefined);
519
+
520
+ const result2 = getFfmpeg_preset({
521
+ tweaks: { ffmpeg_preset: 'quality' }
522
+ } as Config);
523
+ expect(result2).equal('quality');
524
+ });
525
+
526
+ it('getFrame_processing_delay', function() {
527
+ const result1 = getFrame_processing_delay({
528
+ tweaks: {}
529
+ } as Config);
530
+ expect(result1).equal(undefined);
531
+
532
+ const result2 = getFrame_processing_delay({
533
+ tweaks: { frame_processing_delay: 420 }
534
+ } as Config);
535
+ expect(result2).equal(420);
536
+ });
537
+
538
+ it('getVideoTimeouts', function() {
539
+ const result1 = getVideoTimeouts({ tweaks: {} } as Config);
540
+ expect(result1).deep.equal(defaults.timeouts);
541
+
542
+ const result2 = getVideoTimeouts({
543
+ tweaks: {
544
+ timeouts: {
545
+ readVideoFrame: 1000,
546
+ waitDrain: 2000,
547
+ waitForProcessExit: 3000,
548
+ },
549
+ },
550
+ } as Config);
551
+ expect(result2).deep.equal({
552
+ readVideoFrame: 1000,
553
+ waitDrain: 2000,
554
+ waitForProcessExit: 3000,
555
+ });
556
+ });
557
+
558
+ it('checkIsValidRotationAlias', function() {
559
+ const result1 = checkIsValidRotationAlias('up');
560
+ expect(result1).equal(true);
561
+
562
+ const result2 = checkIsValidRotationAlias('down');
563
+ expect(result2).equal(true);
564
+
565
+ const result3 = checkIsValidRotationAlias('fake value');
566
+ expect(result3).equal(false);
567
+ });
568
+ });