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