2

I'm working with CBR, no bit reservoir, 192k bitrate, and 48k sample rate MP3 files.

CBR + 192k bitrate + 48k sample rate gives a clean 576 bytes per frame.

No bit reservoir is to make each frame independent.

The reason I want to stitch them is that I want to stream the MP3 (chunk by chunk).

Therefore I need to decode each chunk into PCM for playback.

When stitching the raw PCM data of the decoded MP3 together, I can hear a click/glitch/silence/something between each chunk on playback.

How can I stream MP3 perfectly without any click, considering my constraints (only CBR, no bit reservoir, etc)? Is it even possible?

4
  • Are you stitching complete MP3 encodes? Or do you trim your MP3s before stitching? Commented Jan 12, 2023 at 17:06
  • Is this helpful to you? ffmpeg has a lot of options. You can play with the bitrates and everything to your liking. superuser.com/questions/87040/… Commented Jan 13, 2023 at 12:15
  • @MarkusSchumann I'm not sure if this answers your question, but I'm stitching parts of an MP3 file (partial chunks) together (as opposed to stitching two complete MP3 files together) Commented Jan 13, 2023 at 18:50
  • @DarkoRiđić Unfortunately this wouldn't solve my issue, as this answer is about stitching different MP3 files together, as opposed to partial chunks :/ Commented Jan 13, 2023 at 18:51

1 Answer 1

2
+200

I don't think you can cut and concatenate MP3 frames naively. The Inverse Modified Discrete Cosine Transform (IMDCT) which is part of the decoding process - has different windowing modes. The windowing mode is signaled within each MP3 frame. In at least one windowing mode the IMDCT is reusing values from the previous MP3 frame. This means - you need to decode the previous frame to decode the current frame correctly.

Lets assume you have packets from file a and file b and you like to play:

a1 a2 a3 b6 b7 b8

to decode b6 correctly - you need to decode b5 and then throw away the PCM samples of b5. So at the cut you have to prime the decoder with b5 without playing b5.

a1 a2 a3 [b5] b6 b7 b8

You could send your player an additional packet at the cuts and then signal the player to discard the primming samples of the decoded additional packets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.