设置自定义 RTMP 流服务器时无法打开连接 tcp://localhost:1935
Cannot open connection tcp://localhost:1935 when to set up custom RTMP stream server
我的简单网络如下:
192.168.31.52 is my local pc
192.168.31.251 is an ip camera.
我可以用 SMPlayer 打开流 rtsp://192.168.31.251/cam/realmonitor?channel=1&subtype=0
。
以这种方式构建我的 nginx 以自定义 RTMP 流。
sudo apt update
sudo apt install build-essential git
sudo apt install libpcre3-dev libssl-dev zlib1g-dev
git clone https://github.com/arut/nginx-rtmp-module.git
git clone https://github.com/nginx/nginx.git
cd nginx
./auto/configure --add-module=../nginx-rtmp-module
make
sudo make install
为 nginx 设置配置文件:
sudo vim /usr/local/nginx/conf/nginx.conf
rtmp {
server {
listen 1935;
application live {
live on;
interleave on;
hls on;
hls_path /tmp/hls;
hls_fragment 15s;
}
}
}
然后给nginx设置权限:
mkdir /tmp/hls
sudo chmod -R 755 /tmp/hls
sudo chown -R www-data:www-data /tmp/hls
在 /tmp/hls
中编辑 index.html。
<p>test for nginx</p>
127.0.0.1/index.html
和192.168.31.52/index.html
都可以打开/tmp/hls/index.html
。
现在在我的网络上打开端口 1935:
sudo firewall-cmd --zone=public --add-port=1935/tcp --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-ports | grep 1935
1935/tcp
启动nginx:
sudo systemctl start nginx
将 rtsp 流从 ip camera--192.168.31.251 上传到本地 pc --192.168.31.52.
input="rtsp://192.168.31.251/cam/realmonitor?channel=1&subtype=0"
output="rtmp://192.168.31.52:1935/live/sample"
ffmpeg -i $input -acodec aac -strict experimental -ar 44100 -ac 2 -b:a 96k -r 25 -b:v 500k -s 640*480 -f flv $output
遇到以下错误:
[tcp @ 0x59fb700] Connection to tcp://192.168.31.52:1935 failed: Connection refused
[rtmp @ 0x59fc5c0] Cannot open connection tcp://192.168.31.52:1935
rtmp://192.168.31.52:1935/live/sample: Connection refused
为了简单起见,我用本地电脑中的mp4文件替换了$input
,相同的错误信息。
怎么解决?
Ping 我的机器:
ping 192.168.31.52
PING 192.168.31.52 (192.168.31.52): 56 data bytes
64 bytes from 192.168.31.52: icmp_seq=0 ttl=64 time=0.108 ms
64 bytes from 192.168.31.52: icmp_seq=1 ttl=64 time=0.107 ms
64 bytes from 192.168.31.52: icmp_seq=2 ttl=64 time=0.111 ms
为什么1935端口没有打开,设置好后重启了nginx?
sudo lsof -i:1935
#nothing in the output
netstat -ltn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:51413 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:1080 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:8123 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:8384 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:9091 0.0.0.0:* LISTEN
tcp6 0 0 :::3306 :::* LISTEN
tcp6 0 0 :::80 :::* LISTEN
tcp6 0 0 :::22000 :::* LISTEN
tcp6 0 0 :::51413 :::* LISTEN
tcp6 0 0 :::21 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
tcp6 0 0 :::2681 :::* LISTEN
防火墙命令无法工作:
sudo firewall-cmd --zone=public --add-port=1935/tcp --permanent
sudo firewall-cmd --reload
我的 nginx 版本:
sudo nginx -v
nginx version: nginx/1.10.3
如果您自己没有将 nginx
配置为系统服务,那么您很可能 运行 是预安装版本,而不是您编译的包含 RTMP 模块的版本。
sudo nginx -v
nginx version: nginx/1.10.3
这是 2017 年的稳定版本。
使用最新版本https://github.com/nginx/nginx.git:
./objs/nginx -v
nginx version: nginx/1.19.6
你第一次问这个问题的29/11/2020的版本应该是mainline 1.19.5.
检查系统服务的定义和nginx
可执行路径。
我的简单网络如下:
192.168.31.52 is my local pc
192.168.31.251 is an ip camera.
我可以用 SMPlayer 打开流 rtsp://192.168.31.251/cam/realmonitor?channel=1&subtype=0
。
以这种方式构建我的 nginx 以自定义 RTMP 流。
sudo apt update
sudo apt install build-essential git
sudo apt install libpcre3-dev libssl-dev zlib1g-dev
git clone https://github.com/arut/nginx-rtmp-module.git
git clone https://github.com/nginx/nginx.git
cd nginx
./auto/configure --add-module=../nginx-rtmp-module
make
sudo make install
为 nginx 设置配置文件:
sudo vim /usr/local/nginx/conf/nginx.conf
rtmp {
server {
listen 1935;
application live {
live on;
interleave on;
hls on;
hls_path /tmp/hls;
hls_fragment 15s;
}
}
}
然后给nginx设置权限:
mkdir /tmp/hls
sudo chmod -R 755 /tmp/hls
sudo chown -R www-data:www-data /tmp/hls
在 /tmp/hls
中编辑 index.html。
<p>test for nginx</p>
127.0.0.1/index.html
和192.168.31.52/index.html
都可以打开/tmp/hls/index.html
。
现在在我的网络上打开端口 1935:
sudo firewall-cmd --zone=public --add-port=1935/tcp --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-ports | grep 1935
1935/tcp
启动nginx:
sudo systemctl start nginx
将 rtsp 流从 ip camera--192.168.31.251 上传到本地 pc --192.168.31.52.
input="rtsp://192.168.31.251/cam/realmonitor?channel=1&subtype=0"
output="rtmp://192.168.31.52:1935/live/sample"
ffmpeg -i $input -acodec aac -strict experimental -ar 44100 -ac 2 -b:a 96k -r 25 -b:v 500k -s 640*480 -f flv $output
遇到以下错误:
[tcp @ 0x59fb700] Connection to tcp://192.168.31.52:1935 failed: Connection refused
[rtmp @ 0x59fc5c0] Cannot open connection tcp://192.168.31.52:1935
rtmp://192.168.31.52:1935/live/sample: Connection refused
为了简单起见,我用本地电脑中的mp4文件替换了$input
,相同的错误信息。
怎么解决?
Ping 我的机器:
ping 192.168.31.52
PING 192.168.31.52 (192.168.31.52): 56 data bytes
64 bytes from 192.168.31.52: icmp_seq=0 ttl=64 time=0.108 ms
64 bytes from 192.168.31.52: icmp_seq=1 ttl=64 time=0.107 ms
64 bytes from 192.168.31.52: icmp_seq=2 ttl=64 time=0.111 ms
为什么1935端口没有打开,设置好后重启了nginx?
sudo lsof -i:1935
#nothing in the output
netstat -ltn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:51413 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:1080 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:8123 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:8384 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:9091 0.0.0.0:* LISTEN
tcp6 0 0 :::3306 :::* LISTEN
tcp6 0 0 :::80 :::* LISTEN
tcp6 0 0 :::22000 :::* LISTEN
tcp6 0 0 :::51413 :::* LISTEN
tcp6 0 0 :::21 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
tcp6 0 0 :::2681 :::* LISTEN
防火墙命令无法工作:
sudo firewall-cmd --zone=public --add-port=1935/tcp --permanent
sudo firewall-cmd --reload
我的 nginx 版本:
sudo nginx -v
nginx version: nginx/1.10.3
如果您自己没有将 nginx
配置为系统服务,那么您很可能 运行 是预安装版本,而不是您编译的包含 RTMP 模块的版本。
sudo nginx -v
nginx version: nginx/1.10.3
这是 2017 年的稳定版本。
使用最新版本https://github.com/nginx/nginx.git:
./objs/nginx -v
nginx version: nginx/1.19.6
你第一次问这个问题的29/11/2020的版本应该是mainline 1.19.5.
检查系统服务的定义和nginx
可执行路径。