-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecord_ffmpeg
More file actions
executable file
·38 lines (35 loc) · 822 Bytes
/
record_ffmpeg
File metadata and controls
executable file
·38 lines (35 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
camera=camera1
# URL standard Intelbras VIP cams
url="rtsp://admin:password@192.168.0.18/cam/realmonitor?channel=1&subtype=0"
segment=800
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
while true; do
time=$(date +%Y%m%d_%H%M%S)
now=$(date +%s)
eta=$(($now + $segment))
movie="./${time}_${camera}.mkv"
echo "Recording $movie..."
ffmpeg -rtsp_transport tcp -t $segment \
-loglevel 16 \
-i "$url" \
-vcodec copy -an -y \
"$movie" &
PID="$!"
while [ -e /proc/$PID ]; do
sleep 1
now=$(date +%s)
remaining=$(($eta - $now))
if [ "$remaining" -lt -10 ]; then
echo "*** WARNING ffmpeg hung up"
kill -9 $PID
sleep 2
fi
done
now=$(date +%s)
remaining=$(($eta - $now))
if [ "$remaining" -gt 0 ]; then
echo "*** WARNING ffmpeg failed or quit early"
sleep 60
fi
done