Using the concat demuxer (add silence to beginning and/or end)
Use the concat demuxer if you want to avoid re-encoding the main segment. This methods works for adding silence to the beginning or end (or both).
Use the anullsrc audio source filter in to create the silent audio. You'll need to match the format, channel layout, and sample rate of the main audio file. Example to make a 5.1 channel, 48000 Hz sample rate, 1 second silent AC3 audio file (as this was what the format in the question):
ffmpeg -f lavfi -i anullsrc=channel_layout=5.1:sample_rate=48000 -t 1 silence.ac3
Now make a text file named input.txt
that lists the files to be concatenated:
file 'silent.ac3'
file 'main.ac3'
If you want the silence at the end instead just switch the order of the files in input.txt
.
Now you can concatenate the files using the concat demuxer:
ffmpeg -f concat -i input.txt -codec copy output.ac3
Using the concat filter (add silence to the beginning and/or end)
Use the concat filter if you want to do everything in one command, or if you want to output to a different format than the input (since this method re-encodes anyway). This methods works for adding silence to the beginning or end or both.
Example to add 1 second of silence to the beginning of a stereo, 44100 Hz sample rate input:
ffmpeg -f lavfi -t 1 -i anullsrc=channel_layout=stereo:sample_rate=44100 -i audio.oga -filter_complex "[0:a][1:a]concat=n=2:v=0:a=1" output.m4a
Filtering will result in re-encoding while the concat demuxer will not.
In anullsrc it is recommended to match the channel layout and sample rate of the input.
If you want to add silence to the end instead just switch the order of the inputs given to the concat filter: [1:a][0:a]concat=n=2:v=0:a=1
.
Using the adelay filter (add silence to beginning)
Use the adelay audio filter if you want to do everything in one command, or if you want to output to a different format than the input (since this method re-encodes anyway). This only works to add silence to the beginning of a file.
This example will add 1 second of silence to the beginning of a stereo input:
ffmpeg -i input.flac -af "adelay=1000|1000" output.opus
- Filtering will result in re-encoding while the concat demuxer will not.
- Value is in milliseconds. Users of recent versions (current git master or anything newer than FFmpeg 4.1) can instead use
1s
for one second.
- Each channel needs its own delay. For example, a mono input would use
adelay=1000
, while a 5.1 input would use adelay=1000|1000|1000|1000|1000|1000
.
Using the apad filter (add silence to the end)
Use the apad audio filter if you want to do everything in one command, or if you want to output to a different format than the input (since this method re-encodes anyway). This only works to add silence to the end of a file.
This example will add 1 second of silence to the end:
ffmpeg -i input.wav -af "apad=pad_dur=1" output.m4a
Filtering will result in re-encoding while the concat demuxer will not.
The pad_dur
option was added after the release of FFmpeg 4.1, so you will need to use a recent build from the git master branch or wait for FFmpeg 4.2.
ffmpeg will append or join same codec same rate things? – Psycogeek – 2013-04-06T19:14:54.337
I suppose... @Psycogeek – Makaveli84 – 2013-04-06T19:21:32.260
And is it capable of generating a silent audio file of the exact same codec rate and channel? http://ffmpeg.org/ffmpeg-filters.html#Examples-34 ? Myself I use GUI methods, but doing what your asking should be fairly easy and very fast, as long as the parameters are all the same. Here is where it is shown adding it to a Mov. http://stackoverflow.com/questions/12368151/adding-silent-audio-to-mov-in-ffmpeg in the answers
– Psycogeek – 2013-04-06T20:47:10.177Use Ardour to add anything you want. If you want effects as well download the Calf plugins.. – dashboard – 2013-04-06T21:25:31.857