node-ffmpeg-installer icon indicating copy to clipboard operation
node-ffmpeg-installer copied to clipboard

ffmpeg removes audio from video instead of add audio to the video

Open xts-bit opened this issue 10 months ago • 0 comments

trying to add background audio to a video in nodejs express, but instead of adding audio to the video it removes the audio from video how to fix?

import { path as ffmpegPath } from '@ffmpeg-installer/ffmpeg';
import ffmpeg from 'fluent-ffmpeg';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import path from 'path';

ffmpeg.setFfmpegPath(ffmpegPath);

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const video = path.resolve(__dirname, 'video3.mp4');
const audio = path.resolve(__dirname, 'video5.mp4');
const destination = path.resolve(__dirname, 'output.mp4');

setTimeout(() => {
  ffmpeg()
    .input(video)
    .input(audio)
    .complexFilter([
      {
        filter: 'amix', options: { inputs: 2, duration: 'longest' }
      }
    ])
    .on('end', async function (output) {
      console.log(output, 'files have been merged and saved.')
    })
    .saveToFile(destination)
}, 3000);

xts-bit avatar Aug 23 '23 09:08 xts-bit