To build a live broadcast platform recently, you need to build servers under Linux and Windows separately, and use two blogs to record the build process
- Download and install nginx and nginx-rtmp-module compilation dependency tools
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev
- Create working directory
mkdir nginx
cd nginx
- Download the source code of nginx and nginx-rtmp-module
#下载nginx源码并解压
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
#下载nginx-rtmp-module源码
git clone https://github.com/arut/nginx-rtmp-module.git
- Compile and install nginx
cd nginx-1.18.0
./configure --add-module=../nginx-rtmp-module --with-http_ssl_module #将rtmp模块编译到nginx
make
make install #或 sudo make install
- Start nginx service
sudo systemctl start nginx
#不出意外,会报下面的错误
Failed to start nginx.service: Unit nginx.service not found
Add nginx to systemctl
cd /usr/lib/systemd/
sudo mkdir system #如果存在该目录直接进入,不存在创建
cd system
sudo touch nginx.service
sudo vi nginx.service
Add the following
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
WorkingDirectory=/usr/local/nginx #此处位置为你的nginx安装目录,根据实际情况进行更改(删掉)
ExecStart=/usr/local/nginx/sbin/nginx #此处位置为你的nginx安装目录中的nginx可执行文件位置,根据实际位置进行更改(删掉)
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#使文件生效
sudo systemctl daemon-reload
- Start nginx service again
sudo systemctl start nginx
Enter the server IP in the browser, the following familiar content appears
- Add the configuration of the rtmp module in the configuration file and start the rtmp service
#进入nginx安装目录的conf目录下修改配置文件
cd /usr/local/nginx/conf/
sudo vi nginx.conf
sudo vi nginx.conf.default
Add the following content (both files need to be added)
rtmp {
server {
listen 1935;
application rtmplive {
live on;
max_connections 1024;
}
}
}
- Restart nginx server
sudo systemctl restart nginx
- FFmpeg streaming
ffmpeg -f dshow -i video="USB2.0 Camera" -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -f flv rtmp://nginx server IP:1935/rtmplive/123
- VLC pull stream
- Shut down the server
sudo systemctl stop nginx
Reference article:
[1]. Add Nginx to systemctl and chkconfig for management
[2]. Cloud server (ubuntu) build nginx-rtmp server to realize live broadcast function (pure command line operation)
[3]. Ubuntu Nginx+Rtmp server build ( Graphic presentation)
If there is any infringement, please contact to delete it. If there is an error, please correct me, thank you