The Computer Oracle

Add silence to the end of an MP3

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Music Box Puzzles

--

Chapters
00:00 Add Silence To The End Of An Mp3
00:43 Answer 1 Score 18
01:48 Accepted Answer Score 11
02:13 Thank you

--

Full question
https://superuser.com/questions/536547/a...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #audio #ffmpeg #mp3 #mencoder

#avk47



ANSWER 1

Score 18


With ffmpeg, you can use the aevalsrc filter to generate silence, and then in a second command use the concat protocol to combine them losslessly:

ffmpeg -filter_complex aevalsrc=0 -t 10 10SecSilence.mp3
ffmpeg -i "concat:input.mp3|10SecSilence.mp3" -c copy output.mp3

You can control the length of silence by altering -t 10 to whatever time in seconds you would prefer. Of course, you only need to generate the silence once, then you can keep the file around and use it to pad each of the files you want to. You may also want to look up the concat demuxer - it's slightly more processor-intensive, but you may find it easier to drop into a shell script.

If you want to do it in a single command, you can use the concat filter - this will require you to re-encode your audio (since filtergraphs are incompatible with -codec copy), so the option above will probably be best for you. But this may be useful for anyone working with raw PCM, looking to add silence to the end before encoding the audio:

ffmpeg -i input.mp3 \
-filter_complex 'aevalsrc=0::d=10[silence];[0:a][silence]concat=n=2:v=0:a=1[out]' \
-map [out] -c:a libmp3lame -q:a 2 output.mp3

Control the length of the silence by changing d=10 to whatever time (in seconds) you want. If you use this method, you may find this FFmpeg MP3 encoding guide useful.




ACCEPTED ANSWER

Score 11


You can do so easily with SoX's pad argument and the following syntax:

sox <oldfile> <newfile> pad <silence at beginning of file> <silence at end of file>

Example:

sox mp3.mp3 mp3withsilence.mp3 pad 0 1

Those silences are in seconds. (Other usages are possible using a different syntax, so as to insert those silences at specific positions. See the SoX documentation for more.)