audioffmpeg

How to mimic Audacity's "truncate silence" with ffmpeg "silenceremove" filter


I want to remove completely silence parts from wav files with ffmpeg.

Input wav can be like : enter image description here

I am using the following ffmpeg command to remove silence part ffmpeg -i input.wav -af silenceremove=stop_periods=-1:stop_duration=0.2:stop_threshold=-45dB output.wav because I understand from the doc that it will remove all silence parts longer than 0.2 s (silence being below -45dB).

But I get that enter image description here where silence part has only been reduced to around 0.1 wheras I want it to be 0 (no remaining silence).

In Audacity I will use "truncate audio" filter and choose the above parameters to detect silence and in the action part I will choose to truncate to 0: enter image description here.

This will yield to what I want (ie an audio with no silence part remaining): enter image description here

Searching on the internet only lead me to what I already do.

So how can I reproduce the output I get from Audacity "Truncate Silence" filter with ffmpeg and remove all silence parts from audio ?

Edit: The output from silencedetect filter is correct: ffmpeg -i input.wav -af silencedetect=0.2:n=-45dB -f null - detects exactly what audacity detects.

Thanks in advance for your help


Solution

  • It looks like the equivalent command to Audacity's truncate silence behaviour is the following:

    ffmpeg -i input.wav -af silenceremove=start_periods=1:stop_periods=-1:stop_duration=0.2:start_threshold=-45dB:stop_threshold=-45dB output.wav
    

    I am not sure why adding those 2 parameters leads to the expected behaviour but it works although for some files silenceremove can remove more parts than Audacity / silencedetect detect.