diff --git a/testdata/moonfire-nvr/movement_detection_via_api_ffmpeg.sh b/testdata/moonfire-nvr/movement_detection_via_api_ffmpeg.sh index c051208..919c7aa 100644 --- a/testdata/moonfire-nvr/movement_detection_via_api_ffmpeg.sh +++ b/testdata/moonfire-nvr/movement_detection_via_api_ffmpeg.sh @@ -1,7 +1,7 @@ #! /bin/bash main() { - local nonrecent_unix="$(($(_date +%s) - 24 * 60 * 60))" # 1d ago + local nonrecent_unix="$(($(_date +%s) - 4 * 60 * 60))" # 4h ago local nonrecent_ts="$(_date -d @$nonrecent_unix -u +%Y-%m-%dT%H:%M:%SZ)" for uuid in $( @@ -54,32 +54,35 @@ main() { threshold="$max_of_last_n" fi done - threshold="$(echo "$threshold + 0.01" | bc)" + threshold="$(perl -e "print $threshold + 0.005")" - local max_flattened_score=$(echo "${flattened_scores[@]:5:${#flattened_scores[@]}-10}" | tr ' ' '\n' | sort -n | tail -n 1) local has_change=false - if [[ "${max_flattened_score#*.}" > "${threshold#*.}" ]]; then + if [ "${#flattened_scores[@]}" -lt 10 ]; then has_change=true + else + local max_flattened_score=$(echo "${flattened_scores[@]:5:${#flattened_scores[@]}-10}" | tr ' ' '\n' | sort -n | tail -n 1) + if [[ "${max_flattened_score#*.}" > "${threshold#*.}" ]]; then + has_change=true + fi fi if $has_change; then echo "$uuid.$recording" >> /tmp/movement_detection_via_api_ffmpeg.sh.txt else echo no movement in "$recording" - api "/api/cameras/$uuid/$stream/view.mp4" \ + echo api "/api/cameras/$uuid/$stream/view.mp4" \ -X DELETE \ -H 'Content-Type: application/json' \ -d "$(printf '{"runStartId": %s}' "$recording")" fi done - break done } api() { local path="$1" shift - curl -sS "${CAMS_URL:-https://cams.inhome.blapointe.com}/${path#/}" "$@" + curl -sS "${CAMS_URL:-http://192.168.0.86:29898}/${path#/}" "$@" } _date() {