FFmpeg - Concenating audio files with spacing

Solution 1:

FFmpeg is capable of handling this. What you need to use is filter_complex with filter chaining. You can create a silent audio with aevalsrc. To create a 5 sec silent audio,

aevalsrc=0:d=5

So the following command will work for you.

ffmpeg -i input_audio_1 -i input_audio_2 -i input_audio_3 -filter_complex "
aevalsrc=0:d=10[s1];
aevalsrc=0:d=15[s2];
aevalsrc=0:d=20[s3];
[s2][1:a]concat=n=2:v=0:a=1[ac1];
[s3][2:a]concat=n=2:v=0:a=1[ac2];
[0:a][s1][ac1][ac2]amix=inputs=4[aout]" -map [aout] output_audio

Here I assumed each audio is having a length of 5 sec and re-encoding is optional like,

-c:a libmp3lame -ac 2 -b:a 128k

As amix cause overlapping of audios I have appended a silent audio to each of the input audio. You can also try amerge and adelay where doc itself has a clear explanation.

Hope this helps you!

Solution 2:

Here is audio concat example:

ffmpeg -y -f s16be -i /dev/zero -af "[in]anullsink;amovie=1.wav[a1];amovie=silence.wav[a2];amovie=2.wav[a3];amovie=4.wav[a4];[a1][a2][a3][a4]concat=n=4:v=0:a=1[out]" -shortest -t 12 output.wav

Notice couple of things you need to know here:

  1. I started with a clean input /dev/zero, it's nice, yet, can there is probably a nicer way of doing it.
  2. You need to know the total duration of the clip before making it (t=12)
  3. I premade the silence.wav file. You can use filters such as anullsrc (see nb_samples on the documentation) or other but this is quite pain-in-the-ass if you ask me.
  4. Sometimes, by using this approach, FFmpeg does not know when to stop, and yet, it will not create empty silence track since the -shortest param is applied.