0

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?

  • Try it first on the Terminal, if it works there adapt your `ffmpeg` command to your script – Marc Jan 10 '22 at 14:43
  • Thanks for suggestions, Yes, I have installed ffmpeg core into my system and I been trying same in terminal but still did not get a single command which could perform my task. Now I'm searching one liner command which could do my task then I will convert that command into fluent-ffmpeg query. If anyone knows command for the above query please let here know. It will help many of us. Thanks!! – Ajeet Kumar Maurya Jan 11 '22 at 06:31

0 Answers0