Last active
October 8, 2022 09:36
-
-
Save snevas/9dc151dea0dc2cdcbe5032bd6026a1b4 to your computer and use it in GitHub Desktop.
RTSP offshore unifi protect cam stream backup with systemd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Made into systemd service with https://northernlightlabs.se/2014-07-05/systemd-status-mail-on-unit-failure.html and added: | |
ExecStartPre=-/usr/bin/docker stop unifi-cam1 | |
ExecStop=/usr/bin/docker stop unifi-cam1 | |
ExecStopPost=/bin/sleep 20 | |
Cleanup with cron: | |
ls -1t /path/cam1-*.mp4 | tail -n +672 | xargs rm -f | |
#!/bin/bash | |
watchdog() { | |
PID=$1 | |
while(true); do | |
FAIL=0 | |
find /output -type f -mmin -15 -name 'cam1-*.mp4' | grep -q . || FAIL=1 | |
if [[ $FAIL -eq 0 ]]; then | |
/bin/systemd-notify WATCHDOG=1; | |
sleep $(($WATCHDOG_USEC / 2000000)) | |
else | |
sleep $(($WATCHDOG_USEC / 4000000)) | |
fi | |
done | |
} | |
watchdog $$ & | |
docker run --name unifi-cam1 --rm -e TZ=Europe/Amsterdam -v /path:/output linuxserver/ffmpeg -rtsp_transport tcp -re -i rtsp://external_ip:7447/cam_token -vcodec copy -acodec copy -f mp4 -f segment -segment_time 900 -segment_atclocktime 1 -strftime 1 -reset_timestamps 1 output/cam1-%Y%m%d-%H%M%S.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment