o that just werks

master
bel 2024-09-07 13:55:21 -06:00
parent 91df362af3
commit ddef839399
1 changed files with 50 additions and 66 deletions

View File

@ -3,40 +3,25 @@
set -eo pipefail set -eo pipefail
main() { main() {
local nonrecent_unix="$(($(_date +%s) - 4 * 60 * 60))" # 4h ago local nonrecent_unix="$(($(_date +%s) - 10 * 60))" # 10m ago
local nonrecent_ts="$(_date -d @$nonrecent_unix -u +%Y-%m-%dT%H:%M:%SZ)" local nonrecent_ts="$(_date -d @$nonrecent_unix -u +%Y-%m-%d_%H-%M-%S)"
for uuid in $( for recording in $(
api /api/ | jq -r .cameras[].uuid api "/api/recording/query?recording-id=9999-12-28_23-59-59_x&limit=10000&reverse=false&include-data=false" \
| jq -r .[].id \
| sort
); do ); do
local stream=main if [[ "$recording" > "$nonrecent_ts" ]]; then
local recordings=($(
api /api/cameras/$uuid/$stream/recordings \
| jq -c '.recordings[] | [.startId, .growing, .startTime90k]' \
| grep -v ,true, \
| jq -r .[0] \
| sort -n #-r
))
for recording in "${recordings[@]}"; do
if grep "^$uuid.$recording$" ${MOONFIRE_DIR:-/tmp}/movement_detection_via_api_ffmpeg.sh.txt; then
continue
fi
local ts="$(_date -u -d @"$(
api "/api/cameras/$uuid/$stream/view.mp4.txt?s=$recording&ts=true" \
| grep -A 1 last_modified: \
| head -n 2 \
| tail -n 1 \
| awk '{print $NF}' \
| tr -d ','
)" +%Y-%m-%dT%H:%M:%SZ )"
if [ -z "$ts" ] || [[ "$ts" > "$nonrecent_ts" ]]; then
echo "$ts > $nonrecent_ts, so skipping" echo "$ts > $nonrecent_ts, so skipping"
continue continue
fi fi
echo uuid=$uuid stream=$stream recording=$recording ts=$ts if grep "^$recording$" ${SENTRYSHOT_DIR:-/tmp}/movement_detection_via_api_ffmpeg.sh.txt; then
api "/api/cameras/$uuid/$stream/view.mp4?s=$recording&ts=true" > /tmp/movement_detection_via_api_ffmpeg.sh.mp4 continue
fi
echo recording=$recording >&2
api "/api/recording/video/$recording" > /tmp/movement_detection_via_api_ffmpeg.sh.mp4
local fps=$(_ffprobe -i /tmp/movement_detection_via_api_ffmpeg.sh.mp4 2>&1 | grep -o '[0-9]*\.*[0-9]* fps' | head -n 1 | awk '{print $1}') local fps=$(_ffprobe -i /tmp/movement_detection_via_api_ffmpeg.sh.mp4 2>&1 | grep -o '[0-9]*\.*[0-9]* fps' | head -n 1 | awk '{print $1}')
local inspection="$(_ffmpeg -i /tmp/movement_detection_via_api_ffmpeg.sh.mp4 -vf 'select=not(mod(n\,'${fps%.*}')),select=gte(scene\,0),metadata=print:file=-' -an -f null - 2> /dev/null | paste - -)" local inspection="$(_ffmpeg -i /tmp/movement_detection_via_api_ffmpeg.sh.mp4 -vf 'select=not(mod(n\,'${fps%.*}')),select=gte(scene\,0),metadata=print:file=-' -an -f null - 2> /dev/null | paste - -)"
@ -56,29 +41,28 @@ main() {
threshold="$max_of_last_n" threshold="$max_of_last_n"
fi fi
done done
threshold="$(_perl -e "print $threshold + 0.01")" threshold="$(_perl -e "print $threshold + 0.005")"
local has_change=false local has_change=false
if [ "${#flattened_scores[@]}" -lt 10 ]; then if [ "${#flattened_scores[@]}" -lt 10 ]; then
echo too short >&2
has_change=true has_change=true
else else
local max_flattened_score=$(echo "${flattened_scores[@]:5:${#flattened_scores[@]}-10}" | tr ' ' '\n' | sort -n | tail -n 1) local max_flattened_score=$(echo "${flattened_scores[@]:5:${#flattened_scores[@]}-10}" | tr ' ' '\n' | sort -n | tail -n 1)
echo "${max_flattened_score#*.} > ${threshold#*.}"
if [[ "${max_flattened_score#*.}" > "${threshold#*.}" ]]; then if [[ "${max_flattened_score#*.}" > "${threshold#*.}" ]]; then
has_change=true has_change=true
fi fi
fi fi
if $has_change; then if $has_change; then
echo "$uuid.$recording" >> ${MOONFIRE_DIR:-/tmp}/movement_detection_via_api_ffmpeg.sh.txt echo "$recording" >> ${SENTRYSHOT_DIR:-/tmp}/movement_detection_via_api_ffmpeg.sh.txt
else else
echo no movement in "$recording" echo no movement in "$recording"
api "/api/cameras/$uuid/$stream/view.mp4" \ api "/api/recording/delete/$recording" \
-X DELETE \ -X DELETE
-H 'Content-Type: application/json' \
-d "$(printf '{"runStartId": %s}' "$recording")"
fi fi
done done
done
} }
api() { api() {