nodejs-audio-visualizer 4.4.12 → 4.5.1

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