-
Notifications
You must be signed in to change notification settings - Fork 15
/
app.js
28 lines (26 loc) · 1.26 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const exec = require('child_process').exec;
const path = require('path');
const ffmpegPath = require('ffmpeg-static');
function amrToMp3(filepath, outputDir = './src/mp3', outputName) {
return new Promise((resolve, reject) => {
const { ext, name: filename } = path.parse(filepath);
// http://xmqvip.oss-cn-hangzhou.aliyuncs.com/other/images/2018/12/11/1544497148360.1526463056869.amr
if (ext.toLocaleLowerCase() != '.amr') {
console.log(`${filepath} is not a .amr file`);
reject(new Error(`${filepath} is not a .amr file`));
return;
}
const _outputName = outputName || filename;
const cmdStr = `${ffmpegPath} -y -i "${path.normalize(filepath)}" -acodec libmp3lame -ar 24000 -vol 500 -ab 128 "${path.join(outputDir, _outputName + '.mp3')}"`;
exec(cmdStr, (err, stdout, stderr) => {
if (err) {
// console.log('error:' + stderr);
reject(new Error('error:' + stderr));
} else {
resolve(`${outputDir}/${_outputName}.mp3`);
// console.log(`transform to mp3 success! ${path.normalize(filepath)}->${path.join(outputDir, _outputName + '.mp3')}`);
}
});
});
}
module.exports = amrToMp3;