3

I am trying to add audio on top video using ffmpeg

ffmpeg -i sample.mp4 -i sample.mp3 -c copy -map 0:v:0 -map 1:a:0 output.mp4

Above code works in my terminal but I would like to use this via ffmpeg node wrapper fluent-ffmpeg

This code is not working and it also not throwing any error

ffmpeg()
    .input('DATA/sample.mp4')
    .input('DATA/sample.mp3')
    .videoCodec('copy')
    .outputOptions(['-map 0:v:0', '-map 1:a:0'])
    // .outputOption('-map 1:a:0')
    .save('node.mp4') 
1
  • I can't reproduce your issue. Maybe try to add an error handler .on('error', function (err, stdout, stderr) { console.log(err.message); }); to log possible error. Commented Jun 25, 2019 at 9:30

3 Answers 3

3

new FFmpeg()
    .addInput(video)
    .addInput(audio)
    .saveToFile(destination, "./temp");

This worked for me having a video with no audio.

Sign up to request clarification or add additional context in comments.

Comments

2

TO pass the output in other function:-

ffmpeg()
  .addInput(videoInput) //your video file input path
  .addInput(audioInput) //your audio file input path
  .output(output) //your output path
  .outputOptions(['-map 0:v', '-map 1:a', '-c:v copy', '-shortest'])
  .on('start', (command) => {
    console.log('TCL: command -> command', command)
  })
  .on('error', (error) => console.log("errrrr",error))
  .on('end',()=>console.log("Completed"))
  .run()  

This command will also adjust if you have a video duration less than the audio duration, (-shortest) this flag will pick the file with less duration

TO save the file:-

 ffmpeg()
  .addInput(videoInput) //your video file input path
  .addInput(audioInput) //your audio file input path
  .output(output) //your output path
  .outputOptions(['-map 0:v', '-map 1:a', '-c:v copy', '-shortest'])
  .saveToFile(destination, "./temp")

Comments

0

MergeAdd and mergeToFile actually have misleading names. They are used to concatenate videos into a single video file.

You should use addInput to add your audio file and then use saveToFile to save the merged output.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.