Splitting Mp3's
caseydk writes: "I'm working on a project that needs to take a single mp3 (a live recording) and play individual sections of it. Preferably, so that the user must only download a portion of the mp3, instead of the whole thing. Unfortunately, most (or all) mp3 splitters that I have found have a gui. I'm looking for something command-line, so that I can just have the server do it during low usage times or (worst case) on the fly. Any suggestions?"
A quick google search on "mp3 header" found this document on the mp3 header format. Where I learnt that the beginning of each frame starts with the first 11 bits set to 1, so you can use this to write a quick script to split a mp3 up into pieces.
You should check out mpgtx, the mpg toolbox.
It's heading for a stable 1.0 release.
You can find it on http://mpgtx.sourceforge.net
By the way, splitters with a gui?
I find it hard to find a mpg splitter with a gui.
I do know mpgcut (or mpcut?) and bc2000.
Which ones are you referring to?
Well, don't worry about that. We can get you back before you leave. (Dr. Who)
I've tried this and it sometimes works and sometimes doesn't depending on the player, since the start of your file snippet will have junk in it, but it seems to me that it would be an easy programming exercise to create a program that would lop off the leading junk until it finds the next valid MP3 frame.
I don't claim to know much about MP3 format, but it appears from a quick session with a hex editor that frames start with 0xfffb9200 - can anyone verify this? If so, you could hack out something in an hour that would be fast, scriptable and do exactly what you want.
For extra credit points, you could then use mp3info to add id3 tags so your file will look cool when playing in xmms or whatever.
... using dd.
I know about the MP3 file header but before I knew about it I was chopping MP3s just for kicks. It works, it's easy and knowing the kbps of the file you can calculate the exact point to start and end. Example:
dd if=biggie_file.mp3 of=shortie_file.mp3 bs=1c seek=200k count=150k
It REALLY does work and it's command line - not to mention all the piping possibilites.
All browsers' default homepage should read: Don't Panic...
If you're encoding MP3 files and intend to split them like this, try to disable the bit reservoir. If you use LAME, the --nores switch will disable it. This may degrade quality slightly, but if you're using VBR or ABR mode it won't really matter. Instead of "lame -b 128", use "lame --nores --abr 128" for example. Then you can split the MP3 without problems.