我正在使用fluent-ffmpeg和libmp3lame(https://github.com/fluent-ffmpeg/node-fluent-ffmpeg)将文件上传转换为mp3,最终上传至S3。文件在转换过程中间歇性损坏(我怀疑)。
我无法自己重现这种情况。同样,我无法向活动用户请求原始的源音频文件,因此测试很困难。
当我在本地下载损坏的mp3进行检查时,我发现它们无法在Finder或iTunes中播放。有趣的是,我可以在Audacity中打开,播放和转换它们。
我已经运行了命令行工具 mp3val ,它会输出以下结果:
Analyzing file "5de58556d770a800168f86f2-bad.mp3"...
WARNING: "~/Downloads/5de58556d770a800168f86f2-bad.mp3" (offset 0xa): MPEG stream error, resynchronized successfully
WARNING: "~/Downloads/5de58556d770a800168f86f2-bad.mp3": VBR detected, but no VBR header is present. Seeking may not work properly.
INFO: "~/Downloads/5de58556d770a800168f86f2-bad.mp3": 3749 MPEG frames (MPEG 1 Layer III), +ID3v2, no VBR header
Done!
我的转换代码如下:
ffmpeg()
.input(tempUploadPath)
.format('mp3')
.audioCodec('libmp3lame')
.audioQuality(0)
.pipe(uploadFromStream(audioPath))
.on('close', () => logger.info('passThrough-close'))
.on('finish', () => {
removeTempFile(tempUploadPath)
.then(() => {
logger.info(`Removed temp file ${tempUploadPath}`);
resolve(audioPath);
})
.catch((err) => {
logger.error('Could not remove template file.', err);
resolve(audioPath);
});
})
.on('error', (err) => {
logger.error(`Could not convert audio. ${JSON.stringify(err)}`);
removeTempFile(tempUploadPath)
.then(() => reject())
.catch((rmErr) => reject(rmErr));
});
这里是一个到损坏的输出文件之一的链接:
https://drive.google.com/open?id=16khdEogaPXeNEM9MuChd5DsNHC3NY0DZ