Reputation: 11
I'm trying to convert an mp3 file stereo to 2 mp3 mono node's fluent-ffmpeg module. 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.
Upvotes: 1
Views: 1975
Reputation: 1
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
Of course you can use .wav or .mp3 too.
Hope it helps!
Upvotes: 0
Reputation: 173
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
Upvotes: 1