Splitting MP3s in Perl

| 1 Comment | No TrackBacks

I listen to some podcasts daily that have annoying messages in them that never change. With a bit of research, I came across the MP3::Splitter module on CPAN which has somewhat confusing documentation but provides a method mp3split() that pulls specified pieces of a file. You provide mp3split() with the input MP3 filename, options as a hash and then any number of arrays that specify which portions of the MP3 to copy into new files. The easiest syntax for specifying a portion is to pass the start position and the length of the desired chunk, both in seconds. From the command line, I did this:

perl -MMP3::Splitter -e "mp3split('foo.mp3', {}, [20,25], [95,600], [950,INF])"

which creates three new MP3 files, 01foo.mp3, 02foo.mp3 and 03_foo.mp3. These can then be joined to create a new MP3:

cat 01_foo.mp3 > new.mp3
cat 02_foo.mp3 >> new.mp3
cat 03_foo.mp3 >> new.mp3

Which will leave you with new.mp3 that is a concatenation of the three pieces. Using cat to join them means the resulting file will probably have some artifacts at the join points but that's not a problem for my use. If it is, you can use something like mp3join to properly join the files.

No TrackBacks

TrackBack URL: http://dinomite.net/cgi-bin/mt/mt-tb.cgi/262

1 Comment

Hello

I am quite new to perl but i need this feature to a php website to take 20 seconds from a mp3 file and email it. Can you give me a hint how to use this library MP3::Splitter?

If you need any extra expliantions a give you.

Thank you

Leave a comment

Pages

About this Entry

This page contains a single entry by Drew Stephens published on September 26, 2008 10:35 AM.

Code Golf: Saving Time was the previous entry in this blog.

Old Techno Album Reviews: Dune - Expedicion is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.