From 45d32dff7ddc4611faa79d0d72c8ac4c0d967480 Mon Sep 17 00:00:00 2001 From: Nemo Date: Mon, 26 Oct 2020 23:22:24 +0530 Subject: [PATCH] Keep stuff in README --- README.md | 1 + split-by-silence | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 split-by-silence diff --git a/README.md b/README.md index 3bd271e..4385931 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ This lives in my `~/projects/scripts` directory and is added to my `$PATH`. Not | plutil.pl | implementation of binary/UTF-8 (text) XML conversion of plist files | | port_block_check.sh | Run this behind a firewall to see if there are any outbound ports that are blocked | | prettyping | Third-party, runs a nice graphical ping | +| pulse-recorder.py | Records a [pulse audio stream easily](https://gist.github.com/ramast/c47bd5e57586e9c2deb74975e27089f0/). | resty | Third-party. A tiny command line REST interface for bash and zsh. | | reverse_video.sh | Reverse a video | | rip-git.pl | Third-party. Brute force and download a publicly exposed .git directory | diff --git a/split-by-silence b/split-by-silence new file mode 100755 index 0000000..c444508 --- /dev/null +++ b/split-by-silence @@ -0,0 +1,43 @@ +#!/bin/bash + +# Source: https://gist.github.com/vi/2fe3eb63383fcfdad7483ac7c97e9deb + +IN=$1 +OUT=$2 + +true ${SD_PARAMS:="-55dB:d=0.3"}; +true ${MIN_FRAGMENT_DURATION:="20"}; +export MIN_FRAGMENT_DURATION + +if [ -z "$OUT" ]; then + echo "Usage: split_by_silence.sh input_media.mp4 output_template_%03d.mkv" + echo "Depends on FFmpeg, Bash, Awk, Perl 5. Not tested on Mac or Windows." + echo "" + echo "Environment variables (with their current values):" + echo " SD_PARAMS=$SD_PARAMS Parameters for FFmpeg's silencedetect filter: noise tolerance and minimal silence duration" + echo " MIN_FRAGMENT_DURATION=$MIN_FRAGMENT_DURATION Minimal fragment duration" + exit 1 +fi + +echo "Determining split points..." >& 2 + +SPLITS=$( + ffmpeg -v warning -i "$IN" -af silencedetect,ametadata=mode=print:file=-:key=lavfi.silence_start -vn -sn -f s16le -y /dev/null \ + | grep lavfi.silence_start= \ + | cut -f 2-2 -d= \ + | perl -ne ' + our $prev; + INIT { $prev = 0.0; } + chomp; + if (($_ - $prev) >= $ENV{MIN_FRAGMENT_DURATION}) { + print "$_,"; + $prev = $_; + } + ' \ + | sed 's!,$!!' +) + + +echo "Splitting points are $SPLITS" + +ffmpeg -v warning -i "$IN" -c copy -map 0 -f segment -segment_times "$SPLITS" "$OUT" \ No newline at end of file