[英]fluent-ffmpeg: how split stereo mp3 to 2 mono file in node.js?
I'm trying to convert an mp3 file stereo to 2 mp3 mono node's fluent-ffmpeg module.我正在尝试将 mp3 文件立体声转换为 2 mp3 单声道节点的fluent-ffmpeg模块。 This is example for terminal:这是终端示例:
ffmpeg -i stereo.wav -map_channel 0.0.0 left.wav -map_channel 0.0.1 right.wav
I need the implementation of this functionality in fluent-ffmpeg .我需要在fluent-ffmpeg 中实现这个功能。
not sure about the mono, but if you want to split a file, you can use不确定单声道,但如果你想分割一个文件,你可以使用
ffmpeg(local_dir).outputOptions('-f segment')
.outputOptions(`-segment_time ${length of each mp3 }`).save(`${save_dir}out%03d.mp3`)
hope it can help you希望它可以帮助你
It's been a long time since you've asked it, but maybe it can help to others.你问它已经很长时间了,但也许它可以帮助其他人。
The way I found to solve the same problem was opening the file twice and save each channel separated.我发现解决同样问题的方法是打开文件两次并将每个通道分开保存。
const splitChannels = (file, leftChannelName, rightChannelName) =>{
ffmpeg(file)
.outputOption('-map_channel 0.0.0')
.save(leftChannelName)
.on('error', (err) => {
console.log(`An error occurred: ${err.message}`);
})
.on('end', () => {
console.log('Left channel splitted!');
})
ffmpeg(pathToAudio)
.outputOption('-map_channel 0.0.1')
.save(rightChannelName)
.on('error', (err) => {
console.log(`An error occurred: ${err.message}`);
})
.on('end', () => {
console.log('Right channel splitted!');
})
}
splitChannels('./files/test.wav', 'left.wav', 'right.wav');
More info: https://trac.ffmpeg.org/wiki/AudioChannelManipulation更多信息: https : //trac.ffmpeg.org/wiki/AudioChannelManipulation
Of course you can use .wav or .mp3 too.当然,您也可以使用 .wav 或 .mp3。
Hope it helps!希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.