Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply best practices for creating programmatic videos with Remotion and React
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/silence-detection.md
1---2name: silence-detection3description: Adaptive silence detection for video/audio files using FFmpeg loudnorm and silencedetect4metadata:5tags: silence, detection, trimming, ffmpeg, loudnorm, audio6---78# Adaptive Silence Detection910Detect silent segments in video or audio files.1112Requires FFmpeg — see [ffmpeg.md](./ffmpeg.md) for how to invoke it in Remotion projects.1314## Step 1: Measure loudness with `loudnorm`1516Use the `loudnorm` filter in JSON mode to get the EBU R128 integrated loudness and gating threshold for each file:1718```bash19npx remotion ffmpeg -i public/video.mov -map 0:a -af loudnorm=print_format=json -f null /dev/null20```2122As output you will get:23- `input_i`: Integrated loudness (dB) — the overall perceived volume24- `input_thresh`: EBU R128 gating threshold (dB) — the level below which audio is considered too quiet to count toward loudness measurement2526## Step 2: Detect silences using adaptive threshold2728Pass the `input_thresh` value from step 1 as the `noise` parameter to `silencedetect`:2930```bash31npx remotion ffmpeg -i public/video.mov -map 0:a -af "silencedetect=noise=${THRESH}dB:d=0.5" -f null /dev/null32```3334Parameters:35- `noise`: The threshold below which audio is considered silent. Use `input_thresh` from step 1.36- `d`: Minimum silence duration in seconds. `0.5` is a good default.3738## Interpreting the output3940The filter outputs pairs of `silence_start` and `silence_end` timestamps:4142```43[silencedetect] silence_start: 044[silencedetect] silence_end: 2.241021 | silence_duration: 2.24102145[silencedetect] silence_start: 38.7742546[silencedetect] silence_end: 39.619604 | silence_duration: 0.84535447```4849## Identifying leading and trailing silence5051- **Leading silence**: Consecutive silence segments starting at or near 0. If the first `silence_start` is > 0.5s, there is no leading silence.52- **Trailing silence**: The last silence segment that extends to (or near) the end of the file. Compare the last `silence_end` with the file's total duration.5354When multiple silences are nearly contiguous at the start or end (gap < 0.2s), treat them as a single leading/trailing silence block.5556## Using with Remotion's `<Video>` component5758Apply the detected trim points using `trimBefore` and `trimAfter` (values are in frames):5960```tsx61import { Video } from "@remotion/media";62import { staticFile, useVideoConfig } from "remotion";6364const { fps } = useVideoConfig();6566<Video67src={staticFile("video.mov")}68trimBefore={Math.floor(leadingEnd * fps)}69trimAfter={Math.ceil(trailingStart * fps)}70/>71```72