Trim an MP3 Programmatically

冷暖自知 提交于 2019-12-22 01:02:04

问题


What is the best way to trim a mp3 file programmatically. 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?


回答1:


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.




回答2:


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




回答3:


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?



来源:https://stackoverflow.com/questions/551074/trim-an-mp3-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!