Remove silence from audio and video with FFmpeg

For audio, use silenceremove: start_periods=1 trims the silence at the start, stop_periods=-1 shortens every pause after it, and stop_duration is how much of each pause stays. For a video, find the pauses with silencedetect and cut picture and sound together with trim, atrim and concat. Every command below ran on a 37 s voice track and a 40 s dialogue scene, and the results are what came out.

Audio Re-encode

Trims the start and shortens every pause over 0.5 s to 0.5 s. One filter, for audio files.

ffmpeg -i in.mp3 -af "silenceremove=start_periods=1:start_threshold=-50dB:stop_periods=-1:stop_threshold=-50dB:stop_duration=0.5" out.mp3

37.0 s in, 29.51 s out. The 2.5 s of silence at the start is gone and the 3 s gaps in the middle and at the end are 0.52 s and 0.51 s long. The MP3 is re-encoded at the 128 kb/s default.

Removed
7.49 s of 37.0 s
Gaps left
0.52 s and 0.51 s
Run time
380 ms
Output
473 KB
Video Re-encode

Finds the pauses with silencedetect and cuts them from picture and sound together. Re-encodes.

ffmpeg -i in.mp4 -filter_complex "$(ffmpeg -nostats -i in.mp4 -af silencedetect=n=-35dB:d=1 -f null - 2>&1 | awk '/Duration/{split($2,h,":");D=h[1]*3600+h[2]*60+h[3]} /silence_start/{s=$NF} /silence_end/{if(s>p)K[n++]=p+0":"s;p=$5} END{if(D>p)K[n++]=p":"D;for(i=0;i<n;i++){printf "[0:v]trim=%s,setpts=PTS-STARTPTS[v%d];[0:a]atrim=%s,asetpts=PTS-STARTPTS[a%d];",K[i],i,K[i],i;c=c"[v"i"][a"i"]"}printf "%sconcat=n=%d:v=1:a=1[v][a]",c,n}')" -map "[v]" -map "[a]" out.mp4

40.0 s in, 26.70 s out. silencedetect found 9 pauses of 1 s or more under -35 dB, 13.34 s in all, and both streams lost them: the picture ends at 26.67 s and the sound at 26.70 s.

Pauses cut
9, 13.34 s in all
Picture, sound
26.67 s, 26.70 s
Run time
2.4 s
Output
3.5 MB

Proof

The pauses before and after

Waveforms on one time scale per input, so a shorter output leaves empty space on the right. Drawn with 12 dB of display gain so the quiet parts show. Red marks what silencedetect found.
in.mp3
Waveform of the 37-second voice track with three shaded silent ranges: at the start, in the middle and at the end
37.0 s Dialogue with digital silence at 0 to 2.5 s, 18.9 to 21.9 s and 34.0 to 37.0 s. silencedetect=n=-50dB:d=1 found those three and nothing else.
silenceremove, areverse twice Both ends trimmed, the middle gap kept
The same waveform with the silence at the start and end gone and the gap in the middle still there
31.48 s 2.50 s cut from the start and 3.01 s from the end. The 3 s gap between the lines is untouched.
stop_periods=-1:stop_duration=0.5 Every gap down to half a second
The waveform with the start silence gone and the middle gap shrunk to a sliver
29.51 s The start is trimmed, the middle gap is 0.52 s and the end 0.51 s. The dialogue between them is the same as in the input.
in.mp4, silencedetect=n=-35dB:d=1
Waveform of the 40-second dialogue scene with nine shaded pauses that still show low room tone
9 pauses The pauses are not empty. Fire and room tone fill them, so they show as a thin band, not a flat line. At -35 dB, 9 of them last 1 s or more.
trim, atrim, concat Pauses cut from picture and sound
Waveform of the cut scene, two thirds as long, with the dialogue lines close together
26.70 s The same lines, 13.30 s shorter. Pauses shorter than the 1 s minimum stay in.
out.mp4, frames 75 and 76 A jump cut where the first pause was
Two frames side by side: the girl reaching out, then the girl already holding a bowl
1.75 s Frame 75 is 0:03.125 in the scene and frame 76 is 0:04.875. The picture between them went with the pause.

Footage: Sintel, © Blender Foundation, CC BY 3.0. Silence inserted by us in in.mp3.

