summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-05-24 22:26:02 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-05-24 23:18:11 +0300
commitc75812751eaa50cd6ea005dd6ca3c1a39c4d74dc (patch)
tree0c919c6cbd7e0f50af361dea94a2004958498ff4
parent00427d1b252474abde7de40588688ec2cea99185 (diff)
ipcam_capture stuff
-rw-r--r--systemd/ipcam_capture@.service13
-rwxr-xr-xtools/ipcam_capture.sh91
2 files changed, 104 insertions, 0 deletions
diff --git a/systemd/ipcam_capture@.service b/systemd/ipcam_capture@.service
new file mode 100644
index 0000000..e87e09c
--- /dev/null
+++ b/systemd/ipcam_capture@.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=save ipcam streams
+After=network-online.target
+
+[Service]
+Restart=always
+User=user
+Group=user
+EnvironmentFile=/etc/ipcam_capture.conf.d/%i.conf
+ExecStart=/home/user/homekit/tools/ipcam_capture.sh --outdir $OUTDIR --creds $CREDS --ip $IP --port $PORT $ARGS
+
+[Install]
+WantedBy=multi-user.target
diff --git a/tools/ipcam_capture.sh b/tools/ipcam_capture.sh
new file mode 100755
index 0000000..d96c06f
--- /dev/null
+++ b/tools/ipcam_capture.sh
@@ -0,0 +1,91 @@
+#!/bin/bash
+
+PROGNAME="$0"
+PORT=554
+IP=
+CREDS=
+DEBUG=0
+CHANNEL=1
+
+die() {
+ echo >&2 "error: $@"
+ exit 1
+}
+
+usage() {
+ cat <<EOF
+usage: $PROGNAME [OPTIONS] COMMAND
+
+Options:
+ --outdir output directory
+ --ip camera IP
+ --port RTSP port (default: 554)
+ --creds
+ --debug
+ --channel 1|2
+
+EOF
+ exit
+}
+
+validate_channel() {
+ local c="$1"
+ case "$c" in
+ 1|2)
+ :
+ ;;
+ *)
+ die "Invalid channel"
+ ;;
+ esac
+}
+
+[ -z "$1" ] && usage
+
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --ip|--port|--creds|--outdir)
+ _var=${1:2}
+ _var=${_var^^}
+ printf -v "$_var" '%s' "$2"
+ shift
+ ;;
+
+ --debug)
+ DEBUG=1
+ ;;
+
+ --channel)
+ CHANNEL="$2"
+ shift
+ ;;
+
+ *)
+ die "Unrecognized argument: $1"
+ ;;
+ esac
+ shift
+done
+
+[ -z "$OUTDIR" ] && die "You must specify output directory (--outdir)."
+[ -z "$IP" ] && die "You must specify camera IP address (--ip)."
+[ -z "$PORT" ] && die "Port can't be empty."
+[ -z "$CREDS" ] && die "You must specify credentials (--creds)."
+validate_channel "$CHANNEL"
+
+if [ ! -d "${OUTDIR}" ]; then
+ mkdir "${OUTDIR}" || die "Failed to create ${OUTDIR}/${NAME}!"
+ echo "Created $OUTDIR."
+fi
+
+if [ "$DEBUG" = "1" ]; then
+ args="-v info"
+else
+ args="-nostats -loglevel warning"
+fi
+
+[ ! -z "$CREDS" ] && CREDS="${CREDS}@"
+
+ffmpeg $args -i rtsp://${CREDS}${IP}:${PORT}/Streaming/Channels/${CHANNEL} \
+ -c copy -f segment -strftime 1 -segment_time 00:10:00 -segment_atclocktime 1 \
+ "$OUTDIR/record_%Y-%m-%d-%H.%M.%S.mp4"