Home Operation and Maintenance Nginx How nginx uses the nginx-rtmp-module module to implement the live broadcast room function

How nginx uses the nginx-rtmp-module module to implement the live broadcast room function

May 19, 2023 am 08:13 AM
nginx nginx-rtmp-module

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
Copy after login

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
Copy after login

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
Copy after login

Add rtmp protocol configuration

wujianjun@wujianjun-work ~/nginx-1.13.6 $ sudo vi /usr/local/nginx/conf/nginx.conf
Copy after login

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;
  }
 }
}
Copy after login

Start & test

Start nginx

wujianjun@wujianjun-work ~/nginx-1.13.6 $ sudo /usr/local/nginx/sbin/nginx
Copy after login

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

How nginx uses the nginx-rtmp-module module to implement the live broadcast room function

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:

How nginx uses the nginx-rtmp-module module to implement the live broadcast room function

After clicking "Play", wait a few seconds and you will see the player displaying the image captured by obs.

How nginx uses the nginx-rtmp-module module to implement the live broadcast room function

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;
 }
 .....
 }
}
Copy after login

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)

How nginx uses the nginx-rtmp-module module to implement the live broadcast room function

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to configure nginx in Windows How to configure nginx in Windows Apr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

See all articles