@zwa73/utils 1.0.13 → 1.0.14
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.d.ts +13 -0
- package/dist/UtilFfmpegTools.js +31 -0
- package/package.json +1 -1
- package/src/UtilFfmpegTools.ts +32 -0
|
@@ -42,6 +42,11 @@ declare class SFfmpegTool {
|
|
|
42
42
|
* @param {number} silence - 保留静音时长
|
|
43
43
|
*/
|
|
44
44
|
static trimSilence(inputWavPath: string, outputWavPath: string, threshold?: number, silence?: number): Promise<boolean>;
|
|
45
|
+
/**重采样
|
|
46
|
+
* @param {string} inputWavPath - 输入wav文件路径
|
|
47
|
+
* @param {string} outputWavPath - 输出wav文件路径
|
|
48
|
+
*/
|
|
49
|
+
static resample(inputWavPath: string, outputWavPath: string, rate?: number): Promise<boolean>;
|
|
45
50
|
/**wav转ogg多线程
|
|
46
51
|
* @param {IOMap} iomap - 输入输出路径映射
|
|
47
52
|
* @param {number} quality - 质量
|
|
@@ -74,6 +79,14 @@ declare class SFfmpegTool {
|
|
|
74
79
|
/**删除静音子线程
|
|
75
80
|
*/
|
|
76
81
|
private static trimSilenceCP;
|
|
82
|
+
/**重采样多线程
|
|
83
|
+
* @param {IOMap} iomap - 输入输出路径映射
|
|
84
|
+
* @param {number} rate - 采样率
|
|
85
|
+
* @param {number} cpCount - 并发数
|
|
86
|
+
*/
|
|
87
|
+
static resampleMP(ioMap: IOMap, rate?: number, cpCount?: number): Promise<void>;
|
|
88
|
+
/**重采样子线程*/
|
|
89
|
+
private static resampleCP;
|
|
77
90
|
}
|
|
78
91
|
export default SFfmpegTool;
|
|
79
92
|
export { SFfmpegTool };
|
package/dist/UtilFfmpegTools.js
CHANGED
|
@@ -109,6 +109,19 @@ class SFfmpegTool {
|
|
|
109
109
|
.on("error", (err) => reject(err));
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
+
/**重采样
|
|
113
|
+
* @param {string} inputWavPath - 输入wav文件路径
|
|
114
|
+
* @param {string} outputWavPath - 输出wav文件路径
|
|
115
|
+
*/
|
|
116
|
+
static async resample(inputWavPath, outputWavPath, rate = 22050) {
|
|
117
|
+
return new Promise((resolve, reject) => {
|
|
118
|
+
fluentFfmpeg(inputWavPath)
|
|
119
|
+
.audioFrequency(rate)
|
|
120
|
+
.save(outputWavPath)
|
|
121
|
+
.on("end", () => resolve(true))
|
|
122
|
+
.on("error", (err) => reject(err));
|
|
123
|
+
});
|
|
124
|
+
}
|
|
112
125
|
//多线程处理
|
|
113
126
|
/**wav转ogg多线程
|
|
114
127
|
* @param {IOMap} iomap - 输入输出路径映射
|
|
@@ -172,6 +185,24 @@ class SFfmpegTool {
|
|
|
172
185
|
await SFfmpegTool.trimSilence(inPath, outpath, threshold, silence);
|
|
173
186
|
}
|
|
174
187
|
}
|
|
188
|
+
/**重采样多线程
|
|
189
|
+
* @param {IOMap} iomap - 输入输出路径映射
|
|
190
|
+
* @param {number} rate - 采样率
|
|
191
|
+
* @param {number} cpCount - 并发数
|
|
192
|
+
*/
|
|
193
|
+
static async resampleMP(ioMap, rate = 22050, cpCount = 16) {
|
|
194
|
+
let cpList = MPClip(ioMap, cpCount);
|
|
195
|
+
for (let cpMap of cpList)
|
|
196
|
+
SFfmpegTool.resampleCP(cpMap, rate);
|
|
197
|
+
}
|
|
198
|
+
/**重采样子线程*/
|
|
199
|
+
static async resampleCP(ioMap, rate = 22050) {
|
|
200
|
+
for (let inPath in ioMap) {
|
|
201
|
+
let outpath = ioMap[inPath];
|
|
202
|
+
console.log("正在处理:" + outpath);
|
|
203
|
+
await SFfmpegTool.resample(inPath, outpath, rate);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
175
206
|
}
|
|
176
207
|
exports.SFfmpegTool = SFfmpegTool;
|
|
177
208
|
/**多线程任务分割器
|
package/package.json
CHANGED
package/src/UtilFfmpegTools.ts
CHANGED
|
@@ -138,6 +138,20 @@ class SFfmpegTool {
|
|
|
138
138
|
.on("error", (err) => reject(err));
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
|
+
/**重采样
|
|
142
|
+
* @param {string} inputWavPath - 输入wav文件路径
|
|
143
|
+
* @param {string} outputWavPath - 输出wav文件路径
|
|
144
|
+
*/
|
|
145
|
+
static async resample(inputWavPath: string, outputWavPath: string, rate: number = 22050): Promise<boolean> {
|
|
146
|
+
return new Promise((resolve, reject) => {
|
|
147
|
+
fluentFfmpeg(inputWavPath)
|
|
148
|
+
.audioFrequency(rate)
|
|
149
|
+
.save(outputWavPath)
|
|
150
|
+
.on("end", () => resolve(true))
|
|
151
|
+
.on("error", (err) => reject(err));
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
141
155
|
//多线程处理
|
|
142
156
|
/**wav转ogg多线程
|
|
143
157
|
* @param {IOMap} iomap - 输入输出路径映射
|
|
@@ -212,6 +226,24 @@ class SFfmpegTool {
|
|
|
212
226
|
await SFfmpegTool.trimSilence(inPath, outpath, threshold, silence);
|
|
213
227
|
}
|
|
214
228
|
}
|
|
229
|
+
|
|
230
|
+
/**重采样多线程
|
|
231
|
+
* @param {IOMap} iomap - 输入输出路径映射
|
|
232
|
+
* @param {number} rate - 采样率
|
|
233
|
+
* @param {number} cpCount - 并发数
|
|
234
|
+
*/
|
|
235
|
+
static async resampleMP(ioMap: IOMap, rate: number = 22050, cpCount: number = 16) {
|
|
236
|
+
let cpList = MPClip(ioMap, cpCount);
|
|
237
|
+
for (let cpMap of cpList) SFfmpegTool.resampleCP(cpMap, rate);
|
|
238
|
+
}
|
|
239
|
+
/**重采样子线程*/
|
|
240
|
+
private static async resampleCP(ioMap: IOMap, rate: number = 22050) {
|
|
241
|
+
for (let inPath in ioMap) {
|
|
242
|
+
let outpath = ioMap[inPath];
|
|
243
|
+
console.log("正在处理:" + outpath);
|
|
244
|
+
await SFfmpegTool.resample(inPath, outpath, rate);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
215
247
|
}
|
|
216
248
|
|
|
217
249
|
/**多线程任务分割器
|