nodejs-audio-visualizer 1.1.1 → 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 CHANGED
@@ -16,8 +16,11 @@ const config = {
16
16
  path: 'media/out.mp4',
17
17
  fps: 25, // Default value: 60
18
18
  spectrum: { // Audio spectrum configuration. Optional.
19
- width: 300, // Default value: 40% of background image width
20
- height: 300, // Default value: 10% of background image 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
+ 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'.
21
24
  color: '#cccc99' // Default value: inverted color of background image
22
25
  }
23
26
  },
@@ -0,0 +1,25 @@
1
+ import { Config } from './index';
2
+ export declare const defaults: {
3
+ fps: number;
4
+ spectrumWidth: string;
5
+ spectrumHeight: string;
6
+ spectrumX: string;
7
+ spectrumY: string;
8
+ spectrumRotation: string;
9
+ };
10
+ export declare const rotationAliasValues: readonly ["up", "down"];
11
+ export declare const checkIsPercentValue: (value: string) => boolean;
12
+ export declare const getAudioFilePath: (config: Config) => string;
13
+ export declare const getBackgroundImagePath: (config: Config) => string;
14
+ export declare const getOutVideoPath: (config: Config) => string;
15
+ export declare const getFPS: (config: Config) => number;
16
+ export declare const getSpectrumWidthAbsolute: (config: Config, backgroundImageWidth: number) => number;
17
+ export declare const getSpectrumHeightAbsolute: (config: Config, backgroundImageHeight: number) => number;
18
+ export declare const getSpectrumXAbsolute: (config: Config, spectrumWidth: number, backgroundImageWidth: number) => number;
19
+ export declare const getSpectrumYAbsolute: (config: Config, spectrumHeight: number, backgroundImageHeight: number) => number;
20
+ export declare const checkIsValidRotationAlias: (aliasName: string) => boolean;
21
+ export declare const getSpectrumRotation: (config: Config) => "up" | "down";
22
+ export declare const getSpectrumColor: (config: Config) => string | import("./image").Color | undefined;
23
+ export declare const getFfmpeg_cfr: (config: Config) => string | undefined;
24
+ export declare const getFfmpeg_preset: (config: Config) => string | undefined;
25
+ export declare const getFrame_processing_delay: (config: Config) => number | undefined;
package/dist/config.js ADDED
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var path_1 = __importDefault(require("path"));
7
+ exports.defaults = {
8
+ fps: 60,
9
+ spectrumWidth: '40%',
10
+ spectrumHeight: '10%',
11
+ spectrumX: 'center',
12
+ spectrumY: 'top',
13
+ spectrumRotation: 'down'
14
+ };
15
+ var postitionAliases = [
16
+ { name: 'left', value: 0 },
17
+ { name: 'center', value: 0.5 },
18
+ { name: 'right', value: 1 },
19
+ { name: 'top', value: 0 },
20
+ { name: 'middle', value: 0.5 },
21
+ { name: 'bottom', value: 1 },
22
+ ];
23
+ exports.rotationAliasValues = ['up', 'down'];
24
+ exports.checkIsPercentValue = function (value) {
25
+ return RegExp(/\d+%/).test(value);
26
+ };
27
+ exports.getAudioFilePath = function (config) {
28
+ return path_1.default.resolve(config.audio.path);
29
+ };
30
+ exports.getBackgroundImagePath = function (config) {
31
+ return path_1.default.resolve(config.image.path);
32
+ };
33
+ exports.getOutVideoPath = function (config) {
34
+ return path_1.default.resolve(config.outVideo.path);
35
+ };
36
+ exports.getFPS = function (config) {
37
+ return config.outVideo.fps || exports.defaults.fps;
38
+ };
39
+ var getSpectrumWidth = function (config) {
40
+ return (config.outVideo.spectrum && config.outVideo.spectrum.width) ||
41
+ exports.defaults.spectrumWidth;
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
+ };
57
+ exports.getSpectrumWidthAbsolute = function (config, backgroundImageWidth) {
58
+ var spectrumWidth = getSpectrumWidth(config);
59
+ try {
60
+ return getSpectrumSizeAbsolute(spectrumWidth, backgroundImageWidth);
61
+ }
62
+ catch (_a) {
63
+ throw new Error(getSpectrumSizeValueErrorMessage('width', spectrumWidth));
64
+ }
65
+ };
66
+ var getSpectrumHeight = function (config) {
67
+ return (config.outVideo.spectrum && config.outVideo.spectrum.height) ||
68
+ exports.defaults.spectrumHeight;
69
+ };
70
+ exports.getSpectrumHeightAbsolute = function (config, backgroundImageHeight) {
71
+ var spectrumHeight = getSpectrumHeight(config);
72
+ try {
73
+ return getSpectrumSizeAbsolute(spectrumHeight, backgroundImageHeight);
74
+ }
75
+ catch (_a) {
76
+ throw new Error(getSpectrumSizeValueErrorMessage('height', spectrumHeight));
77
+ }
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;
121
+ }
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;
156
+ };
157
+ exports.getSpectrumColor = function (config) {
158
+ return (config.outVideo.spectrum && config.outVideo.spectrum.color);
159
+ };
160
+ exports.getFfmpeg_cfr = function (config) {
161
+ return config.tweaks && config.tweaks.ffmpeg_cfr;
162
+ };
163
+ exports.getFfmpeg_preset = function (config) {
164
+ return config.tweaks && config.tweaks.ffmpeg_preset;
165
+ };
166
+ exports.getFrame_processing_delay = function (config) {
167
+ return config.tweaks && config.tweaks.frame_processing_delay;
168
+ };
169
+ //# sourceMappingURL=config.js.map
@@ -0,0 +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;CACzB,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,EAAE;IACzB,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE;IAC9B,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE;CAC7B,CAAC;AAEW,QAAA,mBAAmB,GAAG,CAAC,IAA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AAc;IAChD,IAAM,aAAa,GACjB,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC/D,gBAAQ,CAAC,gBAAgB,CAAC;IAC5B,IAAI,CAAC,iCAAyB,CAAC,aAAa,CAAC,EAAE;QAC7C,MAAM,IAAI,KAAK,CAAC,sCAAoC,aAAa,wBAAmB,2BAA2B,MAAG,CAAC,CAAC;KACrH;IACD,OAAO,aAAkC,CAAC;AAC5C,CAAC,CAAC;AAEW,QAAA,gBAAgB,GAAG,UAAC,MAAc;IAC7C,OAAA,CAAC,MAAM,CAAC,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/image.d.ts CHANGED
@@ -14,7 +14,7 @@ interface Size {
14
14
  height: number;
15
15
  }
