To complement and answer your question about why 1 frame of data doesn't work, I wanted to add that the MP3 format (and most certainly many others) require training the compressor. For that reason a library such as LAME will add some silence at the beginning.
Similarly, to get the last bit of data, it adds yet more silence at the end of the stream. This is usually the job of the Flush()
function. In some situations, when you can't call the Flush()
function, you have to provide the silence yourself. (i.e. when creating a live feed or running with multiple threads.)
Also for those interested in doing a silencing of an existing frame, you can do so by setting all the side info values to zero like so:
FF FB 90 64-00 00 00 00-00 00 00 00-00 00 00 00
00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00
00 00 00 00
WARNING: The size of the side info varies depending on the version (MPEG-1 or not) and whether you have single channel or not.
This is how the Info or Xing tag are defined and if a player doesn't recognize the tag, it will just add an extra ~26ms of silence.
You can actually void the Info or Xing by replacing these character by U
or some other value. These would appear right after the header and side info bytes:
FF FB 90 64-00 00 00 00-00 00 00 00-00 00 00 00
00 00 00 00-00 00 00 00-00 00 00 00-00 00 00 00
00 00 00 00-55 55 55 55
Info would be 49 6E 66 6F
and Xing would be 58 69 6E 67
. This method allows you to edit an MP3 file in place without having to move all the content which can be huge or while streaming.