1

I'd like to seperate the channels of a mp3 file in Python and save it in two other files. Does anybody know a library for this. Thanks in advance.

  • 1
    Quick google search reveals http://pymedia.org/. I've never used it, but the website says: "It allows you to parse, demutiplex, multiplex, decode and encode all supported formats. It can be compiled for Windows, Linux and cygwin." – Robᵩ Apr 15 '13 at 15:40
  • 1
    Related question: http://stackoverflow.com/questions/310765/python-library-to-modify-mp3-audio-without-transcoding – Robᵩ Apr 15 '13 at 15:44

1 Answers1

2

I assume you want to split the channels losslessly, without decoding MP3 and re-encoding it - otherwise you would not have mentioned MP3 at all and would have easily found many tools like Audacity to do that.

There are 4 channel modes of MP3 frames - this means 4 types of MP3 files: simple stereo, joint-stereo, dual-channel, mono. joint-stereo files can't be split without loss. mono files doesn't need splitting. The rest: stereo and dual-channel, consists of less than 0.1% of all MP3 files, technically can be split into 2 files, each for a channel, without loss. However there is not any tool on the Internet to do that - not any command line tool nor any GUI tool, because few need the function.

There are not any python library for you neither. Most libraries abstracted MP3 files into a common audio which you can manipulate, after decoding. pymad is the only one specific to MP3 file, and it can tell if a file is using any of the 4 channel modes, but does not offer to extract a channel without decoding it. If you write a new tool, you will have to work on raw MP3 files or produce a library for it.

And it is not easy to write a tool or library for it. It's one stream with 2 channels and not two streams interleaved on a frame level. You cannot simply work on MP3 frames, drop some frames, keep others, and manage to extract a channel out that way. It's a task for a professional, and perhaps best happen in a decoder project (like lame or libmad) and not in a file manipulation project (like mp3info or the python eyeD3). In other words, this feature is likely written in C, not python.


Implementaiton Note:

The task to build such a tool thus suits well for a computer science C-programming language course project: 1. it takes a lot of time to do; 2. it requires every skill learned from C programming course; 3. it can get wrong easily; 4. it is likely built on the work of other projects, a lesson of adaptating existing work; 5. is a damn-hard endeavor that no-one did before and thus very rewarding 6. perhaps can be done in 300 difficult lines of code instead of bloated simple Visual Basic code, thus is a good lession of modesty and quality; 7. and finally: nobody is waiting in an hurry for a working implementation.

All condition fits perfectly for a C-programming course project.

Implementation Note 2:

some bit-rates are only possible in mono mode (80kbps), and some bit-rates are only possible in stereo mode (e.g. 320kpbs). Luckily this does not present a problem in this task, because all dual-mp3 bit-rate can be mapped into a fitting mono-mp3 bit-rate -- but not vice versa!

Tankman六四
  • 1,638
  • 2
  • 13
  • 19