我的简单网络如下:
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
以这种方式构建用于自定义RTMP流的nginx。
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
从ip摄像头上传rtsp流--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
为了简化问题,我在本地pc中将$input
替换为mp4文件,错误信息相同
如何修复
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
当你第一次问这个问题时,2020年11月29日的版本应该是主线1.19.5。
检查系统服务的定义和nginx
可执行路径。