Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: MP3 errors (Read 4952 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

MP3 errors

Hello -

I'm building a web application that allows the users to upload MP3s of their creation, speech not music. Seems there are a lot of issues with MP3 encoders out there.

On the server I decode it, resample it with SoX (so they all end up 48kHz sample rate, stereo, 16-bit per sample) and then re-encode them as MP3 with lame (and as opus with opusenc). Yes 48000 is excessive for speech, it's a matter of consistently using the sample sample rate for everything on the site.

There are two fairly common errors I encounter.

A) sample rate changes in the stream. I'm not sure what causes this, but lame can not decode those MP3s and they also will not play in some browsers but do in others. I've found that using gst-launch with the libmad plugin in the pipe decodes the few I have come into so far, but does anyone know what causes that encoding error and if there is a proper way to handle it?

B) Sometimes the audios on upload do not have an audio/mpeg mime type when inspected with the php function mime_content_type after upload, but instead have the mime type application/octet-stream.

They still decode to wave using lame (or a gstreamer pipe if they also have the sample rate issue) but is that just a bad encoder setting or is there a different issue going on? That is happening consistently with MP3 audios uploaded by two different people. I had to change the web app to accept that mime type on upload, but that mime type can mean a lot of things. I would rather tell those two users what they are doing wrong, if anyone knows.

Thanks for suggestions.

Re: MP3 errors

Reply #1
For a web facing system I think ffmpeg is much, much more widely used for decoding then lame. Might want to try that.

Re: MP3 errors

Reply #2
There's absolutely no video frames involved, why would I need ffmpeg?

I need lame on the server anyway to encode back to mp3 after the SoX resample, there is no better MP3 encoder.

decoding works fine with lame and gstreamer when lame fails, I just am trying to figure what crappy encoders are changing the sample rate of an MP3 mid-stream and what crappy encoders are creating files that aren't seen as audio/mpeg from the magic bits, so I can tell people not to use them.

I also want to know if changing sample rate inside an MP3 is a known issue with a known fix that might be better than using a gstreamer pipe with the libmad plugin.

Re: MP3 errors

Reply #3
Oh another advantage to using lame for encoding besides its superior quality to all others, I can have lame calculate the replaygain while encoding, grab it from the lame header, and stick it in a TXXX field. That way I don't need mp3gain as part of the process, one less utility (I'm a minimalist when it comes to binaries on the server)

Re: MP3 errors

Reply #4
There's absolutely no video frames involved, why would I need ffmpeg?
It's not just for video. It's a single program that can do most of what you want in a single step: take an arbitrary audio file (not just MP3!), decode it, resample it, and encode to MP3 and Opus. (You'll want a build with libmp3lame and libopus for that last step.)

In case you still need to use LAME separately, ffmpeg has no trouble providing uncompressed audio that you can pipe to LAME.

A) sample rate changes in the stream.
Do you have an example of such a file?

B) Sometimes the audios on upload do not have an audio/mpeg mime type when inspected with the php function mime_content_type after upload, but instead have the mime type application/octet-stream.
That just means PHP isn't smart enough to detect the file. If you can decode it (with ffmpeg, for example), then there's no problem.

Re: MP3 errors

Reply #5
It's a single program that is way beyond the scope of what I need, increasing the attack surface of potential malicious uploads.

It's a single program that has patent issues, I'm not sure it is possible to build it without h.264 support.

It's a single program that at least historically did not do opus encoding as well as the reference opusenc encoder.

I like and use ffmpeg, just don't need it on a server for audio transcoding.

Re: MP3 errors

Reply #6
That just means PHP isn't smart enough to detect the file. If you can decode it (with ffmpeg, for example), then there's no problem.

There are two people specifically who upload files that are not identified by php as audio/mpeg - everyone else, they are always identified correctly.

I don't think the problem is php, but a missing magic byte in the file that is suppose to be there. What encoders do that?

Re: MP3 errors

Reply #7
It's a single program that is way beyond the scope of what I need, increasing the attack surface of potential malicious uploads.

It's a single program that has patent issues, I'm not sure it is possible to build it without h.264 support.

It's a single program that at least historically did not do opus encoding as well as the reference opusenc encoder.

I like and use ffmpeg, just don't need it on a server for audio transcoding.

I would be more concerned about using lame then ffmpeg.

Re: MP3 errors

Reply #8
I don't think the problem is php, but a missing magic byte in the file that is suppose to be there. What encoders do that?
None, because you can't play a MP3 without the magic bytes.

There's probably some other reason why PHP isn't finding them. For example, it may have trouble seeing the MP3 data past ID3v2 tags, or it may not recognize the magic bytes for uncommon encoding settings.

If you upload some samples of files that give you trouble, we can take a closer look.

It's a single program that at least historically did not do opus encoding as well as the reference opusenc encoder.
You can also pipe output from ffmpeg to opusenc.

Re: MP3 errors

Reply #9
MP2 is better suited to web streaming.