nodejs-audio-visualizer 1.2.0 → 2.1.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 +7 -3
- package/dist/config.d.ts +18 -2
- package/dist/config.js +135 -13
- package/dist/config.js.map +1 -1
- package/dist/image.d.ts +27 -2
- package/dist/image.js +78 -22
- package/dist/image.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.js +17 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +190 -14
- package/src/image.ts +137 -21
- package/src/index.ts +44 -9
- package/src/tests/config.test.ts +239 -5
- package/src/tests/image.test.ts +88 -9
- package/src/tests/snapshots/frameSnapshotSpectrumDown.json +1 -0
- package/src/tests/snapshots/frameSnapshotSpectrumUp.json +1 -0
- package/src/tests/snapshots/frameSnapshotSpectrumUpOpacity50.json +1 -0
package/README.md
CHANGED
|
@@ -16,9 +16,13 @@ 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:
|
|
21
|
-
|
|
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
|
+
x: 'center', // Available values: 'left', 'center', right'. Also you can use absolute number values. For example, value 300 for 300 pixels x.
|
|
22
|
+
y: 'bottom', // Available values: 'top', 'middle', bottom'. Also you can use absolute number values. For example, value 300 for 300 pixels y.
|
|
23
|
+
rotation: 'up', // Available values: 'up', 'down'. Default value: 'down'.
|
|
24
|
+
color: '#cccc99', // Default value: inverted color of background image
|
|
25
|
+
opacity: '80%' // Default value: '100%'.
|
|
22
26
|
}
|
|
23
27
|
},
|
|
24
28
|
tweaks: { // Optional
|
package/dist/config.d.ts
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
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
|
+
spectrumX: string;
|
|
7
|
+
spectrumY: string;
|
|
8
|
+
spectrumRotation: string;
|
|
9
|
+
spectrumBusesCount: number;
|
|
10
|
+
spectrumBusMargin: number;
|
|
11
|
+
spectrumOpacity: string;
|
|
6
12
|
};
|
|
13
|
+
export declare const rotationAliasValues: readonly ["up", "down"];
|
|
14
|
+
export declare const checkIsPercentValue: (value: string) => boolean;
|
|
7
15
|
export declare const getAudioFilePath: (config: Config) => string;
|
|
8
16
|
export declare const getBackgroundImagePath: (config: Config) => string;
|
|
9
17
|
export declare const getOutVideoPath: (config: Config) => string;
|
|
10
18
|
export declare const getFPS: (config: Config) => number;
|
|
19
|
+
export declare const getSpectrumBusesCount: () => number;
|
|
20
|
+
export declare const getSpectrumBusMargin: () => number;
|
|
11
21
|
export declare const getSpectrumWidthAbsolute: (config: Config, backgroundImageWidth: number) => number;
|
|
12
22
|
export declare const getSpectrumHeightAbsolute: (config: Config, backgroundImageHeight: number) => number;
|
|
23
|
+
export declare const getSpectrumXAbsolute: (config: Config, spectrumWidth: number, backgroundImageWidth: number) => number;
|
|
24
|
+
export declare const getSpectrumYAbsolute: (config: Config, spectrumHeight: number, backgroundImageHeight: number) => number;
|
|
25
|
+
export declare const checkIsValidRotationAlias: (aliasName: string) => boolean;
|
|
26
|
+
export declare const getSpectrumRotation: (config: Config) => "up" | "down";
|
|
13
27
|
export declare const getSpectrumColor: (config: Config) => string | import("./image").Color | undefined;
|
|
28
|
+
export declare const getSpectrumOpacity: (config: Config) => string;
|
|
29
|
+
export declare const getSpectrumOpacityParsed: (config: Config) => number;
|
|
14
30
|
export declare const getFfmpeg_cfr: (config: Config) => string | undefined;
|
|
15
31
|
export declare const getFfmpeg_preset: (config: Config) => string | undefined;
|
|
16
32
|
export declare const getFrame_processing_delay: (config: Config) => number | undefined;
|
package/dist/config.js
CHANGED
|
@@ -6,11 +6,26 @@ 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
|
+
spectrumX: 'center',
|
|
12
|
+
spectrumY: 'top',
|
|
13
|
+
spectrumRotation: 'down',
|
|
14
|
+
spectrumBusesCount: 64,
|
|
15
|
+
spectrumBusMargin: 4,
|
|
16
|
+
spectrumOpacity: '100%',
|
|
11
17
|
};
|
|
12
|
-
var
|
|
13
|
-
|
|
18
|
+
var postitionAliases = [
|
|
19
|
+
{ name: 'left', value: 0 },
|
|
20
|
+
{ name: 'center', value: 0.5 },
|
|
21
|
+
{ name: 'right', value: 1 },
|
|
22
|
+
{ name: 'top', value: 0 },
|
|
23
|
+
{ name: 'middle', value: 0.5 },
|
|
24
|
+
{ name: 'bottom', value: 1 },
|
|
25
|
+
];
|
|
26
|
+
exports.rotationAliasValues = ['up', 'down'];
|
|
27
|
+
exports.checkIsPercentValue = function (value) {
|
|
28
|
+
return RegExp(/\d+%/).test(value);
|
|
14
29
|
};
|
|
15
30
|
exports.getAudioFilePath = function (config) {
|
|
16
31
|
return path_1.default.resolve(config.audio.path);
|
|
@@ -24,17 +39,34 @@ exports.getOutVideoPath = function (config) {
|
|
|
24
39
|
exports.getFPS = function (config) {
|
|
25
40
|
return config.outVideo.fps || exports.defaults.fps;
|
|
26
41
|
};
|
|
42
|
+
exports.getSpectrumBusesCount = function () { return exports.defaults.spectrumBusesCount; };
|
|
43
|
+
exports.getSpectrumBusMargin = function () { return exports.defaults.spectrumBusMargin; };
|
|
27
44
|
var getSpectrumWidth = function (config) {
|
|
28
45
|
return (config.outVideo.spectrum && config.outVideo.spectrum.width) ||
|
|
29
46
|
exports.defaults.spectrumWidth;
|
|
30
47
|
};
|
|
48
|
+
var getSpectrumSizeAbsolute = function (spectrumSize, backgroundImageSize, fieldName) {
|
|
49
|
+
if (typeof spectrumSize === 'number') {
|
|
50
|
+
return spectrumSize;
|
|
51
|
+
}
|
|
52
|
+
var isPercentValue = exports.checkIsPercentValue(spectrumSize);
|
|
53
|
+
if (!isPercentValue) {
|
|
54
|
+
throw new Error(getSpectrumSizeValueErrorMessage(fieldName, spectrumSize));
|
|
55
|
+
}
|
|
56
|
+
var percentValue = parseInt(spectrumSize) / 100;
|
|
57
|
+
return backgroundImageSize * percentValue;
|
|
58
|
+
};
|
|
59
|
+
var getSpectrumSizeValueErrorMessage = function (fieldName, value) {
|
|
60
|
+
return "Invalid spectrum " + fieldName + " value: '" + value + "'. Use number value or percent value in string, for example: '30%'.";
|
|
61
|
+
};
|
|
31
62
|
exports.getSpectrumWidthAbsolute = function (config, backgroundImageWidth) {
|
|
32
63
|
var spectrumWidth = getSpectrumWidth(config);
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
64
|
+
var spectrumWidthAbsolute = getSpectrumSizeAbsolute(spectrumWidth, backgroundImageWidth, 'width');
|
|
65
|
+
var spectrumWidthWithoutMargin = Math.trunc(spectrumWidthAbsolute / exports.defaults.spectrumBusesCount) - exports.defaults.spectrumBusMargin / 2;
|
|
66
|
+
if (spectrumWidthWithoutMargin <= 0) {
|
|
67
|
+
throw new Error("Spectrum width '" + spectrumWidth + "' is too small.");
|
|
36
68
|
}
|
|
37
|
-
return
|
|
69
|
+
return spectrumWidthAbsolute;
|
|
38
70
|
};
|
|
39
71
|
var getSpectrumHeight = function (config) {
|
|
40
72
|
return (config.outVideo.spectrum && config.outVideo.spectrum.height) ||
|
|
@@ -42,14 +74,104 @@ var getSpectrumHeight = function (config) {
|
|
|
42
74
|
};
|
|
43
75
|
exports.getSpectrumHeightAbsolute = function (config, backgroundImageHeight) {
|
|
44
76
|
var spectrumHeight = getSpectrumHeight(config);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
77
|
+
return getSpectrumSizeAbsolute(spectrumHeight, backgroundImageHeight, 'height');
|
|
78
|
+
};
|
|
79
|
+
var getSpectrumX = function (config) {
|
|
80
|
+
return parseNumberIfPossible((config.outVideo.spectrum && config.outVideo.spectrum.x) ||
|
|
81
|
+
exports.defaults.spectrumX);
|
|
82
|
+
};
|
|
83
|
+
var getSpectrumY = function (config) {
|
|
84
|
+
return parseNumberIfPossible((config.outVideo.spectrum && config.outVideo.spectrum.y) ||
|
|
85
|
+
exports.defaults.spectrumY);
|
|
86
|
+
};
|
|
87
|
+
var parseNumberIfPossible = function (value) {
|
|
88
|
+
var parsed = Number(value);
|
|
89
|
+
if (isNaN(parsed)) {
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
return parsed;
|
|
93
|
+
};
|
|
94
|
+
var parsePositionAlias = function (aliasName) {
|
|
95
|
+
var nameNormalized = aliasName.trim().toLowerCase();
|
|
96
|
+
var alias = postitionAliases.find(function (als) { return als.name === nameNormalized; });
|
|
97
|
+
if (!alias) {
|
|
98
|
+
throw new Error();
|
|
99
|
+
}
|
|
100
|
+
return alias;
|
|
101
|
+
};
|
|
102
|
+
var getValidPositionAliasValues = function () {
|
|
103
|
+
return postitionAliases.map(function (aliasEl) { return aliasEl.name; }).join(', ');
|
|
104
|
+
};
|
|
105
|
+
var getSpectrumAbsolutePosition = function (relativePosition, spectrumSize, backgroundImageSize) {
|
|
106
|
+
switch (relativePosition) {
|
|
107
|
+
case 0:
|
|
108
|
+
return 0;
|
|
109
|
+
case 0.5:
|
|
110
|
+
return relativePosition * backgroundImageSize - spectrumSize / 2;
|
|
111
|
+
case 1:
|
|
112
|
+
return relativePosition * backgroundImageSize - spectrumSize;
|
|
113
|
+
default:
|
|
114
|
+
throw new Error();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
exports.getSpectrumXAbsolute = function (config, spectrumWidth, backgroundImageWidth) {
|
|
118
|
+
var spectrumX = getSpectrumX(config);
|
|
119
|
+
if (typeof spectrumX !== 'string') {
|
|
120
|
+
return spectrumX;
|
|
48
121
|
}
|
|
49
|
-
|
|
122
|
+
try {
|
|
123
|
+
var spectrumXParsed = parsePositionAlias(spectrumX);
|
|
124
|
+
return getSpectrumAbsolutePosition(spectrumXParsed.value, spectrumWidth, backgroundImageWidth);
|
|
125
|
+
}
|
|
126
|
+
catch (_a) {
|
|
127
|
+
throw new Error("Invalid spectrum x value: " + spectrumX + ". Valid values: " + getValidPositionAliasValues() + ".");
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
exports.getSpectrumYAbsolute = function (config, spectrumHeight, backgroundImageHeight) {
|
|
131
|
+
var spectrumY = getSpectrumY(config);
|
|
132
|
+
if (typeof spectrumY !== 'string') {
|
|
133
|
+
return spectrumY;
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
var spectrumXParsed = parsePositionAlias(spectrumY);
|
|
137
|
+
return getSpectrumAbsolutePosition(spectrumXParsed.value, spectrumHeight, backgroundImageHeight);
|
|
138
|
+
}
|
|
139
|
+
catch (_a) {
|
|
140
|
+
throw new Error("Invalid spectrum y value: " + spectrumY + ". Valid values: " + getValidPositionAliasValues() + ".");
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
var getValidRotationAliasValues = function () {
|
|
144
|
+
return exports.rotationAliasValues.join(', ');
|
|
145
|
+
};
|
|
146
|
+
exports.checkIsValidRotationAlias = function (aliasName) {
|
|
147
|
+
return !!exports.rotationAliasValues.find(function (al) { return al === aliasName; });
|
|
148
|
+
};
|
|
149
|
+
exports.getSpectrumRotation = function (config) {
|
|
150
|
+
var rotationValue = (config.outVideo.spectrum && config.outVideo.spectrum.rotation) ||
|
|
151
|
+
exports.defaults.spectrumRotation;
|
|
152
|
+
if (!exports.checkIsValidRotationAlias(rotationValue)) {
|
|
153
|
+
throw new Error("Invalid spectrum rotation value: " + rotationValue + ". Valid values: " + getValidRotationAliasValues + ".");
|
|
154
|
+
}
|
|
155
|
+
return rotationValue;
|
|
50
156
|
};
|
|
51
157
|
exports.getSpectrumColor = function (config) {
|
|
52
|
-
return
|
|
158
|
+
return config.outVideo.spectrum && config.outVideo.spectrum.color;
|
|
159
|
+
};
|
|
160
|
+
exports.getSpectrumOpacity = function (config) {
|
|
161
|
+
return (config.outVideo.spectrum && config.outVideo.spectrum.opacity) ||
|
|
162
|
+
exports.defaults.spectrumOpacity;
|
|
163
|
+
};
|
|
164
|
+
exports.getSpectrumOpacityParsed = function (config) {
|
|
165
|
+
var spectrumOpacity = exports.getSpectrumOpacity(config);
|
|
166
|
+
if (!exports.checkIsPercentValue(spectrumOpacity)) {
|
|
167
|
+
throw new Error("Invalid spectrum opacity value: '" + spectrumOpacity + "'. Use string percent value, for example '80%'.");
|
|
168
|
+
}
|
|
169
|
+
var percentValue = parseInt(spectrumOpacity);
|
|
170
|
+
if ((percentValue < 0) ||
|
|
171
|
+
(percentValue > 100)) {
|
|
172
|
+
throw new Error("Invalid spectrum opacity value: '" + spectrumOpacity + "'. Percent values must be in range from '0%' to '100%'.");
|
|
173
|
+
}
|
|
174
|
+
return percentValue / 100;
|
|
53
175
|
};
|
|
54
176
|
exports.getFfmpeg_cfr = function (config) {
|
|
55
177
|
return config.tweaks && config.tweaks.ffmpeg_cfr;
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;AAAA,8CAAwB;AAGX,QAAA,QAAQ,GAAG;IACtB,GAAG,EAAE,EAAE;IACP,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;AAAA,8CAAwB;AAGX,QAAA,QAAQ,GAAG;IACtB,GAAG,EAAE,EAAE;IACP,a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AAM,CAAC,MAAM,CAAC,sBAAsB;AAArD,CAAqD,CAAC"}
|
package/dist/image.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { RotationAliasName } from './index';
|
|
2
3
|
import { BmpDecoder } from 'bmp-js';
|
|
3
4
|
export interface Color {
|
|
4
5
|
red: number;
|
|
@@ -13,8 +14,32 @@ interface Size {
|
|
|
13
14
|
width: number;
|
|
14
15
|
height: number;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
interface MixColorProps {
|
|
18
|
+
color: Color;
|
|
19
|
+
colorOpacity: number;
|
|
20
|
+
backgroundColor: Color;
|
|
21
|
+
}
|
|
22
|
+
export declare const mixValues: (value1: number, value1Opacity: number, value2: number) => number;
|
|
23
|
+
export declare const mixColors: ({ color, colorOpacity, backgroundColor, }: MixColorProps) => Color;
|
|
24
|
+
interface DrawRectPorps {
|
|
25
|
+
imageDstBuffer: BmpDecoder;
|
|
26
|
+
position: Position;
|
|
27
|
+
size: Size;
|
|
28
|
+
color: Color;
|
|
29
|
+
opacity: number;
|
|
30
|
+
}
|
|
31
|
+
export declare const drawRect: ({ imageDstBuffer, position, size, color, opacity, }: DrawRectPorps) => void;
|
|
32
|
+
interface CreateVisualizerFrameProps {
|
|
33
|
+
backgroundImageBuffer: BmpDecoder;
|
|
34
|
+
spectrum: number[];
|
|
35
|
+
size: Size;
|
|
36
|
+
position: Position;
|
|
37
|
+
rotation: RotationAliasName;
|
|
38
|
+
margin: number;
|
|
39
|
+
color: Color | string;
|
|
40
|
+
opacity: number;
|
|
41
|
+
}
|
|
42
|
+
export declare const createVisualizerFrame: ({ backgroundImageBuffer, spectrum, size, position, rotation, margin, color, opacity, }: CreateVisualizerFrameProps) => BmpDecoder;
|
|
18
43
|
export declare const convertToBmp: (filePath: string) => Promise<Buffer>;
|
|
19
44
|
export declare const parseImage: (buffer: Buffer) => BmpDecoder;
|
|
20
45
|
export declare const createImageBuffer: (image: BmpDecoder) => Buffer;
|
package/dist/image.js
CHANGED
|
@@ -41,50 +41,106 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
var bmp_js_1 = require("bmp-js");
|
|
43
43
|
var jimp_1 = __importDefault(require("jimp"));
|
|
44
|
-
exports.
|
|
44
|
+
exports.mixValues = function (value1, value1Opacity, value2) {
|
|
45
|
+
return Math.round(value2 * (1 - value1Opacity) + value1 * value1Opacity);
|
|
46
|
+
};
|
|
47
|
+
exports.mixColors = function (_a) {
|
|
48
|
+
var color = _a.color, colorOpacity = _a.colorOpacity, backgroundColor = _a.backgroundColor;
|
|
49
|
+
return {
|
|
50
|
+
red: exports.mixValues(color.red, colorOpacity, backgroundColor.red),
|
|
51
|
+
green: exports.mixValues(color.green, colorOpacity, backgroundColor.green),
|
|
52
|
+
blue: exports.mixValues(color.blue, colorOpacity, backgroundColor.blue),
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
exports.drawRect = function (_a) {
|
|
56
|
+
var imageDstBuffer = _a.imageDstBuffer, position = _a.position, size = _a.size, color = _a.color, opacity = _a.opacity;
|
|
45
57
|
for (var currY = position.y; currY < position.y + size.height; currY++) {
|
|
46
58
|
for (var currX = position.x; currX < position.x + size.width; currX++) {
|
|
47
59
|
var idx = (imageDstBuffer.width * currY + currX) << 2;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
60
|
+
if (opacity === 1) {
|
|
61
|
+
imageDstBuffer.data[idx + 1] = color.blue;
|
|
62
|
+
imageDstBuffer.data[idx + 2] = color.green;
|
|
63
|
+
imageDstBuffer.data[idx + 3] = color.red;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
var backgroundPixelColor = {
|
|
67
|
+
red: imageDstBuffer.data[idx + 3],
|
|
68
|
+
green: imageDstBuffer.data[idx + 2],
|
|
69
|
+
blue: imageDstBuffer.data[idx + 1],
|
|
70
|
+
};
|
|
71
|
+
var resultColor = exports.mixColors({
|
|
72
|
+
color: color,
|
|
73
|
+
colorOpacity: opacity,
|
|
74
|
+
backgroundColor: backgroundPixelColor,
|
|
75
|
+
});
|
|
76
|
+
imageDstBuffer.data[idx + 1] = resultColor.blue;
|
|
77
|
+
imageDstBuffer.data[idx + 2] = resultColor.green;
|
|
78
|
+
imageDstBuffer.data[idx + 3] = resultColor.red;
|
|
51
79
|
}
|
|
52
80
|
}
|
|
53
81
|
};
|
|
54
|
-
var drawSpectrum = function (
|
|
55
|
-
var
|
|
82
|
+
var drawSpectrum = function (_a) {
|
|
83
|
+
var imageDstBuffer = _a.imageDstBuffer, spectrum = _a.spectrum, size = _a.size, position = _a.position, rotation = _a.rotation, margin = _a.margin, color = _a.color, opacity = _a.opacity;
|
|
56
84
|
var busWidth = Math.trunc(size.width / spectrum.length);
|
|
57
|
-
var
|
|
85
|
+
var left = Math.trunc(position.x);
|
|
86
|
+
var top = Math.trunc(position.y);
|
|
87
|
+
var height = Math.trunc(size.height);
|
|
58
88
|
for (var spectrumX = 0; spectrumX < spectrum.length; spectrumX++) {
|
|
59
89
|
var spectrumValue = spectrum[spectrumX];
|
|
60
90
|
if ((spectrumValue > 1) || (spectrumValue < 0)) {
|
|
61
91
|
throw new Error('Spectrum values must be in range from 0 to 1');
|
|
62
92
|
}
|
|
63
|
-
var rectX =
|
|
64
|
-
var rectHeight =
|
|
65
|
-
|
|
93
|
+
var rectX = left + busWidth * spectrumX;
|
|
94
|
+
var rectHeight = Math.trunc(height * spectrumValue);
|
|
95
|
+
var rectY = (rotation === 'up') ? top + height - rectHeight : top;
|
|
96
|
+
exports.drawRect({
|
|
97
|
+
imageDstBuffer: imageDstBuffer,
|
|
98
|
+
position: { x: rectX + margin, y: rectY },
|
|
99
|
+
size: { width: busWidth - margin / 2, height: rectHeight },
|
|
100
|
+
color: color,
|
|
101
|
+
opacity: opacity,
|
|
102
|
+
});
|
|
66
103
|
}
|
|
67
104
|
};
|
|
68
|
-
exports.createVisualizerFrame = function (
|
|
69
|
-
var
|
|
70
|
-
|
|
105
|
+
exports.createVisualizerFrame = function (_a) {
|
|
106
|
+
var backgroundImageBuffer = _a.backgroundImageBuffer, spectrum = _a.spectrum, size = _a.size, position = _a.position, rotation = _a.rotation, margin = _a.margin, color = _a.color, opacity = _a.opacity;
|
|
107
|
+
var imageDstBuffer = Object.assign({}, backgroundImageBuffer);
|
|
108
|
+
imageDstBuffer.data = Buffer.from(imageDstBuffer.data);
|
|
71
109
|
var rgbSpectrumColor = (typeof color === 'string') ? hexToRgb(color) : color;
|
|
72
|
-
drawSpectrum(
|
|
73
|
-
|
|
110
|
+
drawSpectrum({
|
|
111
|
+
imageDstBuffer: imageDstBuffer,
|
|
112
|
+
spectrum: spectrum,
|
|
113
|
+
size: size,
|
|
114
|
+
position: position,
|
|
115
|
+
rotation: rotation,
|
|
116
|
+
margin: margin,
|
|
117
|
+
color: rgbSpectrumColor,
|
|
118
|
+
opacity: opacity,
|
|
119
|
+
});
|
|
120
|
+
return imageDstBuffer;
|
|
74
121
|
};
|
|
75
122
|
exports.convertToBmp = function (filePath) { return __awaiter(void 0, void 0, void 0, function () {
|
|
76
123
|
return __generator(this, function (_a) {
|
|
77
|
-
return [2 /*return*/, new Promise(function (resolve) { return __awaiter(void 0, void 0, void 0, function () {
|
|
78
|
-
var image;
|
|
79
|
-
return __generator(this, function (
|
|
80
|
-
switch (
|
|
81
|
-
case 0:
|
|
124
|
+
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
125
|
+
var image, _a;
|
|
126
|
+
return __generator(this, function (_b) {
|
|
127
|
+
switch (_b.label) {
|
|
128
|
+
case 0:
|
|
129
|
+
_b.trys.push([0, 2, , 3]);
|
|
130
|
+
return [4 /*yield*/, jimp_1.default.read(filePath)];
|
|
82
131
|
case 1:
|
|
83
|
-
image =
|
|
132
|
+
image = _b.sent();
|
|
84
133
|
image.getBuffer("image/bmp", function (err, value) {
|
|
134
|
+
if (err) {
|
|
135
|
+
reject(err);
|
|
136
|
+
}
|
|
85
137
|
resolve(value);
|
|
86
138
|
});
|
|
87
|
-
return [
|
|
139
|
+
return [3 /*break*/, 3];
|
|
140
|
+
case 2:
|
|
141
|
+
_a = _b.sent();
|
|
142
|
+
throw new Error("Cannot procces image file from path: " + filePath);
|
|
143
|
+
case 3: return [2 /*return*/];
|
|
88
144
|
}
|
|
89
145
|
});
|
|
90
146
|
}); })];
|
package/dist/image.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.js","sourceRoot":"","sources":["../src/image.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../src/image.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iCAAoD;AACpD,8CAAwB;AAwBX,QAAA,SAAS,GAAE,UAAC,MAAc,EAAE,aAAqB,EAAE,MAAc;IAC5E,OAAA,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,aAAa,CAAC,GAAG,MAAM,GAAG,aAAa,CAAC;AAAjE,CAAiE,CAAC;AAEvD,QAAA,SAAS,GAAG,UAAC,EAIV;QAHd,gBAAK,EACL,8BAAY,EACZ,oCAAe;IAEf,OAAO;QACL,GAAG,EAAE,iBAAS,CAAC,KAAK,CAAC,GAAG,EAAE,YAAY,EAAE,eAAe,CAAC,GAAG,CAAC;QAC5D,KAAK,EAAE,iBAAS,CAAC,KAAK,CAAC,KAAK,EAAE,YAAY,EAAE,eAAe,CAAC,KAAK,CAAC;QAClE,IAAI,EAAE,iBAAS,CAAC,KAAK,CAAC,IAAI,EAAE,YAAY,EAAE,eAAe,CAAC,IAAI,CAAC;KAChE,CAAC;AACJ,CAAC,CAAC;AAUW,QAAA,QAAQ,GAAG,UAAC,EAMT;QALd,kCA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AQ,GAAG,WAAW,CAAC;QACjC,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,WAAW,CAAC;KAChC,CAAC;AACJ,CAAC,CAAC;AAEW,QAAA,WAAW,GAAG,UAAC,KAAY;IACtC,OAAA,CAAC,EAAE,GAAG,EAAE,GAAG,GAAG,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;AAA5E,CAA4E,CAAC;AAE/E,IAAM,QAAQ,GAAG,UAAC,GAAW;IAC3B,IAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC9C,IAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAChD,IAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE/C,OAAO,EAAE,GAAG,KAAA,EAAE,KAAK,OAAA,EAAE,IAAI,MAAA,EAAE,CAAC;AAC9B,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { rotationAliasValues } from './config';
|
|
2
3
|
import { Color } from './image';
|
|
3
4
|
export declare const PCM_FORMAT: {
|
|
4
5
|
bit: number;
|
|
@@ -16,9 +17,13 @@ export interface Config {
|
|
|
16
17
|
path: string;
|
|
17
18
|
fps?: number;
|
|
18
19
|
spectrum?: {
|
|
19
|
-
width?:
|
|
20
|
-
height?:
|
|
20
|
+
width?: SpectrumSizeValue;
|
|
21
|
+
height?: SpectrumSizeValue;
|
|
22
|
+
x?: number | PositionAliasName;
|
|
23
|
+
y?: number | PositionAliasName;
|
|
24
|
+
rotation?: RotationAliasName;
|
|
21
25
|
color?: Color | string;
|
|
26
|
+
opacity?: string;
|
|
22
27
|
};
|
|
23
28
|
};
|
|
24
29
|
tweaks?: {
|
|
@@ -27,4 +32,7 @@ export interface Config {
|
|
|
27
32
|
frame_processing_delay?: number;
|
|
28
33
|
};
|
|
29
34
|
}
|
|
35
|
+
export declare type SpectrumSizeValue = number | string;
|
|
36
|
+
export declare type PositionAliasName = 'left' | 'center' | 'right' | 'top' | 'middle' | 'bottom';
|
|
37
|
+
export declare type RotationAliasName = typeof rotationAliasValues[number];
|
|
30
38
|
export declare const renderAudioVisualizer: (config: Config, onProgress?: ((progress: number) => any) | undefined, shouldStop?: (() => boolean) | undefined) => Promise<number>;
|
package/dist/index.js
CHANGED
|
@@ -62,7 +62,7 @@ var sleep = function (timeout) {
|
|
|
62
62
|
};
|
|
63
63
|
exports.renderAudioVisualizer = function (config, onProgress, shouldStop) {
|
|
64
64
|
return new Promise(function (resolve) { return __awaiter(void 0, void 0, void 0, function () {
|
|
65
|
-
var audioFilePath, backgroundImagePath, outVideoPath, backgroundImageBmpBuffer, backgroundImage, audioReader, audioBuffer, sampleRate, FPS, spectrumWidth, spectrumHeight, spectrumColor, ffmpeg_cfr, ffmpeg_preset, frame_processing_delay,
|
|
65
|
+
var audioFilePath, backgroundImagePath, outVideoPath, backgroundImageBmpBuffer, backgroundImage, audioReader, audioBuffer, sampleRate, spectrumBusesCount, spectrumBusMargin, FPS, spectrumWidth, spectrumHeight, spectrumX, spectrumY, spectrumRotation, spectrumColor, spectrumOpacity, ffmpeg_cfr, ffmpeg_preset, frame_processing_delay, audioDuration, framesCount, audioDataStep, ffmpegVideoWriter, processSpectrum, _loop_1, i, state_1;
|
|
66
66
|
return __generator(this, function (_a) {
|
|
67
67
|
switch (_a.label) {
|
|
68
68
|
case 0:
|
|
@@ -81,15 +81,20 @@ exports.renderAudioVisualizer = function (config, onProgress, shouldStop) {
|
|
|
81
81
|
if (!sampleRate) {
|
|
82
82
|
throw new Error('ffmpeg didn\'t show audio sample rate');
|
|
83
83
|
}
|
|
84
|
+
spectrumBusesCount = config_1.getSpectrumBusesCount();
|
|
85
|
+
spectrumBusMargin = config_1.getSpectrumBusMargin();
|
|
84
86
|
FPS = config_1.getFPS(config);
|
|
85
87
|
spectrumWidth = config_1.getSpectrumWidthAbsolute(config, backgroundImage.width);
|
|
86
88
|
spectrumHeight = config_1.getSpectrumHeightAbsolute(config, backgroundImage.height);
|
|
89
|
+
spectrumX = config_1.getSpectrumXAbsolute(config, spectrumWidth, backgroundImage.width);
|
|
90
|
+
spectrumY = config_1.getSpectrumYAbsolute(config, spectrumHeight, backgroundImage.height);
|
|
91
|
+
spectrumRotation = config_1.getSpectrumRotation(config);
|
|
87
92
|
spectrumColor = config_1.getSpectrumColor(config) ||
|
|
88
93
|
image_1.invertColor(image_1.getImageColor(backgroundImage));
|
|
94
|
+
spectrumOpacity = config_1.getSpectrumOpacityParsed(config);
|
|
89
95
|
ffmpeg_cfr = config_1.getFfmpeg_cfr(config);
|
|
90
96
|
ffmpeg_preset = config_1.getFfmpeg_preset(config);
|
|
91
97
|
frame_processing_delay = config_1.getFrame_processing_delay(config);
|
|
92
|
-
spectrumBusesCount = 64;
|
|
93
98
|
audioDuration = audioBuffer.length / sampleRate;
|
|
94
99
|
framesCount = Math.trunc(audioDuration * FPS);
|
|
95
100
|
audioDataStep = Math.trunc(audioBuffer.length / framesCount);
|
|
@@ -105,7 +110,16 @@ exports.renderAudioVisualizer = function (config, onProgress, shouldStop) {
|
|
|
105
110
|
return exports.PCM_FORMAT.parseFunction(audioBuffer, i * audioDataStep, i * audioDataStep + audioDataStep);
|
|
106
111
|
};
|
|
107
112
|
spectrum = processSpectrum(i, audioDataParser);
|
|
108
|
-
frameImage = image_1.createVisualizerFrame(
|
|
113
|
+
frameImage = image_1.createVisualizerFrame({
|
|
114
|
+
backgroundImageBuffer: backgroundImage,
|
|
115
|
+
spectrum: spectrum,
|
|
116
|
+
size: { width: spectrumWidth, height: spectrumHeight },
|
|
117
|
+
position: { x: spectrumX, y: spectrumY },
|
|
118
|
+
rotation: spectrumRotation,
|
|
119
|
+
margin: spectrumBusMargin,
|
|
120
|
+
color: spectrumColor,
|
|
121
|
+
opacity: spectrumOpacity,
|
|
122
|
+
});
|
|
109
123
|
frameImageBuffer = image_1.createImageBuffer(frameImage);
|
|
110
124
|
isFrameProcessed = ffmpegVideoWriter.stdin.write(frameImageBuffer);
|
|
111
125
|
if (!!isFrameProcessed) return [3 /*break*/, 2];
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAkBkB;AAClB,iCAAqF;AACrF,iCAAgI;AAChI,iCAA4F;AAE/E,QAAA,UAAU,GAAG;IACxB,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,GAAG;IACT,aAAa,EAAE,qBAAa;CAC7B,CAAC;AACF,IAAM,aAAa,GAAG,KAAG,kBAAU,CAAC,IAAI,GAAG,kBAAU,CAAC,GAAK,CAAC;AAyC5D,IAAM,KAAK,GAAG,UAAC,OAAe;IAC5B,OAAA,IAAI,OAAO,CAAC,UAAA,OAAO,IAAI,OAAA,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,EAA5B,CAA4B,CAAC;AAApD,CAAoD,CAAC;AAE1C,QAAA,qBAAqB,GAAG,UAAC,MAAc,EAAE,UAAsC,EAAE,UAA0B;IACtH,OAAA,IAAI,OAAO,CAAS,UAAO,OAAO;;;;;oBAC1B,aAAa,GAAG,yBAAgB,CAAC,MAAM,CAAC,CAAC;oBACzC,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