Run it

Run it on Rendobar

Send the same command from your code. The job fetches each input from its URL and returns the output file's URL when it finishes.

job.ts
import { createClient } from "@rendobar/sdk";
const rb = createClient({ apiKey: process.env.RENDOBAR_API_KEY });
const job = await rb.jobs.run({
type: "ffmpeg",
inputs: {
"in.mp3": "https://cdn.rendobar.com/examples/remove-silence/in.mp3",
},
params: {
command: "ffmpeg -i in.mp3 -af \"silenceremove=start_periods=1:start_threshold=-50dB:stop_periods=-1:stop_threshold=-50dB:stop_duration=0.5\" out.mp3",
},
});
console.log(job.output.file.url);

Install with npm i @rendobar/sdk. jobs.run() submits and waits, so it returns the finished job in one call.

terminal
curl https://api.rendobar.com/jobs \
-H "Authorization: Bearer $RENDOBAR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "ffmpeg",
"inputs": {
"in.mp3": "https://cdn.rendobar.com/examples/remove-silence/in.mp3"
},
"params": {
"command": "ffmpeg -i in.mp3 -af \"silenceremove=start_periods=1:start_threshold=-50dB:stop_periods=-1:stop_threshold=-50dB:stop_duration=0.5\" out.mp3"
}
}'

Returns immediately with a job id. Poll GET /jobs/{id} or register a webhook rather than blocking on the request.

Every variant

Pick the command for your case

Each one ran on the same input. The line under it is what came out. Run times are the best of three runs with FFmpeg 8.0 on one desktop machine, so read them as relative.

  1. Trim silence from the start and end

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

    31.48 s from 37.0 s: 2.50 s cut at the start and 3.01 s at the end, the 3 s gap in the middle untouched. areverse turns the end into a start so the same filter can trim it.

    1.3 s run 505 KB 31.48 s long

  2. Trim silence from the start only

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

    34.50 s: the first 2.50 s are gone and nothing after the first sound changes. Byte for byte the output of silenceremove=1:0:-50dB, the short form in the accepted Stack Overflow answer.

    374 ms run 553 KB 34.50 s long

  3. Trim silence from the end only

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

    33.99 s: the last 3.01 s are gone and the silence at the start stays.

    413 ms run 545 KB 33.99 s long

  4. Trim the ends but keep half a second

    Re-encode
    ffmpeg -i in.mp3 -af "silenceremove=start_periods=1:start_threshold=-50dB:start_silence=0.5,areverse,silenceremove=start_periods=1:start_threshold=-50dB:start_silence=0.5,areverse" out.mp3

    32.48 s, with 0.50 s of silence before the first word and 0.49 s after the last. start_silence is how much of the trimmed silence is kept.

    398 ms run 521 KB 32.48 s long

  5. List the silent parts

    Read only
    ffmpeg -i in.mp4 -af silencedetect=n=-35dB:d=1 -f null -

    9 pairs of silence_start and silence_end lines on stderr, the first from 3.156 to 4.846 s, 13.34 s of pauses in all. Nothing is written to disk.

    246 ms run

  6. Cut given pauses out of a video

    Re-encode
    ffmpeg -i in.mp4 -filter_complex "[0:v]trim=0:3.16,setpts=PTS-STARTPTS[v0];[0:a]atrim=0:3.16,asetpts=PTS-STARTPTS[a0];[0:v]trim=4.85:6.06,setpts=PTS-STARTPTS[v1];[0:a]atrim=4.85:6.06,asetpts=PTS-STARTPTS[a1];[0:v]trim=7.32,setpts=PTS-STARTPTS[v2];[0:a]atrim=7.32,asetpts=PTS-STARTPTS[a2];[v0][a0][v1][a1][v2][a2]concat=n=3:v=1:a=1[v][a]" -map "[v]" -map "[a]" out.mp4

    The first two pauses silencedetect listed, 3.16 to 4.85 s and 6.06 to 7.32 s, cut from both streams. 37.06 s left, picture and sound within 15 ms of each other. Keep the parts between the pauses, one trim pair each.

    2.5 s run 4.3 MB 37.06 s long

  7. Split audio at every pause

    Stream copy
    ffmpeg -i in.mp4 -vn -c:a copy -f segment -segment_times "$(ffmpeg -nostats -i in.mp4 -af silencedetect=n=-35dB:d=1 -f null - 2>&1 | awk '/silence_end/{printf "%s%.2f",c,$5-$8/2;c=","}')" -reset_timestamps 1 part_%02d.m4a

    10 files, part_00.m4a to part_09.m4a, 2.26 to 7.55 s each and 40.02 s together. Each split falls in the middle of a pause, and the audio is copied, not re-encoded.

    339 ms run 867 KB 40.02 s long

