Search code examples
mp3

Can I just append mp3s to each other? Does that create audio artifacts?


I would like to create a long mp3 from several shorter mp3s.

Of course I can use something like ffmpeg or lame to create the long mp3. But I was wondering, since mp3s are nothing frames, could I simply append the mp3s to each other?

Why? I create these file in a web application, and just appending them to each other would be so much easier and cheaper than any other way.

So I have an example where I just did that and here is the result: https://drive.proton.me/urls/62WYEEJX88#q5gjZYQLkbd1

So I notice:

  • playing this file with windows media player, it sound perfect!
  • playing it with chrome, there are some strange noises between the files.

But why is it not also good in chrome? Is there something like garbage data at the beginning of the file that causes this? Or is this because audio just does not work that way, if just just append the files there is no "smooth" transition between them?


Solution

  • Unfortunately, it's not that simple.

    Firstly, your source files need to have the sample rate and channel count. While in theory this could change from one frame to the next, I've never heard of a player that pulls this off. Note that bitrate can change arbitrarily.

    The next problem is that most MP3 files have other junk in them, like ID3 tags. Depending on the version, those tags might be at the beginning or the end of the file.

    Once you've cleaned all that stuff up and are ready to cut and splice, now you run into the problem of the bit reservoir. On most MP3 streams, frames do not actually stand independently. They are not individually decodable. The bit reservoir is sort of like a somewhat variable bitrate within a constant bitrate stream. If there is a passage that's easy to encode, the encoder might pack in additional data for a different frame that's more complicated. The overall stream ends up having a constant bitrate, but those bits are used more efficiently to give higher quality audio.

    Finally, note that MP3s usually start off with a frame or two to initialize things. If you have silence at the beginning/end of your tracks then this isn't your issue, but you might read about the "gapless MP3" problem.

    None of these problems are insurmountable, but I think you'll find that letting FFmpeg do the work is the way to go and will be cheaper than DIY unless all of your source material is particularly prepared ahead of time for splicing.