7

How do you join multiple MP3 files into one? "cat" and "mp3wrap" are no good as they produce non standard MP3 files. I know I can use audacity, but when you have 1000's of MP3 files to join into one, it takes too long.

Any suggestions?

oshirowanen
  • 1,730
  • 15
  • 64
  • 80
  • Keep in mind that MP3 is not a lossless format. Concatentating the audio requires re-encoding them. (Although I'm not 100% sure on this. A while ago somebody figured out how to do certain manipulations on jpg images, another lossy format, without having the re-encode them. While the format is lossy, the transforms were lossless.) – Ouroborus Dec 17 '15 at 05:44

5 Answers5

14

You can do this programmatically with ffmpeg's concat demuxer.

First, create a file called inputs.txt with lines like

file '/path/to/input1.mp3'
file '/path/to/input2.mp3'
file '/path/to/input3.mp3'

...etc. Then, run the following ffmpeg command:

ffmpeg -f concat -i inputs.txt -c copy output.mp3

It's possible to generate inputs.txt easily with a bash for loop (this can probably be done with a Windows batch for loop too), assuming you want to merge the files in alphabetical order. This will match every *.mp3 in the working directory, but it can be easily modified:

for f in ./*.mp3; do echo "file '$f'" >> inputs.txt; done
##  Alternatively
printf "file '%s'\n" ./*.mp3 >> inputs.txt

It's also possible to do the entire thing in one line, avoiding the creation of an intermediate list file with process substitution:

ffmpeg -f concat -i <(printf "file '%s'\n" ./*.mp3) -c copy output.mp3
evilsoup
  • 13,426
  • The process substitution example here creates an input list that ffmpeg doesn't like; it barfs for me with [concat @ 0x10201a200] Impossible to open '/dev/fd/./01 Track.mp3'. I fixed it by making the path to the files absolute: ffmpeg -f concat -i <(printf "file '/path/to/files/%s'\n" *.mp3) -c copy output.mp3 – Neil C. Obremski Feb 24 '14 at 21:15
  • +1 However, as per this answer, you can specify the files inline with "concat:file1.mp3|file2.mp3" instead of inputs.txt, and then -f concat is unnecessary. – Sparhawk May 01 '17 at 03:53
  • 1
    @Sparhawk The concat:file1.mp3|file2.mp3 merges the files before sending it to the decoder. It's basically doing cat file1.mp3 file2.mp3 | ffmpeg -i - and thus can lead to decoding errors when the second file differs from the first or the decoder stumbles over header data in the second file. Using -f concat with a list of files decodes each file on its own and uses the stream only. – mbirth Jul 30 '23 at 17:02
  • Nice find @mbirth. There is more information on the ffmpeg page. – Sparhawk Jul 30 '23 at 22:48
7

Use ffmpeg or a similar tool to convert all of your MP3s into a consistent format, e.g.

ffmpeg -i originalA.mp3 -f mp3 -ab 128kb -ar 44100 -ac 2 intermediateA.mp3 ffmpeg -i originalB.mp3 -f mp3 -ab 128kb -ar 44100 -ac 2 intermediateB.mp3

Then, at runtime, concat your files together:

cat intermediateA.mp3 intermediateB.mp3 > output.mp3

Finally, run them through the tool MP3Val to fix any stream errors without forcing a full re-encode:

mp3val output.mp3 -f -nb
(source)

Nifle
  • 34,446
1

You can use the free mp3cat:

mp3cat indir - > outfile.mp3
niutech
  • 1,096
  • This doesn't currently work unless you've used mp3cat to make a recording in the correct format: https://tomclegg.ca/mp3cat – Louis Jul 15 '18 at 16:50
0

Freemake Audio Converter is great:

http://www.freemake.com/free_audio_converter/

Converts and/or joins audio files.

After downloading and installing Freemake (be careful not to install Ad-Aware Web Companion, TuneUp Utilities, Opera, or set Yahoo! as your homepage), launch the program. Click the +Audio button at the top left of the window, and select the files you want to merge/convert.

Click the Join files "switch" at the top right of the window.

Select the audio type you want (probably FLAC for lossless)

It will let you customize your audio settings and output folder. Once you're ready click convert.

0

Goldwave has some batch processing capabilities, though it's shareware, not freeware.

Force Flow
  • 4,116
  • 8
  • 29
  • 41