Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
938 views
in Technique[技术] by (71.8m points)

ubuntu - How can I remove silence from an MP3 programmatically?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...