System environment
wujianjun@wujianjun-work ~ $ uname -a linux wujianjun-work 4.10.0-37-generic #41~16.04.1-ubuntu smp fri oct 6 22:42:59 utc 2017 x86_64 x86_64 x86_64 gnu/linux
Software environment
obs(open broadcaster software) v20.0.1 (linux)
nginx version: nginx/1.13.6
built by gcc 5.4.0 20160609 (ubuntu 5.4.0-6ubuntu1~16.04.5)
built with openssl 1.0.2g 1 mar 2016
tls sni support enabled
configure arguments: –with-pcre=pcre-8.38 –add-module=nginx-rtmp-module-1.1.11
nginx obs installation and configuration installation obs
wujianjun@wujianjun-work ~ $ sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next wujianjun@wujianjun-work ~ $ sudo apt-get update && sudo apt-get install ffmpeg wujianjun@wujianjun-work ~ $ sudo apt-get install obs-studio wujianjun@wujianjun-work ~ $ sudo add-apt-repository ppa:obsproject/obs-studio wujianjun@wujianjun-work ~ $ sudo apt-get update && sudo apt-get install obs-studio
nginx installs rtmp module
nginx-rtmp-module ( )
wujianjun@wujianjun-work ~ $ sudo apt-get install build-essential wujianjun@wujianjun-work ~ $ wget wget http://nginx.org/download/nginx-1.13.6.tar.gz wujianjun@wujianjun-work ~/nginx-1.13.6 $ wget https://github.com/arut/nginx-rtmp-module/archive/v1.1.11.tar.gz wujianjun@wujianjun-work ~/nginx-1.13.6 $ tar -xvf v1.1.11.tar.gz wujianjun@wujianjun-work ~/nginx-1.13.6 $ wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz wujianjun@wujianjun-work ~/nginx-1.13.6 $ tar -xvf pcre-8.38.tar.gz wujianjun@wujianjun-work ~/nginx-1.13.6 $ ls -all 总用量 748 drwxr-xr-x 9 wujianjun wujianjun 4096 10月 15 11:39 . drwxr-xr-x 63 wujianjun wujianjun 4096 10月 15 11:33 .. drwxr-xr-x 6 wujianjun wujianjun 4096 10月 15 11:33 auto -rw-r--r-- 1 wujianjun wujianjun 282456 10月 10 23:22 changes -rw-r--r-- 1 wujianjun wujianjun 430416 10月 10 23:22 changes.ru drwxr-xr-x 2 wujianjun wujianjun 4096 10月 15 11:33 conf -rwxr-xr-x 1 wujianjun wujianjun 2502 10月 10 23:22 configure drwxr-xr-x 4 wujianjun wujianjun 4096 10月 15 11:33 contrib drwxr-xr-x 2 wujianjun wujianjun 4096 10月 15 11:33 html -rw-r--r-- 1 wujianjun wujianjun 1397 10月 10 23:22 license drwxr-xr-x 2 wujianjun wujianjun 4096 10月 15 11:33 man drwxrwxr-x 6 wujianjun wujianjun 4096 2月 13 2017 nginx-rtmp-module-1.1.11 drwxr-xr-x 7 wujianjun wujianjun 4096 11月 23 2015 pcre-8.38 -rw-r--r-- 1 wujianjun wujianjun 49 10月 10 23:22 readme drwxr-xr-x 9 wujianjun wujianjun 4096 10月 15 11:33 src wujianjun@wujianjun-work ~/nginx-1.13.6 $ ./configure --with-pcre=pcre-8.38 --add-module=nginx-rtmp-module-1.1.11 wujianjun@wujianjun-work ~/nginx-1.13.6 $ make && sudo make install wujianjun@wujianjun-work ~/nginx-1.13.6 $ ls -all /usr/local/nginx/ 总用量 24 drwxr-xr-x 6 root root 4096 10月 15 16:11 . drwxr-xr-x 11 root root 4096 10月 15 16:11 .. drwxr-xr-x 2 root root 4096 10月 15 16:11 conf drwxr-xr-x 2 root root 4096 10月 15 16:11 html drwxr-xr-x 2 root root 4096 10月 15 16:11 logs drwxr-xr-x 2 root root 4096 10月 15 16:11 sbin
Add rtmp protocol configuration
wujianjun@wujianjun-work ~/nginx-1.13.6 $ sudo vi /usr/local/nginx/conf/nginx.conf
Add the following rtmp protocol at the end of the nginx.conf file Configuration
rtmp { server { listen 1935; chunk_size 4096; application live { live on; record off; } } }
Start & test
Start nginx
wujianjun@wujianjun-work ~/nginx-1.13.6 $ sudo /usr/local/nginx/sbin/nginx
Start obs
Open the obs software you just installed, at the source Configure the push source of the image (I choose window capture here), click "Settings" in the lower right corner, and configure the stream push address as shown below
After the configuration is completed, click "Start Push" Stream"
Start a video player that supports network stream playback (the demonstration uses vlc player)
Configure the address for network stream playback, as shown below:
After clicking "Play", wait a few seconds and you will see the player displaying the image captured by obs.
Since the video stream needs to be transmitted over the network, there will be a delay of several seconds in the live image.
http access live video
1. Change the configuration in nginx.conf, add hls configuration (hls is the folder used to store streaming media in the streaming media server), and re-enter the directory where hls is located Just set the http protocol to access the directory. The changed configuration is as follows:
rtmp { server { listen 1935; chunk_size 4096; application live { live on; hls on; hls_path /usr/share/nginx/html/hls; hls_fragment 5s; } } } http { server { listen 80; ..... location / { #root html; root /usr/share/nginx/html; index index.html index.htm; } ..... } }
Note: The user of nginx in the directory where hls is located must have write permission.
2. Obs software configures the recording stream name
There is a place to set the "stream name" below the configuration of the obs push stream URL. You can fill in a name at will (I fill in the example here) "test")
3. Restart nginx and obs software. We can enter http://ip/hls/test.m3u8 in the mobile browser to play the live video on the mobile phone. (The live broadcast delay is a bit large, and the article will be optimized later)
The above is the detailed content of How nginx uses the nginx-rtmp-module module to implement the live broadcast room function. For more information, please follow other related articles on the PHP Chinese website!