cctv/run.sh

61 lines
1.1 KiB
Bash

#! /bin/bash
function main() {
if [ "$#" -eq 0 ]; then
echo "USAGE: $0 ip ip ip..." >&2
return 1
fi
function clean() {
kill -9 $(jobs -p)
}
trap clean EXIT ERR
for ip in "$@"; do
echo recording from $ip...
record "$ip" &
done
for i in "$@"; do
if ! wait -n 1; then
echo "Something died: $?" >&2
return 1
fi
return 0
done
}
function record() {
while true; do
_record "$@"
sleep 10
done
}
function _record() {
ffmpeg \
-threads 0 \
-nostdin \
-nostats \
-loglevel error \
-i rtsp://192.168.0.$1:8554/unicast \
-an \
-map 0 \
-force_key_frames "expr:gte(t,n_forced*9)" \
-f segment \
-segment_time ${SEG:-300} \
-segment_format mp4 \
-strftime 1 \
-minrate .05k \
-vcodec copy \
"${OUT_DIR:-/tmp/ffmpeg_cap}/cap-$1-%Y%m%d_%H%M%S.mp4" \
-vf "select=gt(scene\,0.003),setpts=N/(15*TB)" \
< /dev/null \
>> /tmp/ffmpegs.log \
2>&1
}
if [ "$0" == "$BASH_SOURCE" ]; then
main "$@"
fi