68

I've got many, many mp3 files that I would like to merge into a single file. I've used the command line method

copy /b 1.mp3+2.mp3 3.mp3

but it's a pain when there's a lot of them and their namings are inconsistent. The time never seems to come out right either.

raven
  • 18,004
  • 16
  • 81
  • 112
Dan Williams
  • 4,910
  • 11
  • 37
  • 46
  • 2
    Ah using the dos binary merging tool for music files is not advisable at all. Music files come with headers that indicate information about the music. That's the cause of the inconsistencies. – Chibueze Opata Dec 28 '12 at 15:14
  • You can do this simply using the following command: `rm -f all.mp3 && cat *.mp3 > temp_file.dat; sleep 1; mv temp_file.dat all.mp3 && echo && echo "Your mp3 files have been merged into one file - all.mp3" && echo`. If you find it hard to read here, you can grab it [from this link](https://gist.github.com/bradparks/12444ff9926824decbc9) – Brad Parks Dec 04 '15 at 03:38
  • 1
    If you don't care about re-encoding, you can use something like `ffmpeg -f concat -i <(printf "file '%s'\n" /absolute/path/to/*.mp3) -aq 2 concatenated.mp3`. `-aq 2` corresponds to `-V2` in `lame`. – nisetama May 03 '16 at 11:58
  • @nisetama most people would probably care about re-encoding though as it would needlessly reduce the quality... – Ohad Schneider Nov 14 '17 at 12:19
  • 2
    Since this question is closed, I'll put this here for quick reference: https://github.com/dmulholland/mp3cat - supports both VBR and id3, works great for me so far. – Ohad Schneider Nov 14 '17 at 16:13
  • mp3cat crashes if bitrates of input files are different. Message: Multiple bitrates detected. Adding VBR header. panic: runtime error: index out of range – mosh Feb 25 '18 at 16:58

12 Answers12

63

David's answer is correct that just concatenating the files will leave ID3 tags scattered inside (although this doesn't normally affect playback, so you can do "copy /b" or on UNIX "cat a.mp3 b.mp3 > combined.mp3" in a pinch).

However, mp3wrap isn't exactly the right tool to just combine multiple MP3s into one "clean" file. Rather than using ID3, it actually inserts its own custom data format in amongst the MP3 frames (the "wrap" part), which causes issues with playback, particularly on iTunes and iPods. Although the file will play back fine if you just let them run from start to finish (because players will skip these is arbitrary non-MPEG bytes) the file duration and bitrate will be reported incorrectly, which breaks seeking. Also, mp3wrap will wipe out all your ID3 metadata, including cover art, and fail to update the VBR header with the correct file length.

mp3cat on its own will produce a good concatenated data file (so, better than mp3wrap), but it also strips ID3 tags and fails to update the VBR header with the correct length of the joined file.

Here's a good explanation of these issues and method (two actually) to combine MP3 files and produce a "clean" final result with original metadata intact -- it's command-line so works on Mac/Linux/BSD etc. It uses:

  • mp3cat to combine the MPEG data frames only into a continuous file, then
  • id3cp to copy all metadata over to the combined file, and finally
  • VBRFix to update the VBR header.

