You’d think it would be very easy to combine multiple MP3 files into one, while preserving all the ID3 tag metadata and without re-encoding the audio (which is lossy). Well, it actually isn’t that hard at all.
There is a handy command-line utility for combining MP3 files, mp3wrap. Unfortunately, it doesn’t correct the audio duration tags/headers (so iTunes/iPod will only see the first part of the file), and it clobbers your ID3 tags with its own (so that the file can later be unmerged with mp3split — this is a “feature”).
There’s also the easy cat solution:
cat 1.mp3 2.mp3 > all.mp3
But it doesn’t correct the duration, either. Maybe you don’t care about ID3 tags, and your playback software doesn’t care about a wrong duration header (some ignore it)? But if you want to get your MP3 files right or you’re using something like iTunes, here is how it is done.
The following combines 1.mp3, 2.mp3 and 3.mp3 into all.mp3, and copies ID3 tags from 1.mp3:
mp3wrap tmp.mp3 1.mp3 2.mp3 3.mp3 ffmpeg -i tmp_MP3WRAP.mp3 -acodec copy all.mp3 && rm tmp_MP3WRAP.mp3 id3cp 1.mp3 all.mp3
Here’s what’s happening:
If you have problems with ffmpeg, a little program called vbrfix can be used instead:
mp3wrap tmp.mp3 1.mp3 2.mp3 3.mp3 vbrfix -ri1 -ri2 -lameinfo tmp_MP3WRAP.mp3 all.mp3 && rm tmp_MP3WRAP.mp3 id3cp 1.mp3 all.mp3
lameinfo is specified in the command because Lame had been used for the encoding of the original files, before using mp3wrap to combine them.
You can also substitute the first line of code for this, in order to wrap all files in the folder together:
mp3wrap tmp.mp3 *.mp3
If you have a lot of files to merge, you might run into the shell expansion limit by using a wildcard. If so, us the xargs trick:
$ find -name \*mp3|xargs mp3wrap all.mp3
There is yet another way, without going through mp3wrap:
cat file list... | ffmpeg -f mp3 -i -acodec copy outfile.mp3
And then the id3 copy command.