using FFMPEG with silencedetect to remove audio silence

后端 未结 3 1149
[愿得一人]
[愿得一人] 2020-12-02 13:50

I am trying to use the following command with the latest ffmpeg build to remove silence from my .mp3 files:

ffmpeg -i SILENCE.mp3 -af silencedetect=n=-50dB:d         


        
3条回答
  •  旧巷少年郎
    2020-12-02 14:17

    ffmpeg silence detect only detects the silence. One has to scan the ffmpeg output and cut the mp3 file.

    In theory, this would be done as:

    ffmpeg -i INPUT.mp3 -af silencedetect=n=-50dB:d=1
    

    and monitoring for output in form of:

    [silencedetect @ 0000000004970f80] silence_start: -0.00154195
    [silencedetect @ 0000000004970f80] silence_end: 3.20435 | silence_duration: 3.2059
    ...
    [silencedetect @ 0000000004970f80] silence_start: 343.84
    

    And, cutting start and end silence:

    ffmpeg -i INPUT.mp3 -ss 3.20435 -t (343.84-3.20435)
    

    I ended up writing a small Java program which does it. Hints:

    • ffmpeg writes to stderr. This means, you need to use ProcessBuilder and redirectErrorStream(true).
    • secondly, you need to extract the silence_start and silence_end information.
    • then you might use the timestamps to cut the video

    Following code may be helpful: Using Java and FFMPEG with silencedetect to remove audio silence

提交回复
热议问题