-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_rtsp_multiport_streamer.sh
executable file
·117 lines (98 loc) · 2.6 KB
/
run_rtsp_multiport_streamer.sh
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
#!/bin/bash
# [[ $# != 1 ]] && echo "Error: Wrong argument list. (e.g.: ./run_rtsp_streamer.sh video.mp4)" && exit 1
videosArray=("$@")
# echo "INFO: videos passed:"
for video in ${videosArray[@]}; do
echo "$video"
done
for video in ${videosArray[@]}; do
if ! [[ -f $video ]]; then
echo "ERROR: '$video' file does not exist."
exit 1
fi
done
# Ports list:
# Change lower ports and port range here:
# firstBroadcastPort=50000
# firstInternalPort=51000
firstBroadcastPort=40000
firstInternalPort=41000
portsRange=30
# Max port value calculate:
lastBroadcastPort=$firstBroadcastPort+$portsRange
lastInternalPort=$firstInternalPort+$portsRange
# Init ports list:
allOuterPorts=( $firstBroadcastPort )
allInerPorts=( $firstInternalPort )
# Fill ports list:
for ((port = $firstBroadcastPort; port <= $lastBroadcastPort; port++)); do
allOuterPorts+=( $port )
#allOuterPorts[${#allOuterPorts[@]}]=$port
done
# echo "All Outer Ports:\n ${allOuterPorts[@]}"
# Fill ports list:
for ((port = $firstInternalPort; port <= $lastInternalPort; port++)); do
allInerPorts+=( $port )
done
# echo "All Inner Ports:\n ${allInerPorts[@]}"
# Check availiable ports:
function innerPorts() {
for item in ${allOuterPorts[@]}; do
if [[ $(netstat -tlpn 2>/dev/null | grep "$item" | awk '{print $4}') == '' ]]; then
freeOuterPort=$item
break
fi
done
}
function outerPorts() {
for item in ${allInerPorts[@]}; do
if [[ $(netstat -tlpn 2>/dev/null | grep "$item" | awk '{print $4}') == '' ]]; then
freeInerPort=$item
break
fi
done
}
innerPorts
outerPorts
# echo "INFO: freeInerPort: $freeInerPort"
# echo "INFO: freeOuterPort: $freeOuterPort"
# Stream configuration:
test_video="$1"
ffserver_cfg="${1}_ffserver.config"
function configure_ffserver {
echo "
HTTPPort $freeInerPort
HTTPBindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 10000
CustomLog -
RTSPPort $freeOuterPort
RTSPBindAddress 0.0.0.0
<Stream test>
Format rtp
File \"$test_video\"
</Stream>
<Stream status.html>
Format status
ACL allow localhost
ACL allow 192.168.0.0 192.168.255.255
</Stream>
" > $ffserver_cfg
}
# previous MaxBandwidth 5000000
# MAIN functionality
FFSERVER_CMD="ffserver"
# Change FFserver CMD for MacOS
[[ "$(uname)" == "Darwin" ]] && FFSERVER_CMD="./mac_os/bin/ffserver"
configure_ffserver
# Run stream:
server_ip=$(hostname -I | awk '{print $1}')
echo -e "Running RTSP streamer on (rtsp://${server_ip}:${freeOuterPort}/test)"
$FFSERVER_CMD -f $ffserver_cfg
# Kill streams on exit:
function kill_streams {
killall ffmpeg
echo "all ffmpeg streams killed"
}
trap kill_streams INT