For a Windows GUI tool, take a look at Merge MP3 -- it takes care of everything. (VBRFix also comes in GUI form, but it doesn't do the joining.)

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
joelhardi
  • 11,039
  • 3
  • 32
  • 38
  • 1
    actually `vbrfix` will drop the non-data frames by itself, so the call to `mp3cat` is not required :) (and, since `vbrfix` will also use only the last ID3v1 tag, perhaps `id3cp` is not required either -- i'm still using it in my wrapper script, though...) – simon May 23 '11 at 11:16
  • 1
    True enough ... although it's not like you can skip the mp3cat step, you still have to concatenate the files somehow. I prefer to use id3cp for the reason you mention -- if you just cat together a bunch of files, because ID3v2 is a header and ID3v1 is a footer, depending on which or both of these tags exist, the result of just doing cat and VBRFix would be unpredictable (does it use the ID3 tag of the first mp3, or the last?). Also, VBRFix is the dodgiest of these utilities, so I prefer to give it the least work to do. :) – joelhardi May 23 '11 at 18:48
  • 1
    fair enough -- on my debian system mp3cat was the only thing I had to compile from source, so that's one reason why I just `cat` the files and then run `vbrfix -ri1 -ri2 -always` over the result :) – simon May 24 '11 at 11:08
  • 1
    Here is a command for taking a list of files from a textfile, one per line to run mp3cat with. `cat playlist.txt | { while read fn ; do cat "$fn"; done; } | mp3cat - ->out.mp3` – Colin D Apr 02 '16 at 01:51
  • 1
    Please note there are two tools named *mp3cat*: [MP3cat by Darren Mulholland](http://mulholland.xyz/dev/mp3cat/) and [mp3cat by Tom Clegg](https://tomclegg.ca/mp3cat). – Quinn Comendant Jul 28 '17 at 21:51
  • @QuinnComendant great find, the one by Darren Mulholland supports both VBR and ID3 tagging. It is also quite recent (last commit just a few months ago) – Ohad Schneider Nov 14 '17 at 16:12
  • FYI y'all: The copy of `mp3cat` available via Homebrew (`brew install mp2cat`) is [Tom Clegg's](https://tomclegg.ca/mp3cat). – Quinn Comendant Dec 25 '17 at 10:26
  • 7 years has passed. What tools do u think r good now? I have been trying with ffmpeg and it seems to be doing ok. I checked the metadata using exiftool. How do u verify that the tool doesn't mess up the audios' metadata? – Jun Aug 31 '18 at 21:38
52

As Thomas Owens pointed out, simply concatenating the files will leave multiple ID3 headers scattered throughout the resulting concatenated file - so the time/bitrate info will be wildly wrong.

You're going to need to use a tool which can combine the audio data for you.

mp3wrap would be ideal for this - it's designed to join together MP3 files, without needing to decode + re-encode the data (which would result in a loss of audio quality) and will also deal with the ID3 tags intelligently.

The resulting file can also be split back into its component parts using the mp3splt tool - mp3wrap adds information to the IDv3 comment to allow this.

David Precious
  • 6,544
  • 1
  • 24
  • 31
  • What I really wanted was a GUI to reorder them and output them as one file with the correct headers. I ended up renaming the files to get them in the correct order and used mp3wrap FullDisk.mp3 *.mp3 – Dan Williams Sep 15 '08 at 14:40
  • 2
    Actually, I tried mp3wrap at first and was disappointed by result. Output mp3 file was playing incorrectly. joelhardi's approach (cat + vbrfix) works well, as well as I didn't need any tags at all. – summer.is.gone Mar 15 '15 at 21:01
  • Is mp3wrap still maintained? Site looks like it's from 1993, I don't want to rely on something so dicey. – niico Jan 25 '21 at 14:53
21

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
bmurphy1976
  • 29,564
  • 11
  • 33
  • 24
6

The time problem has to do with the ID3 headers of the MP3 files, which is something your method isn't taking into account as the entire file is copied.

Do you have a language of choice that you want to use or doesn't it matter? That will affect what libraries are available that support the operations you want.

Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
  • This is just a personal project so I don't care about the language. Simple is best, my biggest problem is that it seems like something I shouldn't need to spend too much time on, but have. In answer to your question VB.NET. Thanks – Dan Williams Sep 15 '08 at 13:09
4

What I really wanted was a GUI to reorder them and output them as one file

Playlist Producer does exactly that, decoding and reencoding them into a combined MP3. It's designed for creating mix tapes or simple podcasts, but you might find it useful.

(Disclosure: I wrote the software, and I profit if you buy the Pro Edition. The Lite edition is a free version with a few limitations).

Adam
  • 49
  • 2
  • Any chance this will be updated for windows 8? – TombMedia May 23 '14 at 18:44
  • The software is fully compatible with all modern versions of Windows, including Windows 8, 8.1, and 10. I haven't updated the website in quite a while, it's due for an overhaul, but the software is still available and works fine. – Adam Mar 01 '16 at 15:17
4

MP3 files have headers you need to respect.

You could ether use a library like Open Source Audio Library Project and write a tool around it. Or you can use a tool that understands mp3 files like Audacity.

Chris M.
  • 651
  • 4
  • 19
2

As David says, mp3wrap is the way to go. However, I found that it didn't fix the audio length header, so iTunes refused to play the whole file even though all the data was there. (I merged three 7-minute files, but it only saw up to the first 7 minutes.)

I dug up this blog post, which explains how to fix this and also how to copy the ID3 tags over from the original files (on its own, mp3wrap deletes your ID3 tags). Or to just copy the tags (using id3cp from id3lib), do:

id3cp original.mp3 new.mp3
joelhardi
  • 11,039
  • 3
  • 32
  • 38
  • mp3wrap appears abandoned or at least a project from some random guy that could easily cease to be updated. Any way to do this with ffmpeg? – niico Jan 25 '21 at 15:08
1

I'd not heard of mp3wrap before. Looks great. I'm guessing someone's made it into a gui as well somewhere. But, just to respond to the original post, I've written a gui that does the COPY /b method. So, under the covers, nothing new under the sun, but the program is all about making the process less painful if you have a lot of files to merge...AND you don't want to re-encode AND each set of files to merge are the same bitrate. If you have that (and you're on Windows), check out Mp3Merge at: http://www.leighweb.com/david/mp3merge and see if that's what you're looking for.

1

If you want something free with a simple user interface that makes a completely clean mp3 I recommend MP3 Joiner.

Features:

  • Strips ID3 data (both ID3v1 and ID3v2.x) and doesn't add it's own (unlike mp3wrap)
  • Lossless joining (doesn't decode and re-encode the .mp3s). No codecs required.
  • Simple UI (see below)
  • Low memory usage (uses streams)
  • Very fast (compared to mp3wrap)
  • I wrote it :) - so you can request features and I'll add them.

MP3 Joiner app

Links:

  • MP3 Joiner website: Here
  • Latest installer: Here
James
  • 30,496
  • 19
  • 86
  • 113
  • Doesn't start on windows7. – Stepan Yakovenko Jun 19 '14 at 14:34
  • @stiv It certainly does :) I'd be interested to know what's going wrong on your machine. – James Aug 12 '14 at 16:49
  • @James can't activate. Unusable. – Christian Dalager Oct 05 '14 at 19:34
  • @ChristianDalager There's a known bug where the '.' in the link opened by the activation window is removed from the url. Try clicking 'activate' then change part of the url opened '&v=10' to '&v=1.0'. This applies to anyone using Firefox. Should work fine after that. – James Oct 06 '14 at 22:40
  • Doesn't work on Windows 7, just shows an error during start (complaining that input string format was wrong and that's it). – Denis V Mar 03 '16 at 20:44
  • product activation is broken... – 576i Jun 14 '16 at 19:20
  • It's no longer possible to use this application, as the original website is down. Even though the application is available from software mirrors, it has a built in "free" activation process that can't be completed without visiting the now-gone homepage. – Tobias Cohen Mar 11 '20 at 05:16
