Parsing Mp3 in Python

This is what I have been trying to do for a while, and it is rather an open-ended question. If anyone has any knowledge that can help me shed light on this, it will be very appreciated.

I want to decode an audio stream to mp3 and use it to play animation using python. As I understand it, the audio data in mp3 is stored in frames of 32 frequency subbands (or frequency bins), which is ideal for me - if I could take mp3 and extract the amplitude for each subband on each frame, which would be ideal for what I want make.

I found a solution here https://bitbucket.org/portalfire/pymp3 where all the processing seems to be done in python. It's pretty slow, but even if I could use it to extract what I want, it would be nice - I'm struggling to figure out what is going on in this code. I also had a solution in which I converted to wav and then used fft to extract frequencies from wav. It was very noisy and seems like a stupid way to do it, because the data I want is stored directly in mp3 - converting back to the sound wave seems unnecessary. It was actually faster than the first. Here is what I ended up with:

http://www.youtube.com/watch?v=f_0FORxlK4A

Well, if someone has any tips or experience that they want to share, or ideas for libraries that I should pay attention to, I would really like to hear.

Thanks!

Henry

+6
source share
1 answer

Take a look at:

http://lightshowpi.org/

Pick up the source code and see how they did it.

They also used FFT at the output of the wave, but in real time, and itโ€™s not as slow as you think it works fine on Raspberry Pi.

Instead, they can switch to cosine conversion, since it happens faster, and this is what you would do if you would check the MP3 frames correctly, since MP3 is encoded with cosine conversion.

So, first you need to know which bit resembles frequencies in the real world.

Pypi.python.org now has direct AV or ffmpeg bindings that allow you to decode frame by frame, but I donโ€™t know if you can extract freqs from objects representing frames, or you will have to convert to raw first as well.

If I were you, I would use the clean Python MP3 code you found to extract exactly what I need, optimizing it in the process. Using cython if necessary.

But this approach limits you to just MP3s. Lightshow Pi works with almost all compressed types.

+1
source

Source: https://habr.com/ru/post/952674/


All Articles