I need to decode an MP3 file with Python. What is a good library which can do that?
I looked at PyMedia but the project seems dead and it didn't worked on MacOSX. Then I found out about pyffmpeg but I didn't got it working on MacOSX so far.
Any suggestion?
I did try an easy_install of PyMedia on OS X / Fink, and it did not work because it could not find the source. This module does look quite dead…
One way of decoding MP3 is to call ffmpeg without going through pyffmpeg, but by calling ffmpeg using the standard subprocess module instead.
You really need an external library. It'd be very difficult to do in Python with any sort of speed - see How to convert MP3 to WAV in Python for some discussion.
How about python-mad? MAD being the 'mpeg audio decoder'; there's a python library. It'd give you the audio data. Never used it myself...
I decided to code this myself based on subprocess and ffmpeg.
Some code can be found here:
https://github.com/albertz/learn-midi/blob/master/decode.py
Please try https://github.com/sampsyo/audioread
It's fast, installs from pypi and works well
Related
I'm trying to capture a video using a webcam then encoding it as an mp42 asf file on a windows machine.
I managed to encode an mpeg2 file using pymedia but pymedia doesn't seem to support mp42.
I installed opencv and tried to use the python wrapper but python keeps crashing everytime I create a writer. Even with just captureing images, it seems too slow and unreliable.
Does anyone know of a python module that allow me to create mp42 files?
Thanks,
-Ray
According to this : http://forums.creativecow.net/readpost/291/493 mp42 is a version 2 of MP4 ISO file format. (Explained here)
Where as according to this wiki link, it is an old Microsoft's (proprietary) MPEG4 codec version 2. This was built-in under VFW (video for windows). I think FFMPEG allows encoding using -vcodec MSMPEGv2 (or something like that) as per this link: http://ffmpeg.org/general.html#Video-Codecs. Though i am not sure if this is same.
If FFMPEG works, it has python binding pyffmpeg that might work for you.
For a website i am developing in django i need users to be able to upload .wav or .aif files. I, of course, have to make sure these files really are what they pretend to be - audiofiles. The files then are provided on the webpage, where i need them to be either .ogg or .mp3
While searching for a solution i stumbled across some fearsome possibilities, like using ctypes to handle external libraries. I also found, of course, PyMedia, which i cannot use because i develop on MacOSX. And the python audio tools provide a lot of functionality i do not need.
So far i can see a few possibilities that would satisfy me and are within reach of my programming capabilities:
1 Get PyMedia to run on MacOSX
2 Find a way to use some modules of the python audio tools without the need to use libcdio
3 use python subprocess to run the command line tools of the converters
As i have used none of those tools yet, i can't tell which would possibly be the quickest way to solve my problem. If you Python-Audio-Gurus are out there, could you please share some thoughts? Or maybe you even have a fantastic 1-step-to-happiness solution?
Not strictly a pythonic answer, but perhaps take a look at sox which is a simple command line audio file converter. It can do resampling of audio files for you as well.
Check out the command line options of sox for details. This will of course involve calling the external program using the subprocess module(or other method).
I'm looking for python code that can convert .wav or other format to FLAC or mpeg. I hope there is one that doesn't depend on other binaries or libraries and just pure python so that it can run independently anywhere where python is installed ie also serverside. Do you know any examples?
Thanks
Python Audio Tools seems to fit your description.
Worst case, you'd have to rip the source code out and go from there.
As others have said, there are other alternatives.
I have a couple of video container files which contain audio and video in various codecs. Now I'd like to inspect the container from a Python script to know which codec is used for audio+video. This is on a linux box so I have all the tools available if necessary.
I thought that maybe gstreamer could help me here but I was unable to find an API which could help me here.
Any ideas? I'm also open for any suggestion, doesn't need to be gstreamer as long as it is free software :-)
fs
ffprobe -show_format -show_streams -loglevel quiet -print_format json YOUR_FILE
Just invoke this with subprocess.check_output and you'll get a beautiful JSON description of your media file. If you need it to grab the data from stdin, replace YOUR_FILE with pipe:0.
ffprobe comes with ffmpeg.
Try downloading the ffmpeg source and look at the source for their command line programs. I've hacked up similar utilities in the past. I'm not posting my solution because ffmpeg likes to change their API, so my old code is unlikely to compile with the current version. You'll want to do enough work to create codec context, which you can inspect to get what you need.
Some other alternatives:
MediaInfo: http://mediainfo.sourceforge.net/en
GSpot (Windows only): http://www.headbands.com/gspot/
EDIT:
http://code.google.com/p/pyffmpeg/ might have what you want (I haven't used it myself).
You can use decodebin2 in Gstreamer. Take a look at TAE for code examples.
I'm trying to write my own media player (like Foobar), and I'm having trouble tracking down a Python library that'll play MP3s. I know Pymedia does mp3s, but it looks outdated - the latest installer is for Python version 2.4, and I'm using 2.6. I've never had much success with Pygame, and Pyglet doesn't look like it has too much in the way of documentation. Are there any other alternatives?
There is http://pyglet.org/ and also have you tried http://code.google.com/p/mp3play/? It's also available from PyPi (http://pypi.python.org/pypi/mp3play/) However, I think mp3play is Win32 only for now.
Looking at the updates, there were commits within last couple of months.
I've been using PyMedia in Python 2.6.5 on Windows successfully. Caveats: the documentation is bad and wrong -- many of the tutorials have glaring errors or otherwise don't work -- so I had to do some experimentation and Googling to get my code to work right. Also for whatever reason the maintainers seem to have stopped updating the project site 4 years ago, though they seem to be actively doing something.
I found installers here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
The semi-active forum linked from their website includes some code maintainers who are semi-helpful. I'm jboyd99 if anyone is looking for tips.
For reasons that are beyond me the focus is on car audio systems, despite the fact that it is a fairly fully featured library that does some things no other free Python library does, like read MP3s into raw PCM data. The library has some flaws -- I'll probably use PyAudio or PyAudiere for actual playback for better control of synchrony issues.
Maybe it'd be simpler to write that part of your application in Python 2.4 as a separate "backend". This way you could use PyMedia (http://pymedia.org/) (as you mentioned) for the actual playback. It'd allow you to write your GUI in another Python version (like 2.6), which would also mean more decoupling of program components and parallelism (smoother GUI).
If you target only the Windows platform, then using Media Player via COM might help:
http://www.daniweb.com/code/snippet216465.html