Removes silence from a video using ffmpeg
yarn install
- Ensure
ffmpeg
is on yourPATH
. npx ts-node src\index.ts "<path_to_video>"
- Adjust noise detection tolerance if necessary, e.g.
npx ts-node src\index.ts "<path_to_video>" 0.001 0.5
- See silencedetect options for
noise
andduration
.
- See silencedetect options for
- Adjust trimming buffers if necessary, e.g.
npx ts-node src\index.ts "<path_to_video>" 0.001 0.5 0.2 0.3
- This will add 0.2s to the beginning of each clip and 0.3s to the end of each clip.
This tool runs ffmpeg
several times to:
-
Gets the duration of the video.
ffmpeg -hide_banner -t 0.001 -i <path_to_video> -f null out.null
-
Detects silence in the video.
ffmpeg -hide_banner -dn -vn -ss 0.00 -i <path_to_video> -af silencedetect=n=0.02:d=0.75 -f null out.null
-
Splits the video into clips, keeping only the segments that are not silent.
ffmpeg -hide_banner -y -loglevel warning -stats -dn -ss 43.621 -to 45.047 -i <path_to_video> -map_metadata -1 -map_chapters -1 -max_muxing_queue_size 99999 -c:a aac -c:v libx264 <path_to_clip>
-
Combines all the clips into a single video.
ffmpeg -hide_banner -y -loglevel warning -stats -f concat -safe 0 -i <path_to_clips_list> -c:a copy -c:v copy <path_to_output_video>