> ## Documentation Index
> Fetch the complete documentation index at: https://rendi.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Silence Detection and Removal

> Detect and remove silences from audio and video files using FFmpeg in Rendi

## Overview

FFmpeg can be used for silence detection and removal in audio and video processing. This guide shows you how to:

* Detect silence in media files and export metadata
* Remove silence from media files automatically

## Silence Detection with Metadata Export

The `silencedetect` filter identifies silent segments in audio based on noise threshold and duration. By combining it with `ametadata`, you can export detailed metadata about when silence occurs in your media files.

### FFmpeg Command for Silence Detection

```bash theme={null}
ffmpeg -i https://storage.rendi.dev/sample/popeye_talking.mp4 -af "silencedetect=noise=-20dB:d=0.5,ametadata=mode=print:file=silence_metadata.txt" -f null -
```

#### Command Breakdown:

* `-i input.mp4` - Input video or audio file
* `-af` - Audio filter
* `silencedetect=noise=-20dB:d=0.5` - Detects silence below -20dB lasting at least 0.5 seconds
  * `noise=-20dB` - Threshold for silence (adjust based on your audio; -20dB is moderate, -30dB is more sensitive)
  * `d=0.5` - Minimum duration of silence in seconds
* `ametadata=mode=print:file=silence_metadata.txt` - Exports metadata to a file
  * `mode=print` - Prints metadata for each frame
  * `file=silence_metadata.txt` - Output file for metadata
* `-f null -` - No video output (we're only analyzing)

### Run Silence Detection in Rendi

To run this command in Rendi, you need to use the `/v1/run-ffmpeg-command` endpoint:

```bash theme={null}
curl --location 'https://api.rendi.dev/v1/run-ffmpeg-command' \
--header 'X-API-KEY: <api-key>' \
--header 'Content-Type: application/json; charset=utf-8' \
--data '{
    "input_files": {
        "in_1": "https://storage.rendi.dev/sample/popeye_talking.mp4"
    },
    "output_files": {
        "out_1": "silence_metadata.txt"
    },
    "ffmpeg_command": "-i {{in_1}} -af \"silencedetect=noise=-20dB:d=0.5,ametadata=mode=print:file={{out_1}}\" -f null -"
}'
```

When commands' `status` reaches `SUCCESS`, you'll get the metadata file in the response:

```json theme={null}
{
    "command_id": "089dd36c-723c-4a0a-b68a-8e8cbcc1afd2",
    "status": "SUCCESS",
    "output_files": {
        "out_1": {
            "file_id": "da09eaa7-904f-45e2-a727-74760b2696f6",
            "storage_url": "https://storage.rendi.dev/files/.../silence_metadata.txt",
            "status": "STORED"
        }
    }
}
```

The metadata file will contain timestamps of all detected silence segments, which you can parse for further processing.

## Silence Removal

While FFmpeg includes a `silenceremove` filter, the recommended method for removing silence is the **Jump Cuts** technique, which involves a two-step process:

**Step 1: Detect Silence and Get Timestamps**

First, use `silencedetect` to identify where silence occurs in your video:

```bash theme={null}
curl --location 'https://api.rendi.dev/v1/run-ffmpeg-command' \
--header 'X-API-KEY: <api-key>' \
--header 'Content-Type: application/json; charset=utf-8' \
--data '{
    "input_files": {
        "in_1": "https://storage.rendi.dev/sample/popeye_talking.mp4"
    },
    "output_files": {
        "out_1": "silence_metadata.txt"
    },
    "ffmpeg_command": "-i {{in_1}} -af \"silencedetect=noise=-20dB:d=0.5,ametadata=mode=print:file={{out_1}}\" -f null -"
}'
```

**Step 2: Parse Timestamps and Create Jump Cuts**

Parse the silence timestamps from the metadata file, then use them to create precise jump cuts that completely remove the silent segments. This gives you:

* Complete removal of silence (not just audio compression)
* Maintained video/audio sync
* Precise control over what gets cut
* Shorter final video duration

#### Example: Running Jump Cuts in Rendi

After analyzing the silence metadata, you can create jump cuts to keep only the non-silent portions. For example, to keep segments from 0.0-5.7s, 11.0-18.0s, and 19.0-20.0s:

**Base FFmpeg Command:**

```bash theme={null}
ffmpeg -i https://storage.rendi.dev/sample/popeye_talking.mp4 -vf "select='between(t,0.0,5.7)+between(t,11.0,18.0)+between(t,19.0,20.0)',setpts=N/FRAME_RATE/TB" -af "aselect='between(t,0.0,5.7)+between(t,11.0,18.0)+between(t,19.0,20.0)',asetpts=N/SR/TB" popeye_jumpcuts.mp4
```

**Run in Rendi:**

```bash theme={null}
curl --location 'https://api.rendi.dev/v1/run-ffmpeg-command' \
--header 'X-API-KEY: <api-key>' \
--header 'Content-Type: application/json; charset=utf-8' \
--data '{
    "input_files": {
        "in_1": "https://storage.rendi.dev/sample/popeye_talking.mp4"
    },
    "output_files": {
        "out_1": "popeye_jumpcuts.mp4"
    },
    "ffmpeg_command": "-i {{in_1}} -vf \"select='\''between(t,0.0,5.7)+between(t,11.0,18.0)+between(t,19.0,20.0)'\'',setpts=N/FRAME_RATE/TB\" -af \"aselect='\''between(t,0.0,5.7)+between(t,11.0,18.0)+between(t,19.0,20.0)'\'',asetpts=N/SR/TB\" {{out_1}}"
}'
```

**Command Breakdown:**

* `-vf "select='...'"` - Video filter to select specific time ranges
* `between(t,0.0,5.7)+between(t,11.0,18.0)+between(t,19.0,20.0)` - Keep frames between these timestamps
* `setpts=N/FRAME_RATE/TB` - Reset presentation timestamps for smooth playback
* `-af "aselect='...'"` - Same selection applied to audio
* `asetpts=N/SR/TB` - Reset audio timestamps to maintain sync

For detailed examples of creating jump cuts with specific timestamps, see the [FFmpeg Cheatsheet - Jump Cuts](https://github.com/rendi-api/ffmpeg-cheatsheet?tab=readme-ov-file#jump-cuts) section.

<Tip>
  This two-step approach is superior to `silenceremove` for video files because it actually cuts out the silent portions entirely, making your videos shorter and more engaging, rather than just modifying the audio track.
</Tip>

## Use Cases

**Silence Detection with Metadata:**

* Analyze podcast episodes for silence patterns
* Quality control for audio recordings
* Identify timestamps for manual editing
* Generate subtitles timing

**Silence Removal:**

* Clean up podcast recordings
* Speed up video tutorials by removing pauses
* Create tighter, more engaging content
* Reduce file size by removing dead air

## Tips for Best Results

1. **Test with different thresholds**: Start with `-20dB` and adjust based on your audio quality
2. **Consider minimum duration**: Use `d=0.5` (0.5 seconds) to avoid removing natural pauses in speech
3. **Preview before batch processing**: Test on a small sample first
4. **Use metadata for precision**: Detect silence first, then use timestamps for precise cuts
5. **Quality encoding**: When re-encoding, use `-c:a aac -b:a 128k` for good audio quality

## Related Resources

* [FFmpeg Cheatsheet](https://github.com/rendi-api/ffmpeg-cheatsheet) - More audio processing examples
* [Run FFmpeg Command](/api-reference/endpoint/run-ffmpeg-command) - API documentation
* [Jump Cuts](https://github.com/rendi-api/ffmpeg-cheatsheet#jump-cuts) - Advanced silence cutting techniques
