views:

237

answers:

3

What is the best way to trim a mp3 file programatically. For example, say I want to get rid of the first 2 minutes or last 2 minutes or both. Is there a good way to do this from .NET? Or .NET calling out to a command line tool?

Thanks.

+2  A: 

My bet is on a CLI tool. Take this for example.

Assaf Lavie
+3  A: 

There are two approaches to trimming MP3 files:

First, convert to WAV, trim off the samples you don't want, and then convert back to MP3. The disadvantage is that there will be a very slight loss of quality in the process. The advantage is that you will find plenty of command line tools to do the conversions for you, leaving you simply to trim the WAV file yourself (NAudio would let you do that).

Second, parse the MP3 frames themselves, and throw away whole frames. It doesn't give you so much granularity but there is no loss of quality in the process. You also need to be able to understand the format of the CBR and VBR MP3 frames as well as ID3 frames. There are various .NET libraries around that can read these, but you will still need to write a fair amount of code yourself.

Mark Heath
I think I could do it using the second method. It wouldn't have to be exact trimming. I listen to good 20 podcasts a week and have for about 3 years now. I'm getting a little burned out on the "podcast intro" and would like to trim the first 2 minutes off most podcasts.
tyndall
It might be a good weekend project to see if I can throw something together in .NET to do this, and then chain it into a podcatching process. Thanks for your help.
tyndall
@tyndall did u end up using a tool or custom code? if it was a tool, can u share the link? :)
eglasius
A: 

I wrapped mp3 decoder library and made it available for .net developers. You can find it here:

http://sourceforge.net/projects/mpg123net/

Included are the samples to convert mp3 file to PCM, and read ID3 tags.

Maybe you can use it to find mp3 frames and write out only ones that you are interested in keeping?

Daniel Mošmondor