reduce
parent
74672a5e90
commit
c21a1506b7
|
|
@ -7,22 +7,21 @@ main() {
|
||||||
for uuid in $(
|
for uuid in $(
|
||||||
api /api/ | jq -r .cameras[].uuid
|
api /api/ | jq -r .cameras[].uuid
|
||||||
); do
|
); do
|
||||||
local streams=(main sub)
|
local stream=main
|
||||||
local recordings=($(
|
local recordings=($(
|
||||||
api /api/cameras/$uuid/$streams/recordings \
|
api /api/cameras/$uuid/$stream/recordings \
|
||||||
| jq -c '.recordings[] | [.startId, .growing, .startTime90k]' \
|
| jq -c '.recordings[] | [.startId, .growing, .startTime90k]' \
|
||||||
| grep -v ,true, \
|
| grep -v ,true, \
|
||||||
| jq -r .[0] \
|
| jq -r .[0] \
|
||||||
| sort -n #-r
|
| sort -n #-r
|
||||||
))
|
))
|
||||||
for recording_idx in $(seq 1 ${#recordings[@]}); do
|
for recording in "${recordings[@]}"; do
|
||||||
local recording=${recordings[recording_idx-1]}
|
|
||||||
if grep "^$uuid.$recording$" /tmp/movement_detection_via_api_ffmpeg.sh.txt; then
|
if grep "^$uuid.$recording$" /tmp/movement_detection_via_api_ffmpeg.sh.txt; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local ts="$(_date -u -d @"$(
|
local ts="$(_date -u -d @"$(
|
||||||
api "/api/cameras/$uuid/$streams/view.mp4.txt?s=$recording&ts=true" \
|
api "/api/cameras/$uuid/$stream/view.mp4.txt?s=$recording&ts=true" \
|
||||||
| grep -A 1 last_modified: \
|
| grep -A 1 last_modified: \
|
||||||
| head -n 2 \
|
| head -n 2 \
|
||||||
| tail -n 1 \
|
| tail -n 1 \
|
||||||
|
|
@ -34,16 +33,9 @@ main() {
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo uuid=$uuid stream=$streams recording=$recording ts=$ts
|
echo uuid=$uuid stream=$stream recording=$recording ts=$ts
|
||||||
api "/api/cameras/$uuid/$streams/view.mp4?s=$recording&ts=true" > /tmp/movement_detection_via_api_ffmpeg.sh.mp4
|
api "/api/cameras/$uuid/$stream/view.mp4?s=$recording&ts=true" > /tmp/movement_detection_via_api_ffmpeg.sh.mp4
|
||||||
|
|
||||||
local has_change=false
|
|
||||||
local cksum="$(cksum /tmp/movement_detection_via_api_ffmpeg.sh.mp4)"
|
|
||||||
if grep "^$cksum$" /tmp/movement_detection_via_api_ffmpeg.sh.txt; then
|
|
||||||
has_change=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! $has_change; then
|
|
||||||
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 - -)"
|
||||||
local scores=($(echo "$inspection" | awk '{print $NF}' | sed 's/.*=//'))
|
local scores=($(echo "$inspection" | awk '{print $NF}' | sed 's/.*=//'))
|
||||||
|
|
@ -65,22 +57,19 @@ main() {
|
||||||
threshold="$(echo "$threshold + 0.01" | bc)"
|
threshold="$(echo "$threshold + 0.01" | bc)"
|
||||||
|
|
||||||
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)
|
||||||
|
local has_change=false
|
||||||
if [[ "${max_flattened_score#*.}" > "${threshold#*.}" ]]; then
|
if [[ "${max_flattened_score#*.}" > "${threshold#*.}" ]]; then
|
||||||
has_change=true
|
has_change=true
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
if $has_change; then
|
if $has_change; then
|
||||||
echo "$uuid.$recording" >> /tmp/movement_detection_via_api_ffmpeg.sh.txt
|
echo "$uuid.$recording" >> /tmp/movement_detection_via_api_ffmpeg.sh.txt
|
||||||
echo "$cksum" >> /tmp/movement_detection_via_api_ffmpeg.sh.txt
|
|
||||||
else
|
else
|
||||||
echo no movement in "$recording"
|
echo no movement in "$recording"
|
||||||
for stream in ${streams[@]}; do
|
|
||||||
api "/api/cameras/$uuid/$stream/view.mp4" \
|
api "/api/cameras/$uuid/$stream/view.mp4" \
|
||||||
-X DELETE \
|
-X DELETE \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
-d "$(printf '{"runStartId": %s}' "$recording")"
|
-d "$(printf '{"runStartId": %s}' "$recording")"
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
break
|
break
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue