FFmpeg concatenate audio and offset parts between each other

4

2

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?

layabout

Posted 2016-09-01T18:16:30.250

Reputation: 43

Answers

8

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

Gyan

Posted 2016-09-01T18:16:30.250

Reputation: 21 016

What if i want to ceil duration of inputs before concat and trim? – layabout – 2016-09-02T07:37:12.380

See new command. – Gyan – 2016-09-02T08:03:24.077

Thank you for help! Could you please point me where can i read about input labels? I am not quite understand the meaning of all values in brackets. Also why n=5? 3 input files and anullsrc but from where 5th came? – layabout – 2016-09-02T08:20:21.960

See https://ffmpeg.org/ffmpeg-filters.html#Filtergraph-syntax-1

– Gyan – 2016-09-02T08:26:59.153

15 refers to total number of input pads. The anullsrc is fed twice. – Gyan – 2016-09-02T08:27:34.987