Last active
November 21, 2020 11:52
-
-
Save samunders-core/b6046af149f5e28b8fcb424f307e1258 to your computer and use it in GitHub Desktop.
Self-contained OpenWRT crontab for IP camera records management
This file contains hidden or 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
# #ffmpeg | |
# SECONDS=900 | |
# DURATION=$(($(date "+$SECONDS-(%M%%15)*60-%S"))) | |
## tcp transport ensures bottom half of frame is not pixelated | |
# PRE_IN="-t $DURATION -rtsp_transport tcp" | |
# LOGIN= | |
# PASSWORD= | |
# IP= | |
# IN=rtsp://$LOGIN${PASSWORD:+:$PASSWORD}@$IP:554/mpeg4 | |
# START="$(date '+%Y%m%d_%H%M%S')" | |
# META="-metadata title=$START" | |
# FLAGS="-an -vcodec copy $META -bsf hevc_mp4toannexb -f mp4" | |
# OUT="/records/$START.mp4" | |
# PID=$(pgrep ffmpeg) && { | |
# du -h "$(tr '\0' '\n' < /proc/$PID/cmdline | tail -1)" | logger -t ffmpeg | |
# [ "$DURATION" -lt "$(($SECONDS-10))" ] && exit 0 | |
# } | |
# logger -t ffmpeg ffmpeg $PRE_IN -i "$IN" $FLAGS "$OUT" | |
# exec ffmpeg $PRE_IN -i "$IN" $FLAGS "$OUT" #2> "${OUT%/*}/.${OUT##*/}.stderr" | |
## $'\43' works around busybox's logging of cron command only up to first # | |
* * * * * C=ffmpeg && H=$'\043' && crontab -l | sed -nre "/^$H $H$C/,/^$H exec $C /{s/^$H *//;p}" | sh > /dev/null 2>&1 & | |
# delete hour-sized batches once 90% disk usage is exceeded | |
1 * * * * D=/records && while df -P "$D" | awk '-F[ %]+' '{f=NR>1 && $5 > 90} END{exit 1-f}' && ls -1rtc "$D" | head -4 | xargs -t rm ; do true ; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment