commit 7773dac89ebad85269ba36cafcf508eaa68e2c1d Author: root Date: Sat Nov 20 00:03:45 2021 +0100 ✨ initial commit diff --git a/silence-report.py b/silence-report.py new file mode 100755 index 0000000..428b345 --- /dev/null +++ b/silence-report.py @@ -0,0 +1,53 @@ +#!/usr/bin/python3 +import os +import glob +import re +from datetime import datetime, timedelta +from pytimeparse.timeparse import timeparse + + +silences = [] + +os.chdir("/srv/recording/silence") +for s in glob.glob("*.txt"): + with open(s, 'r') as f: + t = f.read() + + # parse start time from the filename + start_of_flac = datetime.strptime(s, "%Y-%m-%d_%H-%M-%S.flac.txt") + + + # flacs are not necessarily 1 hour long, but ffmpeg thankfully also writes + # out some timestamps, so we use the last one to determine the length + length_of_flac = None + for l in t.split("\n"): + m = re.match(r"size=.* time=([0-9:.]+) .*", l) + if m: + length_of_flac = timeparse(m.group(1)) + + silence_start = None + for l in t.split("\n"): + m = re.search(r"silence_start: ([-0-9.]+)", l) + if m: + silence_start = float(m.group(1)) + silence_end = length_of_flac # fallback + m = re.search(r"silence_end: ([-0-9.]+)", l) + if m: + silence_end = float(m.group(1)) + silences.append((start_of_flac + timedelta(seconds=silence_start), start_of_flac + timedelta(seconds=silence_end))) + + # reset + silence_start = None + silence_end = length_of_flac + + # if there is no "end of silence", ffmpeg does not report it + if silence_start: + silences.append((start_of_flac + timedelta(seconds=silence_start), start_of_flac + timedelta(seconds=silence_end))) + +silences = sorted(silences) + + +FORMAT="%Y-%m-%d %H:%M:%S" +for silence_start, silence_end in silences: + duration = silence_end - silence_start + print("%s;%s;%d" % (silence_start.strftime(FORMAT), silence_end.strftime(FORMAT), round(duration.total_seconds()))) diff --git a/silence.sh b/silence.sh new file mode 100755 index 0000000..ac08399 --- /dev/null +++ b/silence.sh @@ -0,0 +1,9 @@ +#!/bin/bash +cd /srv/recording + +find -name "*.flac" -mmin +1 | while read f; do + if ! test -e silence/"$f".txt; then + echo "$f" + nice -n19 ffmpeg -hide_banner -i $f -af silencedetect=duration=30 -f null - 2>&1 silence/"$f".txt + fi +done