nodejs-audio-visualizer 4.5.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +80 -80
  3. package/dist/audio.d.ts +12 -12
  4. package/dist/audio.js +120 -120
  5. package/dist/beats.d.ts +19 -19
  6. package/dist/beats.js +43 -43
  7. package/dist/bpmEncoder.d.ts +14 -14
  8. package/dist/bpmEncoder.js +97 -97
  9. package/dist/config.d.ts +77 -77
  10. package/dist/config.js +369 -369
  11. package/dist/dsp.d.ts +16 -16
  12. package/dist/dsp.js +76 -76
  13. package/dist/highlight.d.ts +32 -32
  14. package/dist/highlight.js +325 -325
  15. package/dist/image.d.ts +79 -79
  16. package/dist/image.js +458 -458
  17. package/dist/index.d.ts +79 -79
  18. package/dist/index.js +534 -531
  19. package/dist/index.js.map +1 -1
  20. package/dist/subtitleConvert.d.ts +3 -3
  21. package/dist/subtitleConvert.js +61 -61
  22. package/dist/video.d.ts +80 -80
  23. package/dist/video.js +434 -426
  24. package/dist/video.js.map +1 -1
  25. package/dist/waitForEventLoop.d.ts +1 -1
  26. package/dist/waitForEventLoop.js +5 -5
  27. package/package.json +61 -61
  28. package/src/audio.ts +120 -120
  29. package/src/beats.ts +68 -68
  30. package/src/bpmEncoder.ts +97 -97
  31. package/src/config.ts +476 -476
  32. package/src/dsp.ts +95 -95
  33. package/src/highlight.ts +284 -284
  34. package/src/image.ts +602 -602
  35. package/src/index.ts +718 -713
  36. package/src/subtitleConvert.ts +63 -63
  37. package/src/tests/audio.test.ts +96 -96
  38. package/src/tests/config.test.ts +496 -496
  39. package/src/tests/dsp.test.ts +24 -24
  40. package/src/tests/highlight.test.ts +178 -178
  41. package/src/tests/image.test.ts +222 -222
  42. package/src/tests/index.test.ts +180 -112
  43. package/src/tests/subtitleConvert.test.ts +23 -23
  44. package/src/tests/video.test.ts +285 -216
  45. package/src/typings.d.ts +6 -6
  46. package/src/video.ts +550 -542
  47. package/src/waitForEventLoop.ts +2 -2
@@ -1,496 +1,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
- 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
+ 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
+ });