✨ initial commit
commit
7773dac89e
@ -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())))
|
@ -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 </dev/null | sed 's/\r/\n/g' >silence/"$f".txt
|
||||
fi
|
||||
done
|
Loading…
Reference in New Issue