forked from phoboslab/jsmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·162 lines (150 loc) · 3.72 KB
/
init.sh
File metadata and controls
executable file
·162 lines (150 loc) · 3.72 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/sh
DIR_JSMPEG=/root/jsmpeg
LOG=/var/tmp/jsmpeg_rc.log
display_help() {
echo "Usage: $0 rtsp_ip rtsp_port ws_relay_port_src ws_relay_port_dst" >&2
exit 1
}
run_jobs() {
echo nohup http-server ${DIR_JSMPEG} -p ${http_server_port} --cgi >> ${LOG}
nohup http-server ${DIR_JSMPEG} -p ${http_server_port} --cgi >/dev/null 2>&1 &
echo nohup node ${DIR_JSMPEG}/websocket-relay.js supersecret ${ws_relay_port_src} ${ws_relay_port_dst} >> ${LOG}
nohup node ${DIR_JSMPEG}/websocket-relay.js supersecret ${ws_relay_port_src} ${ws_relay_port_dst} >/dev/null 2>&1 &
echo PORT=${http_upload_port} UPLOAD_DIR=${DIR_JSMPEG} UPLOAD_TMP_DIR=/tmp/ http-server-upload >> ${LOG}
PORT=${http_upload_port} UPLOAD_DIR=${DIR_JSMPEG} UPLOAD_TMP_DIR=/tmp/ http-server-upload >/dev/null 2>&1 &
while true
do
curl -v -X DESCRIBE -m 3 $URL_RTSP > /dev/null 2>&1
if [ "$?" -eq 0 ]; then
if [ "$PLATFORM" = "nvds" ]; then
ffmpeg -nostdin -i $URL_RTSP -f mpegts -codec:v mpeg1video "http://${HOST_IP}:${ws_relay_port_src}/supersecret" >/dev/null 2>&1
else
ffmpeg -nostdin -rtsp_transport tcp -i $URL_RTSP -r 30 -q 0 -f mpegts -codec:v mpeg1video "http://${HOST_IP}:${ws_relay_port_src}/supersecret" >/dev/null 2>&1
fi
sleep 1
else
sleep 3
fi
done
}
arg_rtsp_ip=
arg_rtsp_port=
arg_ws_relay_port_src=
arg_ws_relay_port_dst=
arg_rtsp_url_path=
cat /dev/null > ${LOG}
echo "arg number $#" >> ${LOG}
echo "args $@" >> ${LOG}
while [[ "$#" -gt 0 ]]; do
echo "handle arg $1 value $2" >> ${LOG}
case "$1" in
-h | --help)
display_help
exit 0
;;
-p | --platform)
if [ -n "$2" ]; then
case "$2" in
-*)
echo "argument platform have no value!!!" >> ${LOG}
exit 1
;;
*)
PLATFORM=${2}
rm -f /root/jsmpeg/index.html
ln -s /root/jsmpeg/platform/${2}/index.html /root/jsmpeg/index.html
rm -f /root/jsmpeg/env.json
ln -s /root/jsmpeg/platform/${2}/env.json /root/jsmpeg/env.json
shift ;;
esac
fi
shift
;;
--rtsp_ip)
if [ -n "$2" ]; then
case "$2" in
-*) ;;
*)
arg_rtsp_ip=${2}
shift ;;
esac
fi
shift
;;
--rtsp_port)
if [ -n "$2" ]; then
case "$2" in
-*) ;;
*)
arg_rtsp_port=${2}
shift ;;
esac
fi
shift
;;
--ws_relay_port_src)
if [ -n "$2" ]; then
case "$2" in
-*) ;;
*)
arg_ws_relay_port_src=${2}
shift ;;
esac
fi
shift
;;
--ws_relay_port_dst)
if [ -n "$2" ]; then
case "$2" in
-*) ;;
*)
arg_ws_relay_port_dst=${2}
shift ;;
esac
fi
shift
;;
--rtsp_url_path)
if [ -n "$2" ]; then
case "$2" in
-*) ;;
*)
arg_rtsp_url_path=${2}
shift ;;
esac
fi
shift
;;
*)
shift
;;
esac
done
while [ ! -f "${DIR_JSMPEG}/env.json" ]
do
sleep 3
done
echo "Use ${DIR_JSMPEG}/env.json" >> ${LOG}
for s in $(jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ${DIR_JSMPEG}/env.json); do
echo $s >> ${LOG}
export $s
done
[ -n "$arg_rtsp_ip" ] && rtsp_ip=$arg_rtsp_ip
[ -n "$arg_rtsp_port" ] && rtsp_port=$arg_rtsp_port
[ -n "$arg_ws_relay_port_src" ] && ws_relay_port_src=$arg_ws_relay_port_src
[ -n "$arg_ws_relay_port_dst" ] && ws_relay_port_dst=$arg_ws_relay_port_dst
[ -n "$arg_rtsp_url_path" ] && rtsp_url_path=$arg_rtsp_url_path
DEFAULT_ROUTE=$(ip route show default | awk '/default/ {print $3}')
echo DEFAULT_ROUTE=${DEFAULT_ROUTE} >> ${LOG}
if [ ! -z "${DEFAULT_ROUTE}" ]; then
HOST_IP=${DEFAULT_ROUTE}
else
HOST_IP="127.0.0.1"
fi
if [ -z "${rtsp_ip}" ]; then
rtsp_ip=${HOST_IP}
fi
URL_RTSP="rtsp://${rtsp_ip}:${rtsp_port}/${rtsp_url_path}"
echo ${URL_RTSP} >> ${LOG}
killall node ffmpeg http-server http-server-upload >/dev/null 2>&1
run_jobs