1. Remove Silence
  2. Blog

How to remove silence with FFmpeg

FFmpeg has two filters for silence. silenceremove cuts silence out of an audio stream. silencedetect only reports where the silence is. The first is all you need for a podcast or a voice memo. A video needs both, because cutting the sound alone leaves the picture behind.

All commands below work on macOS, Windows and Linux with a current FFmpeg build. The option names and defaults come from the FFmpeg filters documentation.

Remove every pause from an audio file

ffmpeg -i in.wav -af "silenceremove=stop_periods=-1:stop_duration=0.5:stop_threshold=-40dB" out.wav

What each part does:

  • stop_periods=-1 removes silence from the middle of the file, every time it occurs. A negative value means “keep going”, and the FFmpeg manual describes it as the setting for removing silence in the middle of the audio.
  • stop_duration=0.5 cuts only silences that last at least half a second. Shorter gaps, such as breaths between words, stay.
  • stop_threshold=-40dB treats anything quieter than -40 dB as silence. Add dB to the number, or FFmpeg reads it as an amplitude ratio.

The FFmpeg manual’s own example uses stop_duration=1 and stop_threshold=-90dB, which removes only digital silence of one second or more. For a recording made with a microphone, -90 dB is far below the room noise, so almost nothing is cut. Start around -40 dB for a quiet room and -30 dB for a noisy one.

Keep a little silence so it sounds natural

Removing every bit of a pause makes speech sound clipped. stop_silence keeps up to a set amount of each pause:

ffmpeg -i in.wav -af "silenceremove=stop_periods=-1:stop_duration=0.5:stop_threshold=-40dB:stop_silence=0.15" out.wav

Now every pause longer than half a second becomes at most 0.15 seconds long. That is close to the padding a dedicated silence remover keeps on each side of a word.

Trim only the start, or the start and end

To cut the silence before the first sound, for example the second between pressing record and speaking:

ffmpeg -i in.wav -af "silenceremove=start_periods=1:start_threshold=-50dB" out.wav

FFmpeg has no direct setting for the end of the file only. The common trick is to reverse the audio, trim its start, and reverse it back:

ffmpeg -i in.wav -af "silenceremove=start_periods=1:start_threshold=-50dB,areverse,silenceremove=start_periods=1:start_threshold=-50dB,areverse" out.wav

areverse holds the whole stream in memory, so use it on files of reasonable length.

The options that matter

Option Default What it does
start_periods 0 Trim silence at the start. 1 trims up to the first sound
start_threshold 0 Level treated as silence at the start, in dB or as a ratio
start_silence 0 Silence to keep at the start after trimming
stop_periods 0 Negative values remove silence throughout the file
stop_duration 0 Minimum silence length that gets cut
stop_threshold 0 Level treated as silence, in dB or as a ratio
stop_silence 0 Silence to keep from each cut pause
detection rms How level is measured: avg, rms, peak, median, ptp or dev
window 0.02 Seconds of audio used for each level measurement

With every default at 0, the filter does nothing until you set it. That surprises many people the first time.

Find the pauses with silencedetect

silencedetect writes the start and end of each silence to the log, without changing anything:

ffmpeg -i in.mp4 -af silencedetect=noise=-40dB:d=0.5 -f null -

The log shows lines such as silence_start: 12.48 and silence_end: 13.71 | silence_duration: 1.23. The defaults are -60 dB for noise and 2 seconds for d, which suit only very quiet recordings with long pauses. Set both for your recording.

Remove silence from a video

To cut the same pauses from picture and sound, keep everything that is not inside a silence. With the times from silencedetect, write them into select for the video and aselect for the audio:

ffmpeg -i in.mp4 \
  -vf "select='not(between(t,12.48,13.71)+between(t,20.02,21.40))',setpts=N/FRAME_RATE/TB" \
  -af "aselect='not(between(t,12.48,13.71)+between(t,20.02,21.40))',asetpts=N/SR/TB" \
  out.mp4

setpts and asetpts rebuild the timestamps so the remaining frames play back to back. Each pause adds one between() to both filters. For more than a handful, generate the expression with a short script from the silencedetect log, and re-encode, since cuts between keyframes cannot be stream-copied.

This works, but it is slow to set up and easy to get wrong on a long recording. Auto-Editor, an open-source command-line tool, automates the detect-and-cut loop for video and can export a timeline for Premiere Pro, DaVinci Resolve or Final Cut Pro instead of a rendered file.

When a command line is the wrong tool

FFmpeg is the right choice for batch jobs: a folder of voice memos, a server that cleans uploads, a build step. For a single recording, a tool that shows you the cuts is faster, because you hear what was removed and can put a pause back.

  • For audio in the browser, the free tool on this site shows each cut on a waveform and downloads a WAV. Nothing is uploaded.
  • For audio editors, see Audacity’s Truncate Silence, which has the same threshold and duration settings with a preview.
  • For video on iPhone or iPad, QuellCut finds the pauses, shows every cut on a timeline where you can switch it off, removes filler words and exports the video. For settings in general, read silence threshold settings.

Questions

How do I remove all silence from an audio file with FFmpeg?
Use silenceremove with a negative stop_periods: ffmpeg -i in.wav -af silenceremove=stop_periods=-1:stop_duration=0.5:stop_threshold=-40dB out.wav. Raise stop_duration to keep shorter pauses, and move stop_threshold toward 0 dB for a noisy recording.
How do I trim only the silence at the start of a file?
Set start_periods=1 and a start_threshold, for example silenceremove=start_periods=1:start_threshold=-50dB. Leave stop_periods at its default of 0 so nothing else is touched.
Can silenceremove remove silence from a video?
No. It is an audio filter, so it shortens the sound and leaves the picture at full length, and the two drift apart. Find the pauses with silencedetect, then cut both streams with select and aselect, or use a tool built for video.
Why does silenceremove cut my words?
The threshold is too high or the window too short for your recording. Move stop_threshold lower, for example from -30dB to -40dB, and keep a little silence with stop_silence=0.1 so word endings are not clipped.
What do the default values of silenceremove do?
Nothing. Both start_periods and stop_periods default to 0 and both thresholds to 0, so the filter passes the audio through unchanged until you set them.

Sources: FFmpeg Filters Documentation: silenceremove, FFmpeg Filters Documentation: silencedetect, FFmpeg Filters Documentation: select, aselect, Auto-Editor on GitHub.