Search code examples
node.jsffmpegstreampipefluent-ffmpeg

I need to combine audio and video stream with fluent ffmpeg


I need to take an input stream's audio and another stream's video and combine them with fluent-ffmpeg. I am using nodejs. Also, I need to pipe the output. Both of the inputs have video and audio, but I need to merge a stream's audio only, while doing the same with video on the other stream.

Thank you.


Solution

  • you don't need to use fluent-ffmpeg, if you have ffmpeg installed on your machine you can use child-process.

    const {exec} = require("child_process"); 
    const command = "ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac output.mp4" 
    

    I got this command from how to combine audio and video using ffmpeg

    exec(command, (error, stdout, stderr) => {
      if (error) {
        console.error(`exec error: ${error}`);
        return;
      }
      console.log(`stdout: ${stdout}`);
      console.error(`stderr: ${stderr}`);
    })
    

    ;