brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ffmpeg -af silencedetect finds the silent parts of a recording

Ffmpeg
~/tips/tip-ffmpeg-silencedetect-find-gaps

ffmpeg -i recording.mp3 -af silencedetect=n=-50dB:d=5 -f null -

Lists where an audio file goes quiet, without changing the file.

Before I edit a long recording by hand, I’d like a list of where the quiet parts are. silencedetect does that and does not change the file.

The filter logs a message when the audio stays at or below a noise level for at least a minimum time. The two knobs are n (noise, the level) and d (duration). The documentation example detects 5 seconds of silence at a tolerance of -50 dB:

ffmpeg -i recording.mp3 -af silencedetect=n=-50dB:d=5 -f null -

-f null - means ffmpeg decodes the file and writes nothing. The answer is in the log lines that scroll by, with the start and end of every quiet stretch.

The docs also show a run with just a noise value, ffmpeg -i silence.mp3 -af silencedetect=noise=0.0001 -f null -, which is the shortest form to try on a new file.

The same documentation has a sibling, silenceremove, which actually cuts. One of its examples trims the trailing silence longer than a second with silenceremove=stop_periods=-1:stop_duration=1:stop_threshold=-90dB. Only run the removal on a copy: it changes the audio, and the thresholds are easy to set too aggressively.

The main caveat is the noise level. Room hiss, a fan, or music under a talk can sit above -50 dB, and then nothing counts as silence, so the output stays empty. Raise the tolerance (for example -35dB) and shorten d in small steps until the list looks like what you hear.

Further reading: ffmpeg filters documentation: silencedetect and silenceremove

More Ffmpeg tips ffmpeg -stream_loop 2 -i in.mp4 -c copy out.mp4 ffmpeg -i in.mp4 \ ffmpeg -i video.mp4 -i video.en.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=eng video-subs.mp4 ffmpeg -i film.mkv -map 0:v -map 0:a:0 -c:v copy -c:a aac -b:a 192k -ac 2 film-stereo.mkv ffmpeg -i talk.mp4 -vn -c:a copy talk.m4a All Ffmpeg tips (38) All topics

Link