16
16
  export declare const drawRect: (imageDstBuffer: BmpDecoder, position: Position, size: Size, color: Color) => void;
17
- export declare const createVisualizerFrame: (backgroundImageBuffer: BmpDecoder, spectrum: number[], size: Size, color: string | Color) => BmpDecoder;
17
+ export declare const createVisualizerFrame: (backgroundImageBuffer: BmpDecoder, spectrum: number[], size: Size, position: Position, rotation: "up" | "down", color: string | Color) => BmpDecoder;
18
18
  export declare const convertToBmp: (filePath: string) => Promise<Buffer>;
19
19
  export declare const parseImage: (buffer: Buffer) => BmpDecoder;
20
20
  export declare const createImageBuffer: (image: BmpDecoder) => Buffer;
package/dist/image.js CHANGED
@@ -51,25 +51,28 @@ exports.drawRect = function (imageDstBuffer, position, size, color) {
51
51
  }
52
52
  }
53
53
  };
54
- var drawSpectrum = function (imageDstBuffer, spectrum, size, color) {
55
- var paddingLeft = Math.trunc(imageDstBuffer.width / 2 - size.width / 2);
54
+ var drawSpectrum = function (imageDstBuffer, spectrum, size, position, rotation, color) {
56
55
  var busWidth = Math.trunc(size.width / spectrum.length);
56
+ var left = Math.trunc(position.x);
57
+ var top = Math.trunc(position.y);
58
+ var height = Math.trunc(size.height);
57
59
  var margin = 4;
58
60
  for (var spectrumX = 0; spectrumX < spectrum.length; spectrumX++) {
59
61
  var spectrumValue = spectrum[spectrumX];
60
62
  if ((spectrumValue > 1) || (spectrumValue < 0)) {
61
63
  throw new Error('Spectrum values must be in range from 0 to 1');
62
64
  }
63
- var rectX = paddingLeft + busWidth * spectrumX;
64
- var rectHeight = size.height * spectrumValue;
65
- exports.drawRect(imageDstBuffer, { x: rectX + margin, y: 0 }, { width: busWidth - margin / 2, height: rectHeight }, color);
65
+ var rectX = left + busWidth * spectrumX;
66
+ var rectHeight = Math.trunc(height * spectrumValue);
67
+ var rectY = (rotation === 'up') ? top + height - rectHeight : top;
68
+ exports.drawRect(imageDstBuffer, { x: rectX + margin, y: rectY }, { width: busWidth - margin / 2, height: rectHeight }, color);
66
69
  }
67
70
  };
68
- exports.createVisualizerFrame = function (backgroundImageBuffer, spectrum, size, color) {
71
+ exports.createVisualizerFrame = function (backgroundImageBuffer, spectrum, size, position, rotation, color) {
69
72
  var image = Object.assign({}, backgroundImageBuffer);
70
73
  image.data = Buffer.from(image.data);
71
74
  var rgbSpectrumColor = (typeof color === 'string') ? hexToRgb(color) : color;
72
- drawSpectrum(image, spectrum, size, rgbSpectrumColor);
75
+ drawSpectrum(image, spectrum, size, position, rotation, rgbSpectrumColor);
73
76
  return image;
74
77
  };
75
78
  exports.convertToBmp = function (filePath) { return __awaiter(void 0, void 0, void 0, function () {
package/dist/image.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"image.js","sourceRoot":"","sources":["../src/image.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAoD;AACpD,8CAAwB;AAkBX,QAAA,QAAQ,GAAG,UAAC,cAA0B,EAAE,QAAkB,EAAE,IAAU,EAAE,KAAY;IAC/F,KAAK,IAAI,KAAK,GAAG,QAAQ,CAAC,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QACtE,KAAK,IAAI,KAAK,GAAG,QAAQ,CAAC,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YACrE,IAAI,GAAG,GAAG,CAAC,cAAc,CAAC,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;YAEtD,cAAc,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC;YAC1C,cAAc,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;YAC3C,cAAc,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC;SAC1C;KACF;AACH,CAAC,CAAC;AAEF,IAAM,YAAY,GAAG,UAAC,cAA0B,EAAE,QAAkB,EAAE,IAAU,EAAE,KAAY;IAC5F,IAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAC1E,IAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,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CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC;IAC/C,OAAO;QACL,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,WAAW,CAAC;QAC7B,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,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,8 +17,11 @@ export interface Config {
16
17
  path: string;
17
18
  fps?: number;
18
19
  spectrum?: {
19
- width?: number;
20
- height?: number;
20
+ width?: SpectrumSizeValue;
21
+ height?: SpectrumSizeValue;
22
+ x?: number | PositionAliasName;
23
+ y?: number | PositionAliasName;
24
+ rotation?: RotationAliasName;
21
25
  color?: Color | string;
22
26
  };
23
27
  };
@@ -27,4 +31,7 @@ export interface Config {
27
31
  frame_processing_delay?: number;
28
32
  };
29
33
  }
34
+ export declare type SpectrumSizeValue = number | string;
35
+ export declare type PositionAliasName = 'left' | 'center' | 'right' | 'top' | 'middle' | 'bottom';
36
+ export declare type RotationAliasName = typeof rotationAliasValues[number];
30
37
  export declare const renderAudioVisualizer: (config: Config, onProgress?: ((progress: number) => any) | undefined, shouldStop?: (() => boolean) | undefined) => Promise<number>;
package/dist/index.js CHANGED
@@ -46,11 +46,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
49
  Object.defineProperty(exports, "__esModule", { value: true });
53
- var path_1 = __importDefault(require("path"));
50
+ var config_1 = require("./config");
54
51
  var audio_1 = require("./audio");
55
52
  var image_1 = require("./image");
56
53
  var video_1 = require("./video");
@@ -61,17 +58,17 @@ exports.PCM_FORMAT = {
61
58
  };
62
59
  var FFMPEG_FORMAT = "" + exports.PCM_FORMAT.sign + exports.PCM_FORMAT.bit;
63
60
  var sleep = function (timeout) {
64
- return new Promise(function (resolve) { return setTimeout(resolve, 1000); });
61
+ return new Promise(function (resolve) { return setTimeout(resolve, timeout); });
65
62
  };
66
63
  exports.renderAudioVisualizer = function (config, onProgress, shouldStop) {
67
64
  return new Promise(function (resolve) { return __awaiter(void 0, void 0, void 0, function () {
68
- var audioFilePath, backgroundImagePath, outVideoPath, backgroundImageBmpBuffer, backgroundImage, audioReader, audioBuffer, sampleRate, FPS, spectrumWidth, spectrumHeight, spectrumColor, ffmpeg_cfr, ffmpeg_preset, frame_processing_delay, spectrumBusesCount, audioDuration, framesCount, audioDataStep, ffmpegVideoWriter, processSpectrum, _loop_1, i, state_1;
65
+ var audioFilePath, backgroundImagePath, outVideoPath, backgroundImageBmpBuffer, backgroundImage, audioReader, audioBuffer, sampleRate, FPS, spectrumWidth, spectrumHeight, spectrumX, spectrumY, spectrumRotation, spectrumColor, ffmpeg_cfr, ffmpeg_preset, frame_processing_delay, spectrumBusesCount, audioDuration, framesCount, audioDataStep, ffmpegVideoWriter, processSpectrum, _loop_1, i, state_1;
69
66
  return __generator(this, function (_a) {
70
67
  switch (_a.label) {
71
68
  case 0:
72
- audioFilePath = path_1.default.resolve(config.audio.path);
73
- backgroundImagePath = path_1.default.resolve(config.image.path);
74
- outVideoPath = path_1.default.resolve(config.outVideo.path);
69
+ audioFilePath = config_1.getAudioFilePath(config);
70
+ backgroundImagePath = config_1.getBackgroundImagePath(config);
71
+ outVideoPath = config_1.getOutVideoPath(config);
75
72
  return [4 /*yield*/, image_1.convertToBmp(backgroundImagePath)];
76
73
  case 1:
77
74
  backgroundImageBmpBuffer = _a.sent();
@@ -84,16 +81,17 @@ exports.renderAudioVisualizer = function (config, onProgress, shouldStop) {
84
81
  if (!sampleRate) {
85
82
  throw new Error('ffmpeg didn\'t show audio sample rate');
86
83
  }
87
- FPS = config.outVideo.fps || 60;
88
- spectrumWidth = (config.outVideo.spectrum && config.outVideo.spectrum.width) ||
89
- backgroundImage.width * 0.4;
90
- spectrumHeight = (config.outVideo.spectrum && config.outVideo.spectrum.height) ||
91
- backgroundImage.height * 0.1;
92
- spectrumColor = (config.outVideo.spectrum && config.outVideo.spectrum.color) ||
84
+ FPS = config_1.getFPS(config);
85
+ spectrumWidth = config_1.getSpectrumWidthAbsolute(config, backgroundImage.width);
86
+ spectrumHeight = config_1.getSpectrumHeightAbsolute(config, backgroundImage.height);
87
+ spectrumX = config_1.getSpectrumXAbsolute(config, spectrumWidth, backgroundImage.width);
88
+ spectrumY = config_1.getSpectrumYAbsolute(config, spectrumHeight, backgroundImage.height);
89
+ spectrumRotation = config_1.getSpectrumRotation(config);
90
+ spectrumColor = config_1.getSpectrumColor(config) ||
93
91
  image_1.invertColor(image_1.getImageColor(backgroundImage));
94
- ffmpeg_cfr = config.tweaks && config.tweaks.ffmpeg_cfr;
95
- ffmpeg_preset = config.tweaks && config.tweaks.ffmpeg_preset;
96
- frame_processing_delay = config.tweaks && config.tweaks.frame_processing_delay;
92
+ ffmpeg_cfr = config_1.getFfmpeg_cfr(config);
93
+ ffmpeg_preset = config_1.getFfmpeg_preset(config);
94
+ frame_processing_delay = config_1.getFrame_processing_delay(config);
97
95
  spectrumBusesCount = 64;
98
96
  audioDuration = audioBuffer.length / sampleRate;
99
97
  framesCount = Math.trunc(audioDuration * FPS);
@@ -110,7 +108,7 @@ exports.renderAudioVisualizer = function (config, onProgress, shouldStop) {
110
108
  return exports.PCM_FORMAT.parseFunction(audioBuffer, i * audioDataStep, i * audioDataStep + audioDataStep);
111
109
  };
112
110
  spectrum = processSpectrum(i, audioDataParser);
113
- frameImage = image_1.createVisualizerFrame(backgroundImage, spectrum, { width: spectrumWidth, height: spectrumHeight }, spectrumColor);
111
+ frameImage = image_1.createVisualizerFrame(backgroundImage, spectrum, { width: spectrumWidth, height: spectrumHeight }, { x: spectrumX, y: spectrumY }, spectrumRotation, spectrumColor);
114
112
  frameImageBuffer = image_1.createImageBuffer(frameImage);
115
113
  isFrameProcessed = ffmpegVideoWriter.stdin.write(frameImageBuffer);
116
114
  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,8CAAwB;AACxB,iCAAqF;AACrF,iCAAgI;AAChI,iCAA4F;AAE/E,QAAA,UAAU,GAAG;IACxB,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,GAAG;IACT,aAAa,EAAE,qB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,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodejs-audio-visualizer",
3
- "version": "1.1.1",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/config.ts ADDED
@@ -0,0 +1,216 @@
1
+ import path from 'path';
2
+ import { Config, SpectrumSizeValue, PositionAliasName, RotationAliasName } from './index';
3
+
4
+ export const defaults = {
5
+ fps: 60,
6
+ spectrumWidth: '40%',
7
+ spectrumHeight: '10%',
8
+ spectrumX: 'center',
9
+ spectrumY: 'top',
10
+ spectrumRotation: 'down'
11
+ };
12
+
13
+ type RelativePositionValue = 0 | 0.5 | 1;
14
+
15
+ interface PositionAlias {
16
+ name: PositionAliasName;
17
+ value: RelativePositionValue;
18
+ }
19
+
20
+ const postitionAliases: PositionAlias[] = [
21
+ { name: 'left', value: 0 },
22
+ { name: 'center', value: 0.5 },
23
+ { name: 'right', value: 1 },
24
+ { name: 'top', value: 0 },
25
+ { name: 'middle', value: 0.5 },
26
+ { name: 'bottom', value: 1 },
27
+ ];
28
+
29
+ export const rotationAliasValues = ['up', 'down'] as const;
30
+
31
+ export const checkIsPercentValue = (value: string) =>
32
+ RegExp(/\d+%/).test(value)
33
+
34
+ export const getAudioFilePath = (config: Config) =>
35
+ path.resolve(config.audio.path);
36
+
37
+ export const getBackgroundImagePath = (config: Config) =>
38
+ path.resolve(config.image.path);
39
+
40
+ export const getOutVideoPath = (config: Config) =>
41
+ path.resolve(config.outVideo.path);
42
+
43
+ export const getFPS = (config: Config) =>
44
+ config.outVideo.fps || defaults.fps;
45
+
46
+ const getSpectrumWidth = (config: Config) =>
47
+ (config.outVideo.spectrum && config.outVideo.spectrum.width) ||
48
+ defaults.spectrumWidth;
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
+
69
+ export const getSpectrumWidthAbsolute = (
70
+ config: Config, backgroundImageWidth: number
71
+ ) => {
72
+ const spectrumWidth = getSpectrumWidth(config);
73
+ try {
74
+ return getSpectrumSizeAbsolute(spectrumWidth, backgroundImageWidth);
75
+ } catch {
76
+ throw new Error(getSpectrumSizeValueErrorMessage('width', spectrumWidth));
77
+ }
78
+ };
79
+
80
+ const getSpectrumHeight = (config: Config) =>
81
+ (config.outVideo.spectrum && config.outVideo.spectrum.height) ||
82
+ defaults.spectrumHeight;
83
+
84
+ export const getSpectrumHeightAbsolute = (
85
+ config: Config, backgroundImageHeight: number
86
+ ) => {
87
+ const spectrumHeight = getSpectrumHeight(config);
88
+ try {
89
+ return getSpectrumSizeAbsolute(spectrumHeight, backgroundImageHeight);
90
+ } catch {
91
+ throw new Error(getSpectrumSizeValueErrorMessage('height', spectrumHeight));
92
+ }
93
+ };
94
+
95
+ const getSpectrumX = (config: Config) =>
96
+ parseNumberIfPossible(
97
+ (config.outVideo.spectrum && config.outVideo.spectrum.x) ||
98
+ defaults.spectrumX
99
+ );
100
+
101
+ const getSpectrumY = (config: Config) =>
102
+ parseNumberIfPossible(
103
+ (config.outVideo.spectrum && config.outVideo.spectrum.y) ||
104
+ defaults.spectrumY
105
+ );
106
+
107
+ const parseNumberIfPossible = (value: string | number) => {
108
+ const parsed = Number(value);
109
+ if (isNaN(parsed)) {
110
+ return value;
111
+ }
112
+ return parsed;
113
+ };
114
+
115
+ const parsePositionAlias = (aliasName: string): PositionAlias => {
116
+ const nameNormalized = aliasName.trim().toLowerCase();
117
+ const alias = postitionAliases.find(
118
+ als => als.name === nameNormalized
119
+ );
120
+ if (!alias) {
121
+ throw new Error();
122
+ }
123
+ return alias;
124
+ };
125
+
126
+ const getValidPositionAliasValues = () =>
127
+ postitionAliases.map(aliasEl => aliasEl.name).join(', ');
128
+
129
+ const getSpectrumAbsolutePosition = (
130
+ relativePosition: RelativePositionValue,
131
+ spectrumSize: number,
132
+ backgroundImageSize: number
133
+ ) => {
134
+ switch (relativePosition) {
135
+ case 0:
136
+ return 0;
137
+ case 0.5:
138
+ return relativePosition * backgroundImageSize - spectrumSize / 2;
139
+ case 1:
140
+ return relativePosition * backgroundImageSize - spectrumSize;
141
+ default:
142
+ throw new Error();
143
+ }
144
+ };
145
+
146
+ export const getSpectrumXAbsolute = (
147
+ config: Config,
148
+ spectrumWidth: number,
149
+ backgroundImageWidth: number
150
+ ) => {
151
+ const spectrumX = getSpectrumX(config);
152
+ if (typeof spectrumX !== 'string') {
153
+ return spectrumX;
154
+ }
155
+ try {
156
+ const spectrumXParsed = parsePositionAlias(spectrumX);
157
+ return getSpectrumAbsolutePosition(
158
+ spectrumXParsed.value,
159
+ spectrumWidth,
160
+ backgroundImageWidth
161
+ );
162
+ } catch {
163
+ throw new Error(`Invalid spectrum x value: ${spectrumX}. Valid values: ${getValidPositionAliasValues()}.`);
164
+ }
165
+ };
166
+
167
+ export const getSpectrumYAbsolute = (
168
+ config: Config,
169
+ spectrumHeight: number,
170
+ backgroundImageHeight: number
171
+ ) => {
172
+ const spectrumY = getSpectrumY(config);
173
+ if (typeof spectrumY !== 'string') {
174
+ return spectrumY;
175
+ }
176
+ try {
177
+ const spectrumXParsed = parsePositionAlias(spectrumY);
178
+ return getSpectrumAbsolutePosition(
179
+ spectrumXParsed.value,
180
+ spectrumHeight,
181
+ backgroundImageHeight
182
+ );
183
+ } catch {
184
+ throw new Error(`Invalid spectrum y value: ${spectrumY}. Valid values: ${getValidPositionAliasValues()}.`);
185
+ }
186
+ };
187
+
188
+ const getValidRotationAliasValues = () =>
189
+ rotationAliasValues.join(', ');
190
+
191
+ export const checkIsValidRotationAlias = (aliasName: string) => {
192
+ return !!rotationAliasValues.find(al => al === aliasName);
193
+ };
194
+
195
+ export const getSpectrumRotation = (config: Config): RotationAliasName => {
196
+ const rotationValue =
197
+ (config.outVideo.spectrum && config.outVideo.spectrum.rotation) ||
198
+ defaults.spectrumRotation;
199
+ if (!checkIsValidRotationAlias(rotationValue)) {
200
+ throw new Error(`Invalid spectrum rotation value: ${rotationValue}. Valid values: ${getValidRotationAliasValues}.`);
201
+ }
202
+ return rotationValue as RotationAliasName;
203
+ };
204
+
205
+ export const getSpectrumColor = (config: Config) =>
206
+ (config.outVideo.spectrum && config.outVideo.spectrum.color);
207
+
208
+ export const getFfmpeg_cfr = (config: Config) =>
209
+ config.tweaks && config.tweaks.ffmpeg_cfr;
210
+
211
+ export const getFfmpeg_preset = (config: Config) =>
212
+ config.tweaks && config.tweaks.ffmpeg_preset;
213
+
214
+ export const getFrame_processing_delay = (config: Config) =>
215
+ config.tweaks && config.tweaks.frame_processing_delay;
216
+