如何从一个MP3编程方式删除沉默? [英] How can I remove silence from an MP3 programmatically?

查看:217
本文介绍了如何从一个MP3编程方式删除沉默?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有MP3文件,有时必须在年底沉默。我想自动删除该沉默。从我可以告诉,这是完美的沉默(0幅度),而不是背景噪音。内容的长度和沉默变化

我发现了大约裁剪到前30秒或<一href=\"http://stackoverflow.com/questions/1390731/how-to-crop-a-mp3-from-x-to-xn-using-ffmpeg\">cropping以X和X + N秒使用的ffmpeg 。我想我可以使用类似的方法,只要我有办法找到沉默启动时。我将如何做到这一点编程?

例如,一种可能的解决办法是有找到沉默的开始的命令。我期望这样的顺序

 末= $(ffmpeg的一些命令找到的 - 开始 - 的 - 沉默)
ffmpeg的-t$结束-a codeC副本-i inputfile.mp3 outputfile.mp3

解决方案做的不可以必须使用的ffmpeg ,但它确实需要可在Ubuntu。


解决方案

  SOX inputfile.mp3 outputfile.mp3沉默1 0.1 0.1%反沉默1 0.1 0.1%逆转

这将削减任何沉默的时间比从文件0.1秒,如果你只关心修整结束,这可以简化为:

  SOX inputfile.mp3 outputfile.mp3扭转沉默1 0.1 0.1%逆转

详细研究如何的 SOX 沉默作品可以发现的here

I have MP3 files that sometimes have silence at the end. I would like to remove this silence automatically. From what I can tell, it is "perfect" silence (0 amplitude), not background noise. The length of the content and the silence varies.

I found some other questions about cropping to the first 30 seconds or cropping to X and X+N seconds using ffmpeg. I would think I could use a similar approach, as long as I have a way to find when the silence starts. How would I do that programatically?

For example, one possible solution would be to have a command that finds the beginning of the "silence". I'd expect a sequence like this

end=$(ffmpeg some-command-to-find-start-of-silence)
ffmpeg -t "$end" -acodec copy -i inputfile.mp3 outputfile.mp3

The solution does not have to use ffmpeg, but it does need to be available on Ubuntu.

解决方案

sox inputfile.mp3 outputfile.mp3 silence 1 0.1 0.1% reverse silence 1 0.1 0.1% reverse

This will trim any silence longer than 0.1 second from your file. If you're only concerned about trimming the end, this can be simplified to:

sox inputfile.mp3 outputfile.mp3 reverse silence 1 0.1 0.1% reverse

A detailed look into how sox's silence works can be found here.

这篇关于如何从一个MP3编程方式删除沉默?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