nodejs-audio-visualizer 1.4.0 → 2.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.
- package/README.md +2 -2
- package/dist/config.d.ts +3 -2
- package/dist/config.js +28 -12
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +32 -13
- package/src/index.ts +4 -2
- package/src/tests/config.test.ts +35 -5
- package/src/tests/image.test.ts +17 -2
- package/src/tests/snapshots/frameSnapshotSpectrumDown.json +1 -0
- package/src/tests/snapshots/frameSnapshotSpectrumUp.json +1 -0
package/README.md
CHANGED
|
@@ -16,8 +16,8 @@ const config = {
|
|
|
16
16
|
path: 'media/out.mp4',
|
|
17
17
|
fps: 25, // Default value: 60
|
|
18
18
|
spectrum: { // Audio spectrum configuration. Optional.
|
|
19
|
-
width:
|
|
20
|
-
height:
|
|
19
|
+
width: '30%', // 30% of background image width. Default value: 40%. Also you can use absolute values. For example, value 300 for 300 pixels width.
|
|
20
|
+
height: '15%', // 15% of background image height. Default value: 10%. Also you can use absolute values. For example, value 300 for 300 pixels height.
|
|
21
21
|
x: 'center', // Available values: 'left', 'center', right'. Also you can use absolute number values. For example, value 300 for 300 pixels x.
|
|
22
22
|
y: 'bottom', // Available values: 'top', 'middle', bottom'. Also you can use absolute number values. For example, value 300 for 300 pixels y.
|
|
23
23
|
rotation: 'up', // Available values: 'up', 'down'. Default value: 'down'.
|
package/dist/config.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Config } from './index';
|
|
2
2
|
export declare const defaults: {
|
|
3
3
|
fps: number;
|
|
4
|
-
spectrumWidth:
|
|
5
|
-
spectrumHeight:
|
|
4
|
+
spectrumWidth: string;
|
|
5
|
+
spectrumHeight: string;
|
|
6
6
|
spectrumX: string;
|
|
7
7
|
spectrumY: string;
|
|
8
8
|
spectrumRotation: string;
|
|
9
9
|
};
|
|
10
10
|
export declare const rotationAliasValues: readonly ["up", "down"];
|
|
11
|
+
export declare const checkIsPercentValue: (value: string) => boolean;
|
|
11
12
|
export declare const getAudioFilePath: (config: Config) => string;
|
|
12
13
|
export declare const getBackgroundImagePath: (config: Config) => string;
|
|
13
14
|
export declare const getOutVideoPath: (config: Config) => string;
|
package/dist/config.js
CHANGED
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
var path_1 = __importDefault(require("path"));
|
|
7
7
|
exports.defaults = {
|
|
8
8
|
fps: 60,
|
|
9
|
-
spectrumWidth:
|
|
10
|
-
spectrumHeight:
|
|
9
|
+
spectrumWidth: '40%',
|
|
10
|
+
spectrumHeight: '10%',
|
|
11
11
|
spectrumX: 'center',
|
|
12
12
|
spectrumY: 'top',
|
|
13
13
|
spectrumRotation: 'down'
|
|
@@ -21,8 +21,8 @@ var postitionAliases = [
|
|
|
21
21
|
{ name: 'bottom', value: 1 },
|
|
22
22
|
];
|
|
23
23
|
exports.rotationAliasValues = ['up', 'down'];
|
|
24
|
-
|
|
25
|
-
return
|
|
24
|
+
exports.checkIsPercentValue = function (value) {
|
|
25
|
+
return RegExp(/\d+%/).test(value);
|
|
26
26
|
};
|
|
27
27
|
exports.getAudioFilePath = function (config) {
|
|
28
28
|
return path_1.default.resolve(config.audio.path);
|
|
@@ -40,13 +40,28 @@ var getSpectrumWidth = function (config) {
|
|
|
40
40
|
return (config.outVideo.spectrum && config.outVideo.spectrum.width) ||
|
|
41
41
|
exports.defaults.spectrumWidth;
|
|
42
42
|
};
|
|
43
|
+
var getSpectrumSizeAbsolute = function (spectrumSize, backgroundImageSize) {
|
|
44
|
+
if (typeof spectrumSize === 'number') {
|
|
45
|
+
return spectrumSize;
|
|
46
|
+
}
|
|
47
|
+
var isPercentValue = exports.checkIsPercentValue(spectrumSize);
|
|
48
|
+
if (!isPercentValue) {
|
|
49
|
+
throw new Error();
|
|
50
|
+
}
|
|
51
|
+
var percentValue = parseInt(spectrumSize) / 100;
|
|
52
|
+
return backgroundImageSize * percentValue;
|
|
53
|
+
};
|
|
54
|
+
var getSpectrumSizeValueErrorMessage = function (fieldName, value) {
|
|
55
|
+
return "Invalid spectrum " + fieldName + " value: '" + value + "'. Use number value or percent value in string, for example: '30%'.";
|
|
56
|
+
};
|
|
43
57
|
exports.getSpectrumWidthAbsolute = function (config, backgroundImageWidth) {
|
|
44
58
|
var spectrumWidth = getSpectrumWidth(config);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
59
|
+
try {
|
|
60
|
+
return getSpectrumSizeAbsolute(spectrumWidth, backgroundImageWidth);
|
|
61
|
+
}
|
|
62
|
+
catch (_a) {
|
|
63
|
+
throw new Error(getSpectrumSizeValueErrorMessage('width', spectrumWidth));
|
|
48
64
|
}
|
|
49
|
-
return backgroundImageWidth * spectrumWidth;
|
|
50
65
|
};
|
|
51
66
|
var getSpectrumHeight = function (config) {
|
|
52
67
|
return (config.outVideo.spectrum && config.outVideo.spectrum.height) ||
|
|
@@ -54,11 +69,12 @@ var getSpectrumHeight = function (config) {
|
|
|
54
69
|
};
|
|
55
70
|
exports.getSpectrumHeightAbsolute = function (config, backgroundImageHeight) {
|
|
56
71
|
var spectrumHeight = getSpectrumHeight(config);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
72
|
+
try {
|
|
73
|
+
return getSpectrumSizeAbsolute(spectrumHeight, backgroundImageHeight);
|
|
74
|
+
}
|
|
75
|
+
catch (_a) {
|
|
76
|
+
throw new Error(getSpectrumSizeValueErrorMessage('height', spectrumHeight));
|
|
60
77
|
}
|
|
61
|
-
return backgroundImageHeight * spectrumHeight;
|
|
62
78
|
};
|
|
63
79
|
var getSpectrumX = function (config) {
|
|
64
80
|
return parseNumberIfPossible((config.outVideo.spectrum && config.outVideo.spectrum.x) ||
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.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,QAAQ,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;AAA5D,CAA4D,CAAC;AAElD,QAAA,aAAa,GAAG,UAAC,MAAc;IAC1C,OAAA,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU;AAAzC,CAAyC,CAAC;AAE/B,QAAA,gBAAgB,GAAG,UAAC,MAAc;IAC7C,OAAA,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,aAAa;AAA5C,CAA4C,CAAC;AAElC,QAAA,yBAAyB,GAAG,UAAC,MAAc;IACtD,OAAA,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,sBAAsB;AAArD,CAAqD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -17,8 +17,8 @@ export interface Config {
|
|
|
17
17
|
path: string;
|
|
18
18
|
fps?: number;
|
|
19
19
|
spectrum?: {
|
|
20
|
-
width?:
|
|
21
|
-
height?:
|
|
20
|
+
width?: SpectrumSizeValue;
|
|
21
|
+
height?: SpectrumSizeValue;
|
|
22
22
|
x?: number | PositionAliasName;
|
|
23
23
|
y?: number | PositionAliasName;
|
|
24
24
|
rotation?: RotationAliasName;
|
|
@@ -31,6 +31,7 @@ export interface Config {
|
|
|
31
31
|
frame_processing_delay?: number;
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
+
export declare type SpectrumSizeValue = number | string;
|
|
34
35
|
export declare type PositionAliasName = 'left' | 'center' | 'right' | 'top' | 'middle' | 'bottom';
|
|
35
36
|
export declare type RotationAliasName = typeof rotationAliasValues[number];
|
|
36
37
|
export declare const renderAudioVisualizer: (config: Config, onProgress?: ((progress: number) => any) | undefined, shouldStop?: (() => boolean) | undefined) => Promise<number>;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;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AE3C,IAAI,UAAU,IAAI,UAAU,EAAE,EAAE;;qCAE/B;yCACG,sBAAsB,EAAtB,wBAAsB;oCACxB,qBAAM,KAAK,CAAC,sBAAsB,CAAC,EAAA;;oCAAnC,SAAmC,CAAC;;;;;;oBArB/B,CAAC,GAAG,CAAC;;;yBAAE,CAAA,CAAC,GAAG,WAAW,CAAA;kDAAtB,CAAC;;;;;;;oBAAuB,CAAC,EAAE,CAAA;;;oBAyBpC,iBAAiB,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;;;;SAC/B,CAAC;AA1EF,CA0EE,CAAC"}
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { Config, PositionAliasName, RotationAliasName } from './index';
|
|
2
|
+
import { Config, SpectrumSizeValue, PositionAliasName, RotationAliasName } from './index';
|
|
3
3
|
|
|
4
4
|
export const defaults = {
|
|
5
5
|
fps: 60,
|
|
6
|
-
spectrumWidth:
|
|
7
|
-
spectrumHeight:
|
|
6
|
+
spectrumWidth: '40%',
|
|
7
|
+
spectrumHeight: '10%',
|
|
8
8
|
spectrumX: 'center',
|
|
9
9
|
spectrumY: 'top',
|
|
10
10
|
spectrumRotation: 'down'
|
|
@@ -28,8 +28,8 @@ const postitionAliases: PositionAlias[] = [
|
|
|
28
28
|
|
|
29
29
|
export const rotationAliasValues = ['up', 'down'] as const;
|
|
30
30
|
|
|
31
|
-
const
|
|
32
|
-
|
|
31
|
+
export const checkIsPercentValue = (value: string) =>
|
|
32
|
+
RegExp(/\d+%/).test(value)
|
|
33
33
|
|
|
34
34
|
export const getAudioFilePath = (config: Config) =>
|
|
35
35
|
path.resolve(config.audio.path);
|
|
@@ -47,15 +47,34 @@ const getSpectrumWidth = (config: Config) =>
|
|
|
47
47
|
(config.outVideo.spectrum && config.outVideo.spectrum.width) ||
|
|
48
48
|
defaults.spectrumWidth;
|
|
49
49
|
|
|
50
|
+
const getSpectrumSizeAbsolute = (
|
|
51
|
+
spectrumSize: SpectrumSizeValue, backgroundImageSize: number
|
|
52
|
+
) => {
|
|
53
|
+
if (typeof spectrumSize === 'number') {
|
|
54
|
+
return spectrumSize;
|
|
55
|
+
}
|
|
56
|
+
const isPercentValue = checkIsPercentValue(spectrumSize);
|
|
57
|
+
if (!isPercentValue) {
|
|
58
|
+
throw new Error();
|
|
59
|
+
}
|
|
60
|
+
const percentValue = parseInt(spectrumSize) / 100;
|
|
61
|
+
return backgroundImageSize * percentValue;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const getSpectrumSizeValueErrorMessage = (
|
|
65
|
+
fieldName: string, value: SpectrumSizeValue
|
|
66
|
+
) =>
|
|
67
|
+
`Invalid spectrum ${fieldName} value: '${value}'. Use number value or percent value in string, for example: '30%'.`
|
|
68
|
+
|
|
50
69
|
export const getSpectrumWidthAbsolute = (
|
|
51
70
|
config: Config, backgroundImageWidth: number
|
|
52
71
|
) => {
|
|
53
72
|
const spectrumWidth = getSpectrumWidth(config);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
73
|
+
try {
|
|
74
|
+
return getSpectrumSizeAbsolute(spectrumWidth, backgroundImageWidth);
|
|
75
|
+
} catch {
|
|
76
|
+
throw new Error(getSpectrumSizeValueErrorMessage('width', spectrumWidth));
|
|
57
77
|
}
|
|
58
|
-
return backgroundImageWidth * spectrumWidth;
|
|
59
78
|
};
|
|
60
79
|
|
|
61
80
|
const getSpectrumHeight = (config: Config) =>
|
|
@@ -66,11 +85,11 @@ export const getSpectrumHeightAbsolute = (
|
|
|
66
85
|
config: Config, backgroundImageHeight: number
|
|
67
86
|
) => {
|
|
68
87
|
const spectrumHeight = getSpectrumHeight(config);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
88
|
+
try {
|
|
89
|
+
return getSpectrumSizeAbsolute(spectrumHeight, backgroundImageHeight);
|
|
90
|
+
} catch {
|
|
91
|
+
throw new Error(getSpectrumSizeValueErrorMessage('height', spectrumHeight));
|
|
72
92
|
}
|
|
73
|
-
return backgroundImageHeight * spectrumHeight;
|
|
74
93
|
};
|
|
75
94
|
|
|
76
95
|
const getSpectrumX = (config: Config) =>
|
package/src/index.ts
CHANGED
|
@@ -36,8 +36,8 @@ export interface Config {
|
|
|
36
36
|
path: string;
|
|
37
37
|
fps?: number;
|
|
38
38
|
spectrum?: {
|
|
39
|
-
width?:
|
|
40
|
-
height?:
|
|
39
|
+
width?: SpectrumSizeValue;
|
|
40
|
+
height?: SpectrumSizeValue;
|
|
41
41
|
x?: number | PositionAliasName;
|
|
42
42
|
y?: number | PositionAliasName;
|
|
43
43
|
rotation?: RotationAliasName;
|
|
@@ -51,6 +51,8 @@ export interface Config {
|
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
export type SpectrumSizeValue = number | string;
|
|
55
|
+
|
|
54
56
|
export type PositionAliasName =
|
|
55
57
|
'left' |
|
|
56
58
|
'center' |
|
package/src/tests/config.test.ts
CHANGED
|
@@ -15,7 +15,8 @@ import {
|
|
|
15
15
|
getFfmpeg_cfr,
|
|
16
16
|
getFfmpeg_preset,
|
|
17
17
|
getFrame_processing_delay,
|
|
18
|
-
checkIsValidRotationAlias
|
|
18
|
+
checkIsValidRotationAlias,
|
|
19
|
+
checkIsPercentValue
|
|
19
20
|
} from '../config';
|
|
20
21
|
|
|
21
22
|
describe('config', function() {
|
|
@@ -55,13 +56,24 @@ describe('config', function() {
|
|
|
55
56
|
expect(result2).equal(15);
|
|
56
57
|
});
|
|
57
58
|
|
|
59
|
+
it('checkIsPercentValue', function() {
|
|
60
|
+
const result1 = checkIsPercentValue('69%');
|
|
61
|
+
expect(result1).equal(true);
|
|
62
|
+
|
|
63
|
+
const result2 = checkIsPercentValue('69');
|
|
64
|
+
expect(result2).equal(false);
|
|
65
|
+
|
|
66
|
+
const result3 = checkIsPercentValue('fake value');
|
|
67
|
+
expect(result3).equal(false);
|
|
68
|
+
});
|
|
69
|
+
|
|
58
70
|
it('getSpectrumWidthAbsolute', function() {
|
|
59
71
|
const backgroundImageWidth = 1366;
|
|
60
72
|
const result1 = getSpectrumWidthAbsolute({
|
|
61
73
|
outVideo: {}
|
|
62
74
|
} as Config, backgroundImageWidth);
|
|
63
75
|
expect(result1).equal(
|
|
64
|
-
backgroundImageWidth * defaults.spectrumWidth
|
|
76
|
+
backgroundImageWidth * (parseInt(defaults.spectrumWidth) / 100)
|
|
65
77
|
);
|
|
66
78
|
|
|
67
79
|
const result2 = getSpectrumWidthAbsolute({
|
|
@@ -70,9 +82,18 @@ describe('config', function() {
|
|
|
70
82
|
expect(result2).equal(420);
|
|
71
83
|
|
|
72
84
|
const result3 = getSpectrumWidthAbsolute({
|
|
73
|
-
outVideo: { spectrum: { width:
|
|
85
|
+
outVideo: { spectrum: { width: '69%' }}
|
|
74
86
|
} as Config, backgroundImageWidth);
|
|
75
87
|
expect(result3).equal(backgroundImageWidth * 0.69);
|
|
88
|
+
|
|
89
|
+
const result4 = getSpectrumWidthAbsolute.bind(
|
|
90
|
+
undefined,
|
|
91
|
+
{
|
|
92
|
+
outVideo: { spectrum: { width: '69' }}
|
|
93
|
+
} as Config,
|
|
94
|
+
backgroundImageWidth
|
|
95
|
+
);
|
|
96
|
+
expect(result4).to.throw('Invalid spectrum width value: \'69\'. Use number value or percent value in string, for example: \'30%\'.');
|
|
76
97
|
});
|
|
77
98
|
|
|
78
99
|
it('getSpectrumHeightAbsolute', function() {
|
|
@@ -81,7 +102,7 @@ describe('config', function() {
|
|
|
81
102
|
outVideo: {}
|
|
82
103
|
} as Config, backgroundImageHeight);
|
|
83
104
|
expect(result1).equal(
|
|
84
|
-
backgroundImageHeight * defaults.spectrumHeight
|
|
105
|
+
backgroundImageHeight * (parseInt(defaults.spectrumHeight) / 100)
|
|
85
106
|
);
|
|
86
107
|
|
|
87
108
|
const result2 = getSpectrumHeightAbsolute({
|
|
@@ -90,9 +111,18 @@ describe('config', function() {
|
|
|
90
111
|
expect(result2).equal(420);
|
|
91
112
|
|
|
92
113
|
const result3 = getSpectrumHeightAbsolute({
|
|
93
|
-
outVideo: { spectrum: { height:
|
|
114
|
+
outVideo: { spectrum: { height: '69%' }}
|
|
94
115
|
} as Config, backgroundImageHeight);
|
|
95
116
|
expect(result3).equal(backgroundImageHeight * 0.69);
|
|
117
|
+
|
|
118
|
+
const result4 = getSpectrumHeightAbsolute.bind(
|
|
119
|
+
undefined,
|
|
120
|
+
{
|
|
121
|
+
outVideo: { spectrum: { height: '69' }}
|
|
122
|
+
} as Config,
|
|
123
|
+
backgroundImageHeight
|
|
124
|
+
);
|
|
125
|
+
expect(result4).to.throw('Invalid spectrum height value: \'69\'. Use number value or percent value in string, for example: \'30%\'.');
|
|
96
126
|
});
|
|
97
127
|
|
|
98
128
|
it('getSpectrumXAbsolute', function() {
|
package/src/tests/image.test.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { expect } from 'chai';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { drawRect, Color, createVisualizerFrame, parseImage, convertToBmp } from '../image';
|
|
4
4
|
|
|
5
|
+
import frameSnapshotSpectrumDown from './snapshots/frameSnapshotSpectrumDown.json';
|
|
6
|
+
import frameSnapshotSpectrumUp from './snapshots/frameSnapshotSpectrumUp.json';
|
|
7
|
+
|
|
5
8
|
describe('image', function () {
|
|
6
9
|
it('drawRect', function () {
|
|
7
10
|
const imageWidth = 10;
|
|
@@ -32,7 +35,7 @@ describe('image', function () {
|
|
|
32
35
|
const backgroundImagePath = path.resolve('example/media/background.png');
|
|
33
36
|
const backgroundImageBmpBuffer = await convertToBmp(backgroundImagePath);
|
|
34
37
|
const backgroundImage = parseImage(backgroundImageBmpBuffer);
|
|
35
|
-
const
|
|
38
|
+
const frameSpectrumDown = createVisualizerFrame(
|
|
36
39
|
backgroundImage,
|
|
37
40
|
[0.5, 0, 1],
|
|
38
41
|
{ width: 15, height: 20 },
|
|
@@ -40,6 +43,18 @@ describe('image', function () {
|
|
|
40
43
|
'down',
|
|
41
44
|
{ red: 1, green: 1, blue: 1 }
|
|
42
45
|
);
|
|
43
|
-
|
|
46
|
+
const resultSpectrumDown = frameSpectrumDown.data.toJSON().data;
|
|
47
|
+
expect(resultSpectrumDown).deep.equal(frameSnapshotSpectrumDown);
|
|
48
|
+
|
|
49
|
+
const frameSpectrumUp = createVisualizerFrame(
|
|
50
|
+
backgroundImage,
|
|
51
|
+
[0.1, 1, 0],
|
|
52
|
+
{ width: 25, height: 23 },
|
|
53
|
+
{ x: 10, y: 5 },
|
|
54
|
+
'up',
|
|
55
|
+
{ red: 0, green: 123, blue: 69 }
|
|
56
|
+
);
|
|
57
|
+
const resultSpectrumUp = frameSpectrumUp.data.toJSON().data;
|
|
58
|
+
expect(resultSpectrumUp).deep.equal(frameSnapshotSpectrumUp);
|
|
44
59
|
});
|
|
45
60
|
});
|