I have a mp4 video of 31sec with no background Audio. Now I want to add 2 background audios(mp3) on this video i.e. - [0-15s] 1st Audio then [15-31s] 2nd Audio using fluent-ffmpeg. I have been searching a lot for this scenario but not getting right solution. Any lead in this much much appreciated.
const merge = (videoFileName = 'video.mp4') => {
try {
const start1=0, endInSec1=15, start2=16, endInSec2=16;
const audio1 = 'https://d3ezyqzf8yqw4x.cloudfront.net/279499-audio-1639134010235.mp3';
const audio2 = 'https://d3ezyqzf8yqw4x.cloudfront.net/279499-audio-1639130519365.mp3';
ffmpeg()
.input(directory + '/input/' + videoFileName)
.input(audio1)
.setStartTime(start1)
.setDuration(endInSec1)
.input(audio2)
.setStartTime(start2)
.setDuration(endInSec2)
.on('end', () => {
console.log("Done bro")
})
.on('error', (err) => {
console.log(":::::: Getting error at mergeVideo() : ", err);
})
.saveToFile(directory + '/out/' + 'output.mp4')
} catch (err) {
console.log("Getting error :::::::::: ");
}
}
Then I'm calling this method below
(() => {
merge();
})()
When I execute the above code getting an output.mp4 file which has no audio and the length of video is [0-15]sec.
Could someone please help me with it?