summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthomas grothe <thomas@debian>2023-10-31 08:38:30 -0500
committerthomas grothe <thomas@debian>2023-10-31 08:38:30 -0500
commit20ae6cb48ef3ccb80300580b54b7dcc4c7419dc5 (patch)
tree7230ffe473f32265c460c16f4457f6c8c7f47931
parent7ba2f6677e74c86f3e226b5b1f21ff9a26a29b04 (diff)
added security camera scripts
-rwxr-xr-xcapture.sh33
-rwxr-xr-ximgs2vid.sh10
-rwxr-xr-xsave.sh14
3 files changed, 57 insertions, 0 deletions
diff --git a/capture.sh b/capture.sh
new file mode 100755
index 0000000..1043c88
--- /dev/null
+++ b/capture.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+#this script repeatedly captures images from a video device (e.g. /dev/video0) at regular intervals
+#and it compresses images into an .tar.gz after some number and deletes those images
+#and it deletes old archives after some number have been made
+
+MAX_SIZE=1073741824 #1G in bytes
+TIME_INTERVAL=15 #seconds between taking snapshots
+THRESHOLD_ARCHIVE=5760 #number of images after which archiving should be done. 5760 is one day if pics are every 15s
+THRESHOLD_REMOVE=30 #number of image archive tarballs after which a handful of the oldest archives will be deleted
+
+while [[ true ]]; do
+ d=`date +%Y%m%d_%H%M%S`
+ snapshot ${d}.png
+ ln -snf ${d}.png current.png
+ sleep ${TIME_INTERVAL}
+ if [[ `find . -maxdepth 1 -name "*png" | wc -l` -gt ${THRESHOLD_ARCHIVE} ]]; then
+ #if [[ `ls *png | wc -l` -gt ${THRESHOLD_ARCHIVE} ]]; then
+ echo "time to archive captured images"
+ mkdir archive${d}
+ mv *png archive${d}/
+ tar -czvf archive${d}.tar.gz archive${d}/*
+ echo "archive made. images compressed. now deleting source files."
+ rm -rf archive${d}
+ fi
+ if [[ `ls archive* 2&>/dev/null | wc -l` -gt ${THRESHOLD_REMOVE} ]]; then
+ echo "time to remove some old archived image sets"
+ rm `ls -t . | grep archive | tail -n 5` -rf
+ fi
+done
+
+
+#if [ `du . -b | awk '{print $1}'` -gt ${MAX_SIZE} ]; then
+
diff --git a/imgs2vid.sh b/imgs2vid.sh
new file mode 100755
index 0000000..a773ebe
--- /dev/null
+++ b/imgs2vid.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+#take a bunch of image files and turn them into a video
+
+if [[ ${#} != 2 ]]; then
+ echo "provide file pattern and destination filename"
+ exit 0
+fi
+echo $@
+echo "THIS IS SCRIPT IS NOT CURRENTLY WORKING"
+ffmpeg -framerate 8 -pattern_type glob -i "${1}" "${2}"
diff --git a/save.sh b/save.sh
new file mode 100755
index 0000000..7419c2b
--- /dev/null
+++ b/save.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+#security camera companion script
+#move recent images into a folder so they aren't deleted
+
+if [[ $1 ]]; then
+ n=${1}
+else
+ n=40
+fi
+
+mv `ls -rt *png | tail -n ${n}` save/
+chmod a-w save/*png
+#chmod a-w `ls -tr *png | tail -n ${n}`
+