Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xts-bit opened this issue Aug 23, 2023 · 0 comments
Open

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

xts-bit opened this issue Aug 23, 2023 · 0 comments

Comments

@xts-bit
Copy link

xts-bit commented Aug 23, 2023

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant