Concatenating MP3s using Java
Reply #1 – 2006-10-08 07:06:54
I am learning real quick that I can't always just read one MP3 file into memory, add the next, etc., and then just save this bulk of memory into a file (I say "can't always" because this actually worked for some of the samples I've played around with). If the files are capable of being concatenated together, this will work. If they can't be concatenated together, it won't work. There might be a bit of a gap at the join point, or a sync error if the second file has tags at the beginning, but the resultant file will play if the files can be concatenated. Doing it that way should play most of the time, but you seem to imply that generally it does not work. From what I know, at least Foobar will be able to read two concatenated files as long as they have the same sample rate. How did you test for success?Right now, I'd be happy if I could only get information on how to do this with WAV files, and then just convert it to MP3 through some command-line utility. Doing it from a WAV file is fairly straightforward. Just read the WAV header on both files, verify that they are concatenatable(?), make a new header with the updated length, then stick both of the data parts right after it. There are a lot of pages which go over the WAV file format (actually you'll find it called the RIFF file format a lot) this page seems to be pretty informational. By far the most common header is 44 bytes long. If you know where you're getting your WAVs from, you should be able to just code for that case.