1

I would use Winamp to do this. Create a playlist of files you want to merge into one, select Disk Writer output plugin, choose filename and you're done. The file you will get will be correct MP3 file and you can set bitrate etc.

szeryf
  • 3,197
  • 3
  • 27
  • 28
  • When a put a file name in, it simply overwrites the file. Am I missing something? – Dan Williams Sep 15 '08 at 14:14
  • The file name you enter should be that of the file you want the merged output to be saved to. However, this solution involves recoding the audio (de-coding then re-encoding), which will result in a loss of audio quality (as MP3 is a lossy format). I think it'll also take a rather long time :) – David Precious Sep 15 '08 at 14:47
0

Instead of using the command line to do

copy /b 1.mp3+2.mp3 3.mp3

you could instead use "The Rename" to rename all the MP3 fragments into a series of names that are in order based on some kind of counter. Then you could just use the same command line format but change it a little to:

copy /b *.mp3 output_name.mp3

That is assuming you ripped all of these fragment MP3's at the same time and they have the same audio settings. Worked great for me when I was converting an Audio book I had in .aa to a single .mp3. I had to burn all the .aa files to 9 CD's then rip all 9 CD's and then I was left with about 90 mp3's. Really a pain in the a55.

0

Personally I would use something like mplayer with the audio pass though option eg -oac copy