Gotchas

Where it goes wrong

Why did silenceremove cut my file down to almost nothing?

stop_periods=1 does not mean trim the end. It means stop at the first silence and drop everything after it. The start-and-end command in the accepted Stack Overflow answer does that on FFmpeg 8.0:

ffmpeg -i in.mp3 -af silenceremove=1:0:-50dB:stop_periods=1:stop_duration=0:stop_threshold=-50dB out.mp3

0.41 s left of 37.0 s. With stop_duration=0, the first brief dip under -50 dB inside the first line counted as the end.

With stop_duration=1 it stops at the first full second of silence instead, and that gave 17.41 s: everything after the gap in the middle was lost. To trim the end, reverse the audio, trim its start and reverse it back:

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

31.48 s. Both ends trimmed, the middle gap kept.

What dB threshold counts as silence?

A level under your quietest words and over the noise in your pauses. Digital silence passes any threshold. A recorded pause does not: in the test scene the pauses carry fire and room tone that peaks at -36 to -38 dB, and the speech peaks at -14 to -18 dB.

silencedetect counts a stretch as silent only when every sample in it is under the level, so measure before you cut. This counts the pauses of 1 s or more at four levels:

for n in -50 -40 -35 -30; do ffmpeg -nostats -i in.mp4 -af silencedetect=n=${n}dB:d=1 -f null - 2>&1 | grep -c silence_end; done

0, 1, 9 and 11. The 9 pauses at -35 dB add up to 13.34 s. The 11 at -30 dB add up to 22.04 s, more than half the 40 s clip.

-50 dB, the level in the accepted Stack Overflow answer, found the three inserted silences in in.mp3 and nothing at all in the film scene. Start there for clean voice tracks, and raise it toward the noise in your pauses for anything recorded in a room.

Why is my video out of sync after removing silence?

silenceremove is an audio filter. Run it on a video and the sound gets shorter while the picture keeps every frame:

ffmpeg -i in.mp4 -af "silenceremove=start_periods=1:start_threshold=-35dB:stop_periods=-1:stop_threshold=-35dB:stop_duration=0.5" -c:v copy out.mp4

Video 40.0 s, audio 17.80 s. After the first pause every line plays over the wrong picture.

The select and aselect pair that many guides show fails the other way on FFmpeg 8.0. select drops the video frames, but aselect let all 1,875 audio frames through, and did the same with aselect=0:

ffmpeg -i in.mp4 -vf "select='not(between(t,3.16,4.85))',setpts=N/FRAME_RATE/TB" -af "aselect='not(between(t,3.16,4.85))',asetpts=N/SR/TB" out.mp4

Video 38.29 s, audio 40.0 s.

Cut both streams with trim and atrim and join them with concat, as the video commands on this page do. Each kept part gets a video trim and an audio trim with the same times, so the two cannot drift.

Why is there still silence left after silenceremove?

Because stop_duration is the length of pause that stays, not the shortest pause that goes. With stop_periods=-1:stop_duration=1 each 3 s gap in the test file came out 1.02 s long. With stop_duration=0.5 it came out 0.52 s.

Set it to 0 and the gaps go completely, along with more than you asked for:

ffmpeg -i in.mp3 -af "silenceremove=start_periods=1:start_threshold=-50dB:stop_periods=-1:stop_threshold=-50dB:stop_duration=0" out.mp3

23.32 s. The inserted silence adds up to 8.5 s, so 5.18 s more came out of the dialogue itself.

Keep a short pause, like the 0.5 s in the first command on this page, so the cuts never reach into the words.

Related: Mute a section, Split a video, Trim a video, Normalize audio.

Your command. Our infrastructure.

Bring your own commands. Run them on scalable CPU and GPU infrastructure, and pay only for compute time.