Ffmpeg 无法打开连接tcp://localhost:1935 何时设置自定义RTMP流服务器
我的简单网络如下所示:Ffmpeg 无法打开连接tcp://localhost:1935 何时设置自定义RTMP流服务器,ffmpeg,ip-camera,Ffmpeg,Ip Camera,我的简单网络如下所示: 192.168.31.52 is my local pc 192.168.31.251 is an ip camera. 我可以打开流rtsp://192.168.31.251/cam/realmonitor?channel=1&subtype=0使用SMPlayer。 以这种方式构建用于定制RTMP流的nginx sudo apt update sudo apt install build-essential git sudo apt install libpcre
192.168.31.52 is my local pc
192.168.31.251 is an ip camera.
我可以打开流rtsp://192.168.31.251/cam/realmonitor?channel=1&subtype=0
使用SMPlayer。以这种方式构建用于定制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;
}
}
}
mkdir /tmp/hls
sudo chmod -R 755 /tmp/hls
sudo chown -R www-data:www-data /tmp/hls
然后设置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;
}
}
}
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>
启动nginx:
sudo systemctl start nginx
将rtsp流从ip摄像头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中的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年的稳定版本
使用最新版本:
从2020年11月29日开始,当你第一次问这个问题时,这个版本应该是主线1.19.5
检查系统服务的定义和
nginx
可执行路径。如果您自己没有将nginx
配置为系统服务,那么您很可能运行的是预安装版本,而不是您编译的包含RTMP模块的版本
sudo nginx -v
nginx version: nginx/1.10.3
这是2017年的稳定版本
使用最新版本:
从2020年11月29日开始,当你第一次问这个问题时,这个版本应该是主线1.19.5
检查系统服务的定义和nginx可执行路径。我会首先检查您是否可以ping机器。其次,我会检查端口
1935
是否在目的地实际打开。为什么1935没有打开?如何修复?我会首先检查您是否可以ping机器。第二,我会检查端口1935
是否在目的地实际打开。为什么1935没有打开?如何修复?如何将/objs/nginx
包装为服务?@showkey@showkey但您应该删除另一个版本并将可执行文件放在系统路径中如何将/objs/nginx
包装为服务服务?@showkey@showkey,但您应该删除其他版本,并将可执行文件放在系统路径中