[TOC]
## 一、安装ffmpeg
>[info] **1.升级系统**
~~~
yum install epel-release -y
yum update -y
shutdown -r now
~~~
>[info] **2.安装Nux Dextop Yum 源**
~~~
rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
~~~
>[info] **3.安装FFmpeg 和 FFmpeg开发包**
~~~
yum install ffmpeg ffmpeg-devel -y
~~~
>[info] **4.测试是否安装成功**
~~~
ffmpeg
~~~
## 二、Nginx编译安装
>[info] **1、下载**
下载`nginx`、`nginx-http-flv-module`到`/opt/tools/`目录中。`无需解压`!
>[info] **2、安装系统相关依赖项**
~~~
yum -y install unzip
yum -y install gcc-c++
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
~~~
>[info] **3、解压`nginx-http-flv-module-1.2.10.zip`解压到`/usr/local/nginx`目录中**
>[danger]`/usr/local/nginx`此目录需自行新建
~~~
cd /opt/tools
unzip nginx-http-flv-module-1.2.10.zip
cp -r /opt/tools/nginx-http-flv-module-1.2.10 /usr/local/nginx/nginx-http-flv-module
~~~
>[info] **4、将`nginx-http-flv-module`模板添加到`nginx`中,生成`make`文件 并安装`nginx`**
~~~
cd /opt/tools
tar -zxvf nginx-1.21.5.tar.gz
cd nginx-1.21.5
./configure --prefix=/usr/local/nginx --add-module=/usr/local/nginx/nginx-http-flv-module
make && make install
~~~
>[info]**5、修改`nginx`配置文件**
~~~
worker_processes 1;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1985; #监听的端口
application myapp {
live on;
hls on;
hls_path /usr/local/html/hls;#视频流存放地址
hls_fragment 5s;
hls_playlist_length 15s;
hls_continuous on; #连续模式。
hls_cleanup on; #对多余的切片进行删除。
hls_nested on; #嵌套模式。
}
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
add_header 'Access-Control-Allow-Origin' '*';
root html;
index index.html index.htm;
}
location /live {
flv_live on;
}
location /flv {
add_header 'Access-Control-Allow-Origin' '*';
flv_live on;
chunked_transfer_encoding on;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
~~~
>[info] **6、启动`nginx`服务**
~~~
cd /usr/local/nginx/sbin
./nginx
~~~
Tips:停止nginx服务“`./nginx -s stop`” , 重新加载配置 “`./nginx -s reload`”
## 三、关闭防火墙
关闭防火墙
~~~
systemctl stop firewalld
~~~
查看防火墙状态
~~~
systemctl status firewalld
~~~
## 四、使用 OBS 推流
1. 打开`OBS 设置面板 > 推流`
1. 将服务设置为:`自定义`
2. 服务器设置为:`rtmp://你的IP地址:1985/myapp/`
3. 串流密钥设置为房间名:`testv`
>[danger] 只要Nginx启动了 即无需再使用任何命令 如:`ffmpeg -re -i rtmp://127.0.0.1:1985/myapp/testv -c copy -f flv rtmp://127.0.0.1:1985/myapp/testv`
> 此类是不需要的
## 五、常见问题
> 出现服务链接失败、拒绝连接
更改监听端口号(1985)、应用名(myapp)