Catch no recent recordings and disk cap

master
bel 2020-04-16 01:00:38 +00:00
parent cf749e7326
commit 60c011278f
12 changed files with 61 additions and 14 deletions

View File

@ -1,47 +1,94 @@
#! /bin/bash #! /bin/bash
SEG="${SEG:-300}"
function main() { function main() {
if [ "$#" -eq 0 ]; then if [ "$#" -eq 0 ]; then
echo "USAGE: $0 ip ip ip..." >&2 log "USAGE: $0 ip ip ip..." >&2
return 1 return 1
fi fi
function clean() { function clean() {
kill -9 $(jobs -p) kill -9 $(jobs -p)
} }
if [ "$(hostname)" == "Scratch" ]; then
trap clean EXIT ERR trap clean EXIT ERR
mkdirs & fi
watchman "$@" &
for ip in "$@"; do for ip in "$@"; do
echo recording from $ip... log recording from $ip...
record "$ip" & record "$ip" &
done done
for i in "$@"; do for i in "$@"; do
if ! wait -n 1; then if ! wait -n 1; then
echo "Something died: $?" >&2 log "Something died: $?"
exit 1 exit 1
fi fi
exit 0 exit 0
done done
} }
function log() {
echo "$(date): $@" >&2
}
function mkdirs() { function mkdirs() {
while sleep 10; do
mkdir -p "${OUT_DIR:-/tmp/ffmpeg_cap}/$(date +%Y)/$(date +%m)/$(date +%d)" mkdir -p "${OUT_DIR:-/tmp/ffmpeg_cap}/$(date +%Y)/$(date +%m)/$(date +%d)"
}
function watchman() {
log watchman starting on $@
local max_last=$SEG
max_last=$((max_last*3))
function finder() {
local suffix="${1:-"*"}"
find "${OUT_DIR:-/tmp/ffmpeg_cap}" -type f -name "*_${suffix}.m*"
}
function mark_last_file() {
local now="$(date +%s)"
local suffix="$1"
local min=$((max_last-1))
for f in $(finder "$suffix"); do
local ts="$(stat -c '%X' "$f")"
if ((now-ts<min)); then
min=$((now-ts))
fi
done
echo $min
}
function check_disk() {
if du -s "${OUT_DIR:-/tmp/ffmpeg_cap}" | grep -E '^[6-9][0-9]{5}'; then
return 1
fi
}
while sleep 10; do
mkdirs
for suffix in "$@"; do
local seconds=$(mark_last_file "$suffix")
log "$suffix: $seconds s"
if ((seconds>max_last)); then
log "no new videos in $seconds seconds for $suffix, panicking"
exit 1
fi
done
until check_disk; do
local f="$(finder | sort | head -n 1)"
log "high disk usage, pruning $f"
rm -f "$f"
done
done done
} }
function record() { function record() {
while true; do log "starting record for $@"
echo "starting record for $@"
_record "$@" _record "$@"
sleep 10 tail -n 50 /tmp/ffmpegs.log
done
} }
function _record() { function _record() {
local out="${OUT_DIR:-/tmp/ffmpeg_cap}/%Y/%m/%d/%H-%M-%S_$1.mp4" local out="${OUT_DIR:-/tmp/ffmpeg_cap}/%Y/%m/%d/%H-%M-%S_${1}.mp4"
mkdirs
ffmpeg \ ffmpeg \
-threads 0 \ -threads 0 \
-nostdin \ -nostdin \
@ -52,7 +99,7 @@ function _record() {
-map 0 \ -map 0 \
-force_key_frames "expr:gte(t,n_forced*9)" \ -force_key_frames "expr:gte(t,n_forced*9)" \
-f segment \ -f segment \
-segment_time ${SEG:-300} \ -segment_time $SEG \
-segment_format mp4 \ -segment_format mp4 \
-strftime 1 \ -strftime 1 \
-minrate .05k \ -minrate .05k \

0
testdata/ffmpeg/ffmpegs.log vendored Normal file → Executable file
View File

0
testdata/ffmpeg/log vendored Normal file → Executable file
View File

0
testdata/ffmpeg/run.sh vendored Normal file → Executable file
View File

0
testdata/motion/cameras/wyze0.conf vendored Normal file → Executable file
View File

0
testdata/motion/cameras/wyze1.conf vendored Normal file → Executable file
View File

0
testdata/motion/cameras/wyze2.conf vendored Normal file → Executable file
View File

0
testdata/motion/cameras/wyze3.conf vendored Normal file → Executable file
View File

0
testdata/motion/motion.conf vendored Normal file → Executable file
View File

0
testdata/motion/run.sh vendored Normal file → Executable file
View File

0
testdata/openrtsp/install.sh vendored Normal file → Executable file
View File

0
testdata/openrtsp/run.sh vendored Normal file → Executable file
View File