1

Hey I'm currently working on a node.js program that will convert a audio track to the .wav format. But I am having a hard time splitting the newly created wav file into 2 separate wav files Splitting the audio tracks from the Left and the Right audio channel.

Trying to automate this structure

FileName.wav (Stereo)
FileName_left.wav (Left Channel Mono)
FileName_right.wav (Right Channel Mono)

Ive tried many different methods, ended up with this function which is utilizing fluent-ffmpeg But this current implementation is throwing an error in my try catch block

"Error occurred while processing the audio: No output specified"

Does anyone have any idea why this error is throwing? I tried adding .output(${outputLeft}) to no avail, I also tried adding a path like "./" infront of left.wav in the -map. I cant solve how to provide an output

const ffmpeg = require("fluent-ffmpeg");
async function splitChannels(infile) {
    console.log(`Stereo To Mono Conversion Started!`);
    const outputLeft = infile.replace(".wav", "_left.wav");
    const outputRight = infile.replace(".wav", "_right.wav");

    try {
        // Split the left channel
        await new Promise((resolve, reject) => {
            ffmpeg(infile)
                .outputOptions([
                    '-filter_complex "[0:a:{k}]channelsplit=channel_layout=stereo[left][right]"',
                    '-c:a pcm_s16le',
                    `-map "[left]" left.wav`,
                    `-map "[right]" right.wav`,
                ])
                .on('error', (err) => {
                    console.log(`An error occurred while splitting the left channel: ${err.message}`);
                    reject(err);
                })
                .on('end', () => {
                    console.log('Channels splitted!');
                    resolve();
                })
                .run();
        });
    } catch (err) {
        console.error('Error occurred while processing the audio:', err.message);
    }
}
Rishi
  • 13
  • 3

0 Answers0