@zwa73/utils 1.0.157 → 1.0.159
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/dist/UtilFfmpegTools.js +31 -13
- package/package.json +1 -1
- package/src/UtilFfmpegTools.ts +31 -13
package/dist/UtilFfmpegTools.js
CHANGED
|
@@ -116,12 +116,18 @@ class SFfmpegTool {
|
|
|
116
116
|
*/
|
|
117
117
|
static async cutAudio(audioPath, outPath, start, time) {
|
|
118
118
|
return new Promise((resolve, reject) => {
|
|
119
|
-
(0, fluent_ffmpeg_1.default)(audioPath)
|
|
119
|
+
const ins = (0, fluent_ffmpeg_1.default)(audioPath)
|
|
120
120
|
.setStartTime(start)
|
|
121
121
|
.setDuration(time)
|
|
122
122
|
.save(outPath)
|
|
123
|
-
.on("end", () =>
|
|
124
|
-
|
|
123
|
+
.on("end", () => {
|
|
124
|
+
resolve(true);
|
|
125
|
+
ins.kill('SIGTERM');
|
|
126
|
+
})
|
|
127
|
+
.on("error", (err) => {
|
|
128
|
+
reject(err);
|
|
129
|
+
ins.kill('SIGTERM');
|
|
130
|
+
});
|
|
125
131
|
});
|
|
126
132
|
}
|
|
127
133
|
/**删除首尾静音
|
|
@@ -132,14 +138,20 @@ class SFfmpegTool {
|
|
|
132
138
|
*/
|
|
133
139
|
static async trimSilence(inputWavPath, outputWavPath, threshold = -50, silence = 0.2) {
|
|
134
140
|
return new Promise((resolve, reject) => {
|
|
135
|
-
(0, fluent_ffmpeg_1.default)(inputWavPath)
|
|
141
|
+
const ins = (0, fluent_ffmpeg_1.default)(inputWavPath)
|
|
136
142
|
.audioFilters(`silenceremove=start_periods=1:start_threshold=${threshold}dB:start_silence=${silence}`)
|
|
137
143
|
.audioFilters("areverse")
|
|
138
144
|
.audioFilters(`silenceremove=start_periods=1:start_threshold=${threshold}dB:start_silence=${silence}`)
|
|
139
145
|
.audioFilters("areverse")
|
|
140
146
|
.save(outputWavPath)
|
|
141
|
-
.on("end", () =>
|
|
142
|
-
|
|
147
|
+
.on("end", () => {
|
|
148
|
+
resolve(true);
|
|
149
|
+
ins.kill('SIGTERM');
|
|
150
|
+
})
|
|
151
|
+
.on("error", (err) => {
|
|
152
|
+
reject(err);
|
|
153
|
+
ins.kill('SIGTERM');
|
|
154
|
+
});
|
|
143
155
|
});
|
|
144
156
|
}
|
|
145
157
|
/**重采样
|
|
@@ -148,11 +160,17 @@ class SFfmpegTool {
|
|
|
148
160
|
*/
|
|
149
161
|
static async resample(inputWavPath, outputWavPath, rate = 22050) {
|
|
150
162
|
return new Promise((resolve, reject) => {
|
|
151
|
-
(0, fluent_ffmpeg_1.default)(inputWavPath)
|
|
163
|
+
const ins = (0, fluent_ffmpeg_1.default)(inputWavPath)
|
|
152
164
|
.audioFrequency(rate)
|
|
153
165
|
.save(outputWavPath)
|
|
154
|
-
.on("end", () =>
|
|
155
|
-
|
|
166
|
+
.on("end", () => {
|
|
167
|
+
resolve(true);
|
|
168
|
+
ins.kill('SIGTERM');
|
|
169
|
+
})
|
|
170
|
+
.on("error", (err) => {
|
|
171
|
+
reject(err);
|
|
172
|
+
ins.kill('SIGTERM');
|
|
173
|
+
});
|
|
156
174
|
});
|
|
157
175
|
}
|
|
158
176
|
//多线程处理
|
|
@@ -162,7 +180,7 @@ class SFfmpegTool {
|
|
|
162
180
|
* @param cpCount - 并发数
|
|
163
181
|
*/
|
|
164
182
|
static async wav2oggMP(ioMap, quality = 10, cpCount = 16) {
|
|
165
|
-
await new UtilClass_1.Stream(Object.entries(ioMap))
|
|
183
|
+
await new UtilClass_1.Stream(Object.entries(ioMap), cpCount)
|
|
166
184
|
.map(async ([inPath, outPath]) => {
|
|
167
185
|
UtilLogger_1.SLogger.info(`SFfmpegTool.wav2oggMP 正在处理:${outPath}`);
|
|
168
186
|
await SFfmpegTool.wav2ogg(inPath, outPath, quality);
|
|
@@ -175,7 +193,7 @@ class SFfmpegTool {
|
|
|
175
193
|
* @param cpCount - 并发数
|
|
176
194
|
*/
|
|
177
195
|
static async flac2oggMP(ioMap, quality = 10, cpCount = 16) {
|
|
178
|
-
await new UtilClass_1.Stream(Object.entries(ioMap))
|
|
196
|
+
await new UtilClass_1.Stream(Object.entries(ioMap), cpCount)
|
|
179
197
|
.map(async ([inPath, outPath]) => {
|
|
180
198
|
UtilLogger_1.SLogger.info(`SFfmpegTool.flac2oggMP 正在处理:${outPath}`);
|
|
181
199
|
await SFfmpegTool.flac2ogg(inPath, outPath, quality);
|
|
@@ -188,7 +206,7 @@ class SFfmpegTool {
|
|
|
188
206
|
* @param silence - 保留静音时长
|
|
189
207
|
*/
|
|
190
208
|
static async trimSilenceMP(ioMap, threshold = -50, silence = 0.2, cpCount = 16) {
|
|
191
|
-
await new UtilClass_1.Stream(Object.entries(ioMap))
|
|
209
|
+
await new UtilClass_1.Stream(Object.entries(ioMap), cpCount)
|
|
192
210
|
.map(async ([inPath, outPath]) => {
|
|
193
211
|
UtilLogger_1.SLogger.info(`SFfmpegTool.trimSilenceMP 正在处理:${outPath}`);
|
|
194
212
|
await SFfmpegTool.trimSilence(inPath, outPath, threshold, silence);
|
|
@@ -201,7 +219,7 @@ class SFfmpegTool {
|
|
|
201
219
|
* @param cpCount - 并发数
|
|
202
220
|
*/
|
|
203
221
|
static async resampleMP(ioMap, rate = 22050, cpCount = 16) {
|
|
204
|
-
await new UtilClass_1.Stream(Object.entries(ioMap))
|
|
222
|
+
await new UtilClass_1.Stream(Object.entries(ioMap), cpCount)
|
|
205
223
|
.map(async ([inPath, outPath]) => {
|
|
206
224
|
UtilLogger_1.SLogger.info(`SFfmpegTool.resampleMP 正在处理:${outPath}`);
|
|
207
225
|
await SFfmpegTool.resample(inPath, outPath, rate);
|
package/package.json
CHANGED
package/src/UtilFfmpegTools.ts
CHANGED
|
@@ -110,12 +110,18 @@ class SFfmpegTool {
|
|
|
110
110
|
time: number
|
|
111
111
|
): Promise<boolean> {
|
|
112
112
|
return new Promise((resolve, reject) => {
|
|
113
|
-
fluentFfmpeg(audioPath)
|
|
113
|
+
const ins = fluentFfmpeg(audioPath)
|
|
114
114
|
.setStartTime(start)
|
|
115
115
|
.setDuration(time)
|
|
116
116
|
.save(outPath)
|
|
117
|
-
.on("end", () =>
|
|
118
|
-
|
|
117
|
+
.on("end", () => {
|
|
118
|
+
resolve(true);
|
|
119
|
+
ins.kill('SIGTERM');
|
|
120
|
+
})
|
|
121
|
+
.on("error", (err) => {
|
|
122
|
+
reject(err);
|
|
123
|
+
ins.kill('SIGTERM');
|
|
124
|
+
});
|
|
119
125
|
});
|
|
120
126
|
}
|
|
121
127
|
/**删除首尾静音
|
|
@@ -131,7 +137,7 @@ class SFfmpegTool {
|
|
|
131
137
|
silence: number = 0.2
|
|
132
138
|
): Promise<boolean> {
|
|
133
139
|
return new Promise((resolve, reject) => {
|
|
134
|
-
fluentFfmpeg(inputWavPath)
|
|
140
|
+
const ins = fluentFfmpeg(inputWavPath)
|
|
135
141
|
.audioFilters(
|
|
136
142
|
`silenceremove=start_periods=1:start_threshold=${threshold}dB:start_silence=${silence}`
|
|
137
143
|
)
|
|
@@ -141,8 +147,14 @@ class SFfmpegTool {
|
|
|
141
147
|
)
|
|
142
148
|
.audioFilters("areverse")
|
|
143
149
|
.save(outputWavPath)
|
|
144
|
-
.on("end", () =>
|
|
145
|
-
|
|
150
|
+
.on("end", () => {
|
|
151
|
+
resolve(true);
|
|
152
|
+
ins.kill('SIGTERM');
|
|
153
|
+
})
|
|
154
|
+
.on("error", (err) => {
|
|
155
|
+
reject(err);
|
|
156
|
+
ins.kill('SIGTERM');
|
|
157
|
+
});
|
|
146
158
|
});
|
|
147
159
|
}
|
|
148
160
|
/**重采样
|
|
@@ -151,11 +163,17 @@ class SFfmpegTool {
|
|
|
151
163
|
*/
|
|
152
164
|
static async resample(inputWavPath: string, outputWavPath: string, rate: number = 22050): Promise<boolean> {
|
|
153
165
|
return new Promise((resolve, reject) => {
|
|
154
|
-
fluentFfmpeg(inputWavPath)
|
|
166
|
+
const ins = fluentFfmpeg(inputWavPath)
|
|
155
167
|
.audioFrequency(rate)
|
|
156
168
|
.save(outputWavPath)
|
|
157
|
-
.on("end", () =>
|
|
158
|
-
|
|
169
|
+
.on("end", () => {
|
|
170
|
+
resolve(true);
|
|
171
|
+
ins.kill('SIGTERM');
|
|
172
|
+
})
|
|
173
|
+
.on("error", (err) => {
|
|
174
|
+
reject(err);
|
|
175
|
+
ins.kill('SIGTERM');
|
|
176
|
+
});
|
|
159
177
|
});
|
|
160
178
|
}
|
|
161
179
|
|
|
@@ -166,7 +184,7 @@ class SFfmpegTool {
|
|
|
166
184
|
* @param cpCount - 并发数
|
|
167
185
|
*/
|
|
168
186
|
static async wav2oggMP(ioMap: IOMap, quality = 10, cpCount = 16) {
|
|
169
|
-
await new Stream(Object.entries(ioMap))
|
|
187
|
+
await new Stream(Object.entries(ioMap),cpCount)
|
|
170
188
|
.map(async ([inPath, outPath]) => {
|
|
171
189
|
SLogger.info(`SFfmpegTool.wav2oggMP 正在处理:${outPath}`);
|
|
172
190
|
await SFfmpegTool.wav2ogg(inPath, outPath, quality);
|
|
@@ -183,7 +201,7 @@ class SFfmpegTool {
|
|
|
183
201
|
quality: number = 10,
|
|
184
202
|
cpCount: number = 16
|
|
185
203
|
) {
|
|
186
|
-
await new Stream(Object.entries(ioMap))
|
|
204
|
+
await new Stream(Object.entries(ioMap),cpCount)
|
|
187
205
|
.map(async ([inPath, outPath]) => {
|
|
188
206
|
SLogger.info(`SFfmpegTool.flac2oggMP 正在处理:${outPath}`);
|
|
189
207
|
await SFfmpegTool.flac2ogg(inPath, outPath, quality);
|
|
@@ -201,7 +219,7 @@ class SFfmpegTool {
|
|
|
201
219
|
silence: number = 0.2,
|
|
202
220
|
cpCount: number = 16
|
|
203
221
|
) {
|
|
204
|
-
await new Stream(Object.entries(ioMap))
|
|
222
|
+
await new Stream(Object.entries(ioMap),cpCount)
|
|
205
223
|
.map(async ([inPath, outPath]) => {
|
|
206
224
|
SLogger.info(`SFfmpegTool.trimSilenceMP 正在处理:${outPath}`);
|
|
207
225
|
await SFfmpegTool.trimSilence(inPath, outPath, threshold, silence);
|
|
@@ -215,7 +233,7 @@ class SFfmpegTool {
|
|
|
215
233
|
* @param cpCount - 并发数
|
|
216
234
|
*/
|
|
217
235
|
static async resampleMP(ioMap: IOMap, rate: number = 22050, cpCount: number = 16) {
|
|
218
|
-
await new Stream(Object.entries(ioMap))
|
|
236
|
+
await new Stream(Object.entries(ioMap),cpCount)
|
|
219
237
|
.map(async ([inPath, outPath]) => {
|
|
220
238
|
SLogger.info(`SFfmpegTool.resampleMP 正在处理:${outPath}`);
|
|
221
239
|
await SFfmpegTool.resample(inPath, outPath, rate);
|