3

Good Day,

I would like to know if it is possible to "join" a portion of an mp3 file to another without re-encoding using ffmpeg. I need to prepend an audio mp3 file with silence to ensure it is 60 seconds long.

i.e if my audio file a.mp3 is 40 seconds I need to prepend 20 seconds of silence without re-encoding.

My thoughts on doing this was to have a 60 second long silence mp3 (silence.mp3) at the same CBR and sample rate of my audio (44100 and 40kbps). I then need to "trim" this file and concat/join with the audio file (a.mp3) appropriately.

I have a linux script that computes the required seconds to prepend and I tried using the following filter_complex expression:

ffmpeg -i silence.mp3 -i a.mp3 -filter_complex "[1]adelay=20000[b];[0][b]amix=2" out.mp3

This works however takes too long as it performs re-encoding which takes a long to process. Im looking for a non re encoding solution that can just join the correct sized portion of silence.mp3 to a.mp3. The commands would need to include as a parameter the length of silence that must be used from the overall silence.mp3 file.

Any advise is appreciated.

1 Answer 1

2

Your requirement is to not re-encode and yet that's what your method does.

Let's say you have a silent MP3 of the required duration ready.

Create a text file, list.txt

file silence.mp3
outpoint 20
file main.mp3

and join

ffmpeg -f concat -i list.txt -c copy merged.mp3

I assume the properties of silence.mp3 match the main audio file, in terms of channel count and sampling rate.

5
  • Thanks and Yes, the only method I could get to work requires re-encoding, this is why it is not suitable, apologies if that was not clear. The problem is that I do not have a silence file of the required length. I have a silence file of the total length that must be trimmed as part of the process. Dec 11, 2017 at 10:16
  • Seams to work but my two mp3 input files are CBR and for some reason the output is being picked up as VBR by mediainfo. Dec 11, 2017 at 18:27
  • Tested it here and I get CBR. Show ffprobe readout of all 3 files - silence, main and output.
    – Gyan
    Dec 12, 2017 at 4:32
  • What does outpoint 20 mean? Aug 7, 2023 at 14:36
  • Read the first 20 seconds of silence.mp3
    – Gyan
    Aug 7, 2023 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.