FFmpeg concatenate audio and offset parts between each other

I figured out how I can concatenate multiple audio files with complex filter, but struggling with offsetting audio in result file. Say, I want to add a gap of 1 seconds silence between each concatenate file. Is it possible to do with FFmpeg?


Solution 1:

Generate a null audio stream and insert that with a trim.

Let's say you have three audio files and you want gaps of 1 and 3 seconds between them respectively, then you would use

ffmpeg -i 1.mp3 -i 2.mp3 -i 3.mp3 -f lavfi -i anullsrc -filter_complex \
       "[3]atrim=duration=1[g1];[3]atrim=duration=3[g2];
        [0][g1][1][g2][2]concat=n=5:v=0:a=1"  out.mp3

If you need to trim the inputs as well,

ffmpeg -i 1.mp3 -i 2.mp3 -i 3.mp3 -f lavfi -i anullsrc -filter_complex \
       "[0]atrim=duration=20[t0];[1]atrim=duration=120[t1];[2]atrim=duration=45[t2];
        [3]atrim=duration=1[g1];[3]atrim=duration=3[g2];
        [t0][g1][t1][g2][t2]concat=n=5:v=0:a=1"  out.mp3