Skip to content

Commit dc9b5db

Browse files
committed
initial commit
0 parents  commit dc9b5db

5 files changed

Lines changed: 52 additions & 0 deletions

File tree

cleanup.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#/bin/sh
2+
3+
## delete anything older than 3 days
4+
## assumes folder structure like /base/cameras/location/room
5+
find /base/path/to/recordings/*/*/*/ -type d -mtime +7 -exec rm -rf {} \;
6+
7+

location-room.service

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[Unit]
2+
DefaultDependencies=no
3+
After=network.target
4+
5+
[Service]
6+
Type=simple
7+
Environment="REC_SCRIPT=/path/to/script/record_location_room.sh"
8+
Restart=always
9+
RestartSec=3
10+
User=your-user
11+
Group=your-group
12+
ExecStart=/bin/bash /path/to/script/watchdog.sh
13+
TimeoutStartSec=0
14+
WatchdogSec=16
15+
NotifyAccess=all
16+
17+
[Install]
18+
WantedBy=default.target
19+

record_location_room.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
TS_DAY=$(date +%Y_%m_%d)
2+
mkdir -p -- /base/cameras/location/room/
3+
ffmpeg -rtsp_transport tcp -i rtsp://your-rtsp-url -c copy -acodec aac -f mpegts - >> /base/cameras/location/room/$TS_DAY.ts
4+

remux_previous_day.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
file_name=$(date --date="yesterday" +%Y_%m_%d)
2+
for location_name in /base/cameras/*/* ; do
3+
ffmpeg -i ${location_name}/${file_name}.ts -c copy ${location_name}/${file_name}.mp4 && rm ${location_name}/${file_name}.ts
4+
done
5+

watchdog.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
ROOT_PID=$$
3+
eval ${REC_SCRIPT} &
4+
5+
while(true); do
6+
REC_PID=$(pstree -hp $ROOT_PID | grep -oP "ffmpeg\(\K\d+")
7+
LIVE=0
8+
test `stat -L -c %Y /proc/${REC_PID}/fd/1` -ge $(($EPOCHSECONDS - 10)) && LIVE=1
9+
10+
if [[ $LIVE -eq 1 ]]; then
11+
/bin/systemd-notify WATCHDOG=1;
12+
sleep $(($WATCHDOG_USEC / 2000000))
13+
else
14+
sleep 1
15+
fi
16+
done
17+

0 commit comments

Comments
 (0)