nodejs-audio-visualizer 2.0.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 +2 -1
- package/dist/config.d.ts +7 -0
- package/dist/config.js +31 -15
- package/dist/config.js.map +1 -1
- package/dist/image.d.ts +27 -2
- package/dist/image.js +72 -19
- package/dist/image.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +39 -13
- package/src/image.ts +130 -25
- package/src/index.ts +16 -8
- package/src/tests/config.test.ts +60 -0
- package/src/tests/image.test.ts +80 -18
- package/src/tests/snapshots/frameSnapshotSpectrumUpOpacity50.json +1 -0
package/README.md
CHANGED
|
@@ -21,7 +21,8 @@ const config = {
|
|
|
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'.
|
|
24
|
-
color: '#cccc99' // Default value: inverted color of background image
|
|
24
|
+
color: '#cccc99', // Default value: inverted color of background image
|
|
25
|
+
opacity: '80%' // Default value: '100%'.
|
|
25
26
|
}
|
|
26
27
|
},
|
|
27
28
|
tweaks: { // Optional
|
package/dist/config.d.ts
CHANGED
|
@@ -6,6 +6,9 @@ export declare const defaults: {
|
|
|
6
6
|
spectrumX: string;
|
|
7
7
|
spectrumY: string;
|
|
8
8
|
spectrumRotation: string;
|
|
9
|
+
spectrumBusesCount: number;
|
|
10
|
+
spectrumBusMargin: number;
|
|
11
|
+
spectrumOpacity: string;
|
|
9
12
|
};
|
|
10
13
|
export declare const rotationAliasValues: readonly ["up", "down"];
|
|
11
14
|
export declare const checkIsPercentValue: (value: string) => boolean;
|
|
@@ -13,6 +16,8 @@ export declare const getAudioFilePath: (config: Config) => string;
|
|
|
13
16
|
export declare const getBackgroundImagePath: (config: Config) => string;
|
|
14
17
|
export declare const getOutVideoPath: (config: Config) => string;
|
|
15
18
|
export declare const getFPS: (config: Config) => number;
|
|
19
|
+
export declare const getSpectrumBusesCount: () => number;
|
|
20
|
+
export declare const getSpectrumBusMargin: () => number;
|
|
16
21
|
export declare const getSpectrumWidthAbsolute: (config: Config, backgroundImageWidth: number) => number;
|
|
17
22
|
export declare const getSpectrumHeightAbsolute: (config: Config, backgroundImageHeight: number) => number;
|
|
18
23
|
export declare const getSpectrumXAbsolute: (config: Config, spectrumWidth: number, backgroundImageWidth: number) => number;
|
|
@@ -20,6 +25,8 @@ export declare const getSpectrumYAbsolute: (config: Config, spectrumHeight: numb
|
|
|
20
25
|
export declare const checkIsValidRotationAlias: (aliasName: string) => boolean;
|
|
21
26
|
export declare const getSpectrumRotation: (config: Config) => "up" | "down";
|
|
22
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;
|
|
23
30
|
export declare const getFfmpeg_cfr: (config: Config) => string | undefined;
|
|
24
31
|
export declare const getFfmpeg_preset: (config: Config) => string | undefined;
|
|
25
32
|
export declare const getFrame_processing_delay: (config: Config) => number | undefined;
|
package/dist/config.js
CHANGED
|
@@ -10,7 +10,10 @@ exports.defaults = {
|
|
|
10
10
|
spectrumHeight: '10%',
|
|
11
11
|
spectrumX: 'center',
|
|
12
12
|
spectrumY: 'top',
|
|
13
|
-
spectrumRotation: 'down'
|
|
13
|
+
spectrumRotation: 'down',
|
|
14
|
+
spectrumBusesCount: 64,
|
|
15
|
+
spectrumBusMargin: 4,
|
|
16
|
+
spectrumOpacity: '100%',
|
|
14
17
|
};
|
|
15
18
|
var postitionAliases = [
|
|
16
19
|
{ name: 'left', value: 0 },
|
|
@@ -36,17 +39,19 @@ exports.getOutVideoPath = function (config) {
|
|
|
36
39
|
exports.getFPS = function (config) {
|
|
37
40
|
return config.outVideo.fps || exports.defaults.fps;
|
|
38
41
|
};
|
|
42
|
+
exports.getSpectrumBusesCount = function () { return exports.defaults.spectrumBusesCount; };
|
|
43
|
+
exports.getSpectrumBusMargin = function () { return exports.defaults.spectrumBusMargin; };
|
|
39
44
|
var getSpectrumWidth = function (config) {
|
|
40
45
|
return (config.outVideo.spectrum && config.outVideo.spectrum.width) ||
|
|
41
46
|
exports.defaults.spectrumWidth;
|
|
42
47
|
};
|
|
43
|
-
var getSpectrumSizeAbsolute = function (spectrumSize, backgroundImageSize) {
|
|
48
|
+
var getSpectrumSizeAbsolute = function (spectrumSize, backgroundImageSize, fieldName) {
|
|
44
49
|
if (typeof spectrumSize === 'number') {
|
|
45
50
|
return spectrumSize;
|
|
46
51
|
}
|
|
47
52
|
var isPercentValue = exports.checkIsPercentValue(spectrumSize);
|
|
48
53
|
if (!isPercentValue) {
|
|
49
|
-
throw new Error();
|
|
54
|
+
throw new Error(getSpectrumSizeValueErrorMessage(fieldName, spectrumSize));
|
|
50
55
|
}
|
|
51
56
|
var percentValue = parseInt(spectrumSize) / 100;
|
|
52
57
|
return backgroundImageSize * percentValue;
|
|
@@ -56,12 +61,12 @@ var getSpectrumSizeValueErrorMessage = function (fieldName, value) {
|
|
|
56
61
|
};
|
|
57
62
|
exports.getSpectrumWidthAbsolute = function (config, backgroundImageWidth) {
|
|
58
63
|
var spectrumWidth = getSpectrumWidth(config);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
throw new Error(getSpectrumSizeValueErrorMessage('width', spectrumWidth));
|
|
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.");
|
|
64
68
|
}
|
|
69
|
+
return spectrumWidthAbsolute;
|
|
65
70
|
};
|
|
66
71
|
var getSpectrumHeight = function (config) {
|
|
67
72
|
return (config.outVideo.spectrum && config.outVideo.spectrum.height) ||
|
|
@@ -69,12 +74,7 @@ var getSpectrumHeight = function (config) {
|
|
|
69
74
|
};
|
|
70
75
|
exports.getSpectrumHeightAbsolute = function (config, backgroundImageHeight) {
|
|
71
76
|
var spectrumHeight = getSpectrumHeight(config);
|
|
72
|
-
|
|
73
|
-
return getSpectrumSizeAbsolute(spectrumHeight, backgroundImageHeight);
|
|
74
|
-
}
|
|
75
|
-
catch (_a) {
|
|
76
|
-
throw new Error(getSpectrumSizeValueErrorMessage('height', spectrumHeight));
|
|
77
|
-
}
|
|
77
|
+
return getSpectrumSizeAbsolute(spectrumHeight, backgroundImageHeight, 'height');
|
|
78
78
|
};
|
|
79
79
|
var getSpectrumX = function (config) {
|
|
80
80
|
return parseNumberIfPossible((config.outVideo.spectrum && config.outVideo.spectrum.x) ||
|
|
@@ -155,7 +155,23 @@ exports.getSpectrumRotation = function (config) {
|
|
|
155
155
|
return rotationValue;
|
|
156
156
|
};
|
|
157
157
|
exports.getSpectrumColor = function (config) {
|
|
158
|
-
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;
|
|
159
175
|
};
|
|
160
176
|
exports.getFfmpeg_cfr = function (config) {
|
|
161
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,KAAK;IACpB,cAAc,EAAE,KAAK;IACrB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,KAAK;IAChB,gBAAgB,EAAE,MAAM;
|
|
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,KAAK;IACpB,cAAc,EAAE,KAAK;IACrB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,KAAK;IAChB,gBAAgB,EAAE,MAAM;IACxB,kBAAkB,EAAE,EAAE;IACtB,iBAAiB,EAAE,CAAC;IACpB,eAAe,EAAE,MAAM;CACxB,CAAC;AASF,IAAM,gBAAgB,GAAoB;IACxC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE;IAC1B,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE;IAC9B,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE;IAC3B,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,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AM,eAAe,GAAG,0BAAkB,CAAC,MAAM,CAAC,CAAC;IACnD,IAAI,CAAC,2BAAmB,CAAC,eAAe,CAAC,EAAE;QACzC,MAAM,IAAI,KAAK,CAAC,sCAAoC,eAAe,oDAAiD,CAAC,CAAC;KACvH;IACD,IAAM,YAAY,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;IAC/C,IACE,CAAC,YAAY,GAAG,CAAC,CAAC;QAClB,CAAC,YAAY,GAAG,GAAG,CAAC,EACpB;QACA,MAAM,IAAI,KAAK,CAAC,sCAAoC,eAAe,4DAAyD,CAAC,CAAC;KAC/H;IACD,OAAO,YAAY,GAAG,GAAG,CAAC;AAC5B,CAAC,CAAC;AAEW,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/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,22 +41,50 @@ 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 (
|
|
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;
|
|
55
84
|
var busWidth = Math.trunc(size.width / spectrum.length);
|
|
56
85
|
var left = Math.trunc(position.x);
|
|
57
86
|
var top = Math.trunc(position.y);
|
|
58
87
|
var height = Math.trunc(size.height);
|
|
59
|
-
var margin = 4;
|
|
60
88
|
for (var spectrumX = 0; spectrumX < spectrum.length; spectrumX++) {
|
|
61
89
|
var spectrumValue = spectrum[spectrumX];
|
|
62
90
|
if ((spectrumValue > 1) || (spectrumValue < 0)) {
|
|
@@ -65,29 +93,54 @@ var drawSpectrum = function (imageDstBuffer, spectrum, size, position, rotation,
|
|
|
65
93
|
var rectX = left + busWidth * spectrumX;
|
|
66
94
|
var rectHeight = Math.trunc(height * spectrumValue);
|
|
67
95
|
var rectY = (rotation === 'up') ? top + height - rectHeight : top;
|
|
68
|
-
exports.drawRect(
|
|
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
|
+
});
|
|
69
103
|
}
|
|
70
104
|
};
|
|
71
|
-
exports.createVisualizerFrame = function (
|
|
72
|
-
var
|
|
73
|
-
|
|
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);
|
|
74
109
|
var rgbSpectrumColor = (typeof color === 'string') ? hexToRgb(color) : color;
|
|
75
|
-
drawSpectrum(
|
|
76
|
-
|
|
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;
|
|
77
121
|
};
|
|
78
122
|
exports.convertToBmp = function (filePath) { return __awaiter(void 0, void 0, void 0, function () {
|
|
79
123
|
return __generator(this, function (_a) {
|
|
80
|
-
return [2 /*return*/, new Promise(function (resolve) { return __awaiter(void 0, void 0, void 0, function () {
|
|
81
|
-
var image;
|
|
82
|
-
return __generator(this, function (
|
|
83
|
-
switch (
|
|
84
|
-
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)];
|
|
85
131
|
case 1:
|
|
86
|
-
image =
|
|
132
|
+
image = _b.sent();
|
|
87
133
|
image.getBuffer("image/bmp", function (err, value) {
|
|
134
|
+
if (err) {
|
|
135
|
+
reject(err);
|
|
136
|
+
}
|
|
88
137
|
resolve(value);
|
|
89
138
|
});
|
|
90
|
-
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*/];
|
|
91
144
|
}
|
|
92
145
|
});
|
|
93
146
|
}); })];
|
package/dist/image.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.js","sourceRoot":"","sources":["../src/image.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iCAAoD;AACpD,8CAAwB;
|
|
1
|
+
{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AAE,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
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, spectrumX, spectrumY, spectrumRotation, 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,6 +81,8 @@ 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,10 +91,10 @@ exports.renderAudioVisualizer = function (config, onProgress, shouldStop) {
|
|
|
89
91
|
spectrumRotation = config_1.getSpectrumRotation(config);
|
|
90
92
|
spectrumColor = config_1.getSpectrumColor(config) ||
|
|
91
93
|
image_1.invertColor(image_1.getImageColor(backgroundImage));
|
|
94
|
+
spectrumOpacity = config_1.getSpectrumOpacityParsed(config);
|
|
92
95
|
ffmpeg_cfr = config_1.getFfmpeg_cfr(config);
|
|
93
96
|
ffmpeg_preset = config_1.getFfmpeg_preset(config);
|
|
94
97
|
frame_processing_delay = config_1.getFrame_processing_delay(config);
|
|
95
|
-
spectrumBusesCount = 64;
|
|
96
98
|
audioDuration = audioBuffer.length / sampleRate;
|
|
97
99
|
framesCount = Math.trunc(audioDuration * FPS);
|
|
98
100
|
audioDataStep = Math.trunc(audioBuffer.length / framesCount);
|
|
@@ -108,7 +110,16 @@ exports.renderAudioVisualizer = function (config, onProgress, shouldStop) {
|
|
|
108
110
|
return exports.PCM_FORMAT.parseFunction(audioBuffer, i * audioDataStep, i * audioDataStep + audioDataStep);
|
|
109
111
|
};
|
|
110
112
|
spectrum = processSpectrum(i, audioDataParser);
|
|
111
|
-
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
|
+
});
|
|
112
123
|
frameImageBuffer = image_1.createImageBuffer(frameImage);
|
|
113
124
|
isFrameProcessed = ffmpegVideoWriter.stdin.write(frameImageBuffer);
|
|
114
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,mBAAmB,GAAG,+BAAsB,CAAC,MAAM,CAAC,CAAC;oBACrD,YAAY,GAAG,wBAAe,CAAC,MAAM,CAAC,CAAC;oBAEZ,qBAAM,oBAAY,CAAC,mBAAmB,CAAC,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AAiB;wCACzB,KAAK,EAAE,aAAa;wCACpB,OAAO,EAAE,eAAe;qCACzB,CAAC,CAAC;oCACG,gBAAgB,GAAG,yBAAiB,CAAC,UAAU,CAAC,CAAC;oCACjD,gBAAgB,GAAG,iBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;yCACrE,CAAC,gBAAgB,EAAjB,wBAAiB;oCACnB,qBAAM,iBAAS,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAA;;oCAAxC,SAAwC,CAAC;;;oCAE3C,IAAI,UAAU,IAAI,UAAU,EAAE,EAAE;;qCAE/B;yCACG,sBAAsB,EAAtB,wBAAsB;oCACxB,qBAAM,KAAK,CAAC,sBAAsB,CAAC,EAAA;;oCAAnC,SAAmC,CAAC;;;;;;oBAvB/B,CAAC,GAAG,CAAC;;;yBAAE,CAAA,CAAC,GAAG,WAAW,CAAA;kDAAtB,CAAC;;;;;;;oBAAuB,CAAC,EAAE,CAAA;;;oBA2BpC,iBAAiB,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;;;;SAC/B,CAAC;AA9EF,CA8EE,CAAC"}
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -7,7 +7,10 @@ export const defaults = {
|
|
|
7
7
|
spectrumHeight: '10%',
|
|
8
8
|
spectrumX: 'center',
|
|
9
9
|
spectrumY: 'top',
|
|
10
|
-
spectrumRotation: 'down'
|
|
10
|
+
spectrumRotation: 'down',
|
|
11
|
+
spectrumBusesCount: 64,
|
|
12
|
+
spectrumBusMargin: 4,
|
|
13
|
+
spectrumOpacity: '100%',
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
type RelativePositionValue = 0 | 0.5 | 1;
|
|
@@ -43,19 +46,25 @@ export const getOutVideoPath = (config: Config) =>
|
|
|
43
46
|
export const getFPS = (config: Config) =>
|
|
44
47
|
config.outVideo.fps || defaults.fps;
|
|
45
48
|
|
|
49
|
+
export const getSpectrumBusesCount = () => defaults.spectrumBusesCount;
|
|
50
|
+
|
|
51
|
+
export const getSpectrumBusMargin = () => defaults.spectrumBusMargin;
|
|
52
|
+
|
|
46
53
|
const getSpectrumWidth = (config: Config) =>
|
|
47
54
|
(config.outVideo.spectrum && config.outVideo.spectrum.width) ||
|
|
48
55
|
defaults.spectrumWidth;
|
|
49
56
|
|
|
50
57
|
const getSpectrumSizeAbsolute = (
|
|
51
|
-
spectrumSize: SpectrumSizeValue,
|
|
58
|
+
spectrumSize: SpectrumSizeValue,
|
|
59
|
+
backgroundImageSize: number,
|
|
60
|
+
fieldName: string
|
|
52
61
|
) => {
|
|
53
62
|
if (typeof spectrumSize === 'number') {
|
|
54
63
|
return spectrumSize;
|
|
55
64
|
}
|
|
56
65
|
const isPercentValue = checkIsPercentValue(spectrumSize);
|
|
57
66
|
if (!isPercentValue) {
|
|
58
|
-
throw new Error();
|
|
67
|
+
throw new Error(getSpectrumSizeValueErrorMessage(fieldName, spectrumSize));
|
|
59
68
|
}
|
|
60
69
|
const percentValue = parseInt(spectrumSize) / 100;
|
|
61
70
|
return backgroundImageSize * percentValue;
|
|
@@ -70,11 +79,13 @@ export const getSpectrumWidthAbsolute = (
|
|
|
70
79
|
config: Config, backgroundImageWidth: number
|
|
71
80
|
) => {
|
|
72
81
|
const spectrumWidth = getSpectrumWidth(config);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
const spectrumWidthAbsolute = getSpectrumSizeAbsolute(spectrumWidth, backgroundImageWidth, 'width');
|
|
83
|
+
const spectrumWidthWithoutMargin =
|
|
84
|
+
Math.trunc(spectrumWidthAbsolute / defaults.spectrumBusesCount) - defaults.spectrumBusMargin / 2;
|
|
85
|
+
if (spectrumWidthWithoutMargin <= 0) {
|
|
86
|
+
throw new Error(`Spectrum width '${spectrumWidth}' is too small.`);
|
|
77
87
|
}
|
|
88
|
+
return spectrumWidthAbsolute;
|
|
78
89
|
};
|
|
79
90
|
|
|
80
91
|
const getSpectrumHeight = (config: Config) =>
|
|
@@ -85,11 +96,7 @@ export const getSpectrumHeightAbsolute = (
|
|
|
85
96
|
config: Config, backgroundImageHeight: number
|
|
86
97
|
) => {
|
|
87
98
|
const spectrumHeight = getSpectrumHeight(config);
|
|
88
|
-
|
|
89
|
-
return getSpectrumSizeAbsolute(spectrumHeight, backgroundImageHeight);
|
|
90
|
-
} catch {
|
|
91
|
-
throw new Error(getSpectrumSizeValueErrorMessage('height', spectrumHeight));
|
|
92
|
-
}
|
|
99
|
+
return getSpectrumSizeAbsolute(spectrumHeight, backgroundImageHeight, 'height');
|
|
93
100
|
};
|
|
94
101
|
|
|
95
102
|
const getSpectrumX = (config: Config) =>
|
|
@@ -203,7 +210,26 @@ export const getSpectrumRotation = (config: Config): RotationAliasName => {
|
|
|
203
210
|
};
|
|
204
211
|
|
|
205
212
|
export const getSpectrumColor = (config: Config) =>
|
|
206
|
-
|
|
213
|
+
config.outVideo.spectrum && config.outVideo.spectrum.color;
|
|
214
|
+
|
|
215
|
+
export const getSpectrumOpacity = (config: Config) =>
|
|
216
|
+
(config.outVideo.spectrum && config.outVideo.spectrum.opacity) ||
|
|
217
|
+
defaults.spectrumOpacity;
|
|
218
|
+
|
|
219
|
+
export const getSpectrumOpacityParsed = (config: Config) => {
|
|
220
|
+
const spectrumOpacity = getSpectrumOpacity(config);
|
|
221
|
+
if (!checkIsPercentValue(spectrumOpacity)) {
|
|
222
|
+
throw new Error(`Invalid spectrum opacity value: '${spectrumOpacity}'. Use string percent value, for example '80%'.`);
|
|
223
|
+
}
|
|
224
|
+
const percentValue = parseInt(spectrumOpacity);
|
|
225
|
+
if (
|
|
226
|
+
(percentValue < 0) ||
|
|
227
|
+
(percentValue > 100)
|
|
228
|
+
) {
|
|
229
|
+
throw new Error(`Invalid spectrum opacity value: '${spectrumOpacity}'. Percent values must be in range from '0%' to '100%'.`);
|
|
230
|
+
}
|
|
231
|
+
return percentValue / 100;
|
|
232
|
+
};
|
|
207
233
|
|
|
208
234
|
export const getFfmpeg_cfr = (config: Config) =>
|
|
209
235
|
config.tweaks && config.tweaks.ffmpeg_cfr;
|