How to make a video overlay, preserving the overlay sound?

32 Views Asked by At

I'm using fluent-ffmpeg library for NodeJS, trying to overlay the video, but also need to set the audio from the overlay to the main video

ffmpeg()
.input(mainVideo)
.input(pipVideo)
.complexFilter([
 {
  'filter': 'overlay', 
  'options': {'x':0, 'y':0, 'eof_action': 'pass'},
  'inputs':['0:v', '1:v'],
  'outputs': 'output'
 }
], 'output')
.saveToFile(outputFile) //output filepath
.on('end', function (err, stdout, stderr) { //on the end of video generation
  console.log('done')
})
.on('error', function(err) {
  throw new Error(err.message)
})

1

There are 1 best solutions below

0
Nikita Lvov On

After dozens of different combinations tried I have find out that it loosing other inputs if you are using only video filters. I have added a simple filter to set the volume of audio stream to 100% from original (dummy filter) So the working solution:

    ffmpeg()
    .input(mainVideo)
    .input(pipVideo)
    .complexFilter([
     {
      'filter': 'overlay', 
      'options': {'x':0, 'y':0, 'eof_action': 'pass'},
      'inputs':['0:v', '1:v'],
      'outputs': 'output'
     },
     { 'filter': 'volume',
       'options': { 'volume': 1 }, 'inputs': '1:a',
       'outputs': 'audio' 
     }
    ])
    .outputOptions(['-map', '[output]', '-map', '[audio]' ])
    .saveToFile(outputFile) //output filepath
    .on('end', function (err, stdout, stderr) { //on the end of video generation
      console.log('done')
    })
    .on('error', function(err) {
      throw new Error(err.message)
    })