Python 中的 Mp3 解析 [英] Mp3 parsing in Python

查看:65
本文介绍了Python 中的 Mp3 解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我一直在尝试做的事情,而且更像是一个开放式问题.如果有人有任何知识可以帮助我对此有所了解,将不胜感激.

This is something I have been trying to do for a while, and is more of an open ended question. If anyone has any knowledge that can help me shed some light on this, it would be very much appreciated.

我想解码 mp3 中的音频流并使用它来驱动动画,全部使用 python.据我了解,mp3 中的音频数据存储在 32 个频率子带(或频率箱)的帧中,这对我来说是理想的 - 如果我可以使用 mp3 并为每一帧的每个子带提取振幅,那将适合我想做的事情.

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

我在这里找到了解决方案 https://bitbucket.org/portalfire/pymp3 似乎所有处理都在这里要在python中完成.它很慢,但即使我可以用它来提取我想要的东西,它也会很好 - 我正在努力理解该代码中发生了什么.我还有一个解决方案,我转换为 wav,然后使用 fft 从 wav 中提取频率.这非常嘈杂,似乎是一种愚蠢的方法,因为我想要的数据直接存储在 mp3 中 - 转换回声波似乎没有必要.不过,这实际上比第一个更快.这是我最后的结果:

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

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

好吧,如果有人有任何建议,或者他们想分享的经验,或者我应该看看图书馆的想法,我真的很想听听.

Well if anyone has any advice, or experience they want to share, or ideas for libraries I should look at, I'd really like to hear.

谢谢!

亨利

推荐答案

看一看:

http://lightshowpi.org/

嗅探源代码,看看他们是如何做到的.

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

他们还在波形输出上使用了 FFT,但它是实时的,它并没有你认为在 Raspberry Pi 上运行得那么慢.

They also used FFT on the wave output but in real time, and it is not so slow as you consider that it works fine on Raspberry Pi.

他们可能会切换到余弦变换,因为它更快,如果直接检查 MP3 帧,这就是您要做的,因为 MP3 是余弦变换编码的.

They might switch to cosine transform instead as it is faster, and this is what you would be doing if checking MP3 frames dirrectly, as MP3 is cosine transform encoded.

因此,您首先必须知道哪个 bin 与现实世界中的哪个频率相似.

So, you will firstly have to know which bin resembles which frequencies in real world.

在 pypi.python.org 上,现在有 AV 或 ffmpeg 直接绑定,允许您逐帧解码,但我不知道您是否可以从表示帧的对象中提取频率,或者您必须首先转换为原始

On pypi.python.org there are AV or ffmpeg direct bindings now that allow you to decode frame by frame, but I don't know whether you can extract freqs from objects representing frames or you would have to firstly convert to raw as well.

如果我是你,我会使用你找到的纯 Python MP3 代码来提取我需要的内容,并在此过程中对其进行优化.如果需要,使用 cython.

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

但这种方法仅限于 MP3.Lightshow Pi 适用于几乎所有压缩类型.

But that approach limits you to MP3 only. Lightshow Pi works on almost all compressed types.

这篇关于Python 中的 Mp3 解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