Repository navigation
Filter trailingsilence
trailingsilence reports where a stream's audible content ends. A media server can store that point and a player can stop there.
It never cuts anything. Trimming is your job, with a second, ordinary ffmpeg -to pass.
# Step 1: measure. destination writes the JSON report.
# The metadata is on the final frame either way, so a bare -af trailingsilence works too.
ffmpeg -i in.mka -af trailingsilence=destination=report.json -f null -
# Step 2: cut, using recommended_end from step 1. This often needs no re-encode.
ffmpeg -i in.mka -to <recommended_end> -c copy out.mkaThe table is copied from ffmpeg -h filter=trailingsilence of v1.0.47.
| Option | Type | Default | What it does |
|---|---|---|---|
noise |
double | 0.00316228 |
Silence threshold, in dB or as a linear amplitude. The default is -50 dB. Range: 0 to DBL_MAX. |
n |
double | 0.00316228 |
Alias for noise. |
duration |
duration | 2 |
Minimum length of the trailing silence, in seconds. A quiet run must reach it before it counts. |
d |
duration | 2 |
Alias for duration. |
min_stream_duration |
duration | 10 |
Skip streams shorter than this. Nothing is reported as detected. |
safety_margin |
duration | 0.25 |
How far after silence_start the advice sits. |
destination |
string | empty | Path for the JSON report. Empty disables the report. The frame metadata is still emitted. |
format |
string | json |
Report format. Only json is supported. |
noise accepts -50dB or 0.00316227766. Both are the same threshold.
All six keys are on the final frame of every run, also when nothing is found. Each is lavfi.trailingsilence.<key>.
| Key | What it is |
|---|---|
detected |
1 if a qualifying trailing silence was found, else 0. |
silence_start |
Measured. Seconds from the stream start to where the trailing quiet run begins. |
silence_duration |
Measured. The length of that quiet run. |
stream_duration |
Measured. The total stream duration. |
recommended_end |
Advice. min(silence_start + safety_margin, stream_duration). |
safety_margin |
The margin that was applied. It echoes the option for a caller that only sees the report. |
silence_start is where the signal fell below noise and stayed there. That is a measurement.
recommended_end is advice. It is the measurement plus a small safety margin. A very quiet outro can sit below the threshold and still be audible: a fading tail, room tone, a soft sustained note. You can use the exact measured point, the padded advice, or your own policy in between.
When detected=0, every key is still emitted and recommended_end equals stream_duration. You can pass recommended_end straight to -to without checking detected. On a stream with nothing to trim, the command trims nothing.
The one exception: if the filter saw no audio at all (a seek past the end, an empty or undecodable track), the report is still written, but every field is 0, recommended_end included. stream_duration == 0 identifies this case. A caller that reads recommended_end blindly must check for it.
The report is written to destination. These properties hold:
-
A bad report setup fails before any work.
destinationandformatare checked when the filter graph is built, before a frame is decoded. An unwritable path or an unsupported format gives an error line and a non-zero exit code. -
The file never exists half-written. The content goes to
<destination>.partand is renamed into place at the end of the stream. Treat "present" as "finished". -
An unfinished run cannot destroy a finished report. A run that never reaches the end of the stream (killed, or a graph torn down early by
-frames:aor an output limit) publishes nothing and leaves any earlier report as it was. A stray.partfile is the sign of such a run. -
destinationmust be a plain file path. A protocol URL opens but cannot be renamed. The filter reports that and leaves the finished report at the temporary path.
- Streams shorter than
min_stream_duration(10 s by default). - Entirely silent streams. There is no audible content to keep, so there is no honest cut point.
- Silence in the middle of the stream that does not reach the end.
- Live input. The report is made at the end of the stream, which live input never reaches.
The filter is in every platform archive. It needs no model and no extra files. The release smoke test checks it on a generated fixture: a padded tail must give detected=1.
Users
Filters and components
- Filter-stemsplit
- Filter-lyricsalign
- Whisper-Language-Detection
- Whisper-Word-Timestamps
- Filter-trailingsilence
- Filter-keydetect
- Filter-beatdetect
- Filter-rubberband
- Muxer-Sprite-Sheet
- Muxer-Chapter-VTT
- Muxer-VOBsub
- Protocol-dvdread
- Protocol-OmniDrive
- Auto-Create-Directories
- AACS-and-BDplus
- HLS-Master-Playlist
- Subtitles-OCR
- HEVC-Alpha
Acceleration and codecs
Contributors