Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mp3 audio merging with -itsoffset using ffmpeg: no effect

I use ffmpeg to merge mp3's in my node server. It works but the offset doesn't have any effect.. I can't see what is wrong then i'd like to get your help :)

var command = "ffmpeg -i "+ input1+ " -itsoffset 40 -i " + input2 +" -filter_complex amerge -c:a libmp3lame -q:a 4 "+ output;

        exec(command, function (error, stdout, stderr) {
            if (stdout) console.log(stdout);
            if (stderr) console.log(stderr);

            if (error) {
                console.log('exec error: ' + error);
                response.statusCode = 404;
                response.end();

            } else {
                // Do something
            }

        });

I tried it also on my computer just in the terminal and it also works with the same problem..

Thanks, Itzhak

like image 691
Itzhak Avatar asked Aug 11 '15 11:08

Itzhak


People also ask

Can I merge two audio together?

When you need to merge several songs into a single composition, the easiest way is to use our Online Audio Joiner application. It works in a browser window and you can join MP3 and other format files without installing the software on your computer. Open Online Audio Joiner website.


1 Answers

Instead of using itsoffset you can append a silent audio to the beginning of the audio. Assume we have three audios to be merged each of 10 sec long. So you can append silent audio as follows.

  • First audio : No silent audio
  • Second audio : Append 10 sec silent audio to the beginning
  • Third audio : Append (10 sec) x 2 silent audio to the beginning

There after you can mix all these audios together. To create a silent audio you can use aevalsrc filter with filter_complex. Following will work for the above example.

ffmpeg -i 0.mp3 -i 1.mp3 -i 2.mp3 -filter_complex 
"aevalsrc=0:d=10[s1];
aevalsrc=0:d=20[s2];
[s1][1:a]concat=n=2:v=0:a=1[ac1];
[s2][2:a]concat=n=2:v=0:a=1[ac2];
[0:a][ac1][ac2]amix=3[aout]" -map [aout] out.mp3

Here [s1] and [s2] are the corresponding silent audio source for second and third input audio streams. Then each silent source will be concatenated with there corresponding audio streams using concat filter. Finally all concatenated audios will be mixed using amix filter.

Else you can try amerge and adelay where doc itself has a clear explanation.

Hope this helps!

like image 125
Chamath Avatar answered Sep 29 '22 01:09

Chamath