Using Nginx to build live streaming media platform

Source: Internet
Author: User

Demo Environment
Nginx build
CentOS 7
OBS Studio
VLC Media Player
Build nginx-rtmp Live server-obs record push stream-VLC video stream playback

1.First Compile and install Nginx

H ow to build nginx  
[root@localhost ~]# tar xvf nginx-1.8.1.tar.gz 
[root@localhost ~]# unzip 
[root@localhost ~]# cd nginx-1.8.1
[root@localhost ~]# yum -y install zlib zlib-devel openssl* pcre pcre-devel gd-devel #nginx的依赖包
[root@localhost nginx-1.8.1]# ./configure --add-module=../nginx-rtmp-module-master
[root@localhost nginx-1.8.1]# make -j 4 && make install

2.Test whether the installation was successful

[root@localhost nginx-1.8.1]# cd /usr/local/nginx
[root@localhost nginx ]# ./sbin/nginx #start sevice

Entering the virtual machine's IP in the browser or localhost appears as follows to indicate that the installation was successful

3.Configuration of the Live service

[root@centos6(cyn) nginx ]# vim /usr/local/nginx/conf/nginx.conf#Add this rtmp configuration at the end of the configuration file.
Rtmp { #rtmp configured block, this place is the root of the live configuration
     Server { #server instance
                 Listen 1935;#Listen and accept the port
                 Application mytv { # three types of application / instance (1) rtmp recording (vod), (2) rtmp live (live), (3) hls live (hls)
                         Live on; #Open live broadcast mode, one-to-many broadcast
                         Hls on; #open live
                         Hls_path /usr/local/nginx/html/hls;#Directory/path for recording video files
                         Hls_fragment 2s; # followed by time, used to set the size of each block. The default is 5 seconds. Can only be an integer

Here are some of the HLS configurations that can be configured according to your needs

Hls_playlist_length: Set the length of the playlist in seconds
Hls_sync: synchronization time of audio and video
Hls_continuous: on|off Sets the continuous mode, starting from the point where playback stops or skips directly
Hls_nested: on|off defaults to off. The effect after opening is that each stream has a folder
Hls_base_url: Set the base URL, valid for relative URLs in m3u8
Hls_cleanup: on|off is on by default, removes media blocks that are not already in the list.
Hls_fragment_naming: sequential (named using a growing integer) | timestamp (timestamp using media block) | system (using system timestamp) naming
Hls_fragment_naming_granularity: the precision of the timestamp if it is named using a timestamp
Hls_fragment_slicing: plain (the media block is changed when the required duration is reached)|aligned (a few durations when the database block is reached)

4.Create a directory/path to a video file

[root@localhost nginx]# mkdir /usr/local/nginx/html/hls

5.Restarting the service, shutting down the firewall and SELinux

[root@localhost nginx]#./sbin/nginx -s stop
[root@localhost nginx]#./sbin/nginx
[root@localhost nginx]# iptables -F
[root@localhost nginx]# setenforce 0

6.Here the server has been set up, we start to push the flow settings
Click on the file, settings, stream, select a custom streaming server in the stream type, fill in the URL with the Rtmp:// (IP plus instance name), and then fill in the name of the stream with a name (any), the OBS settings are complete
Click Start to push the stream, in the bottom left corner of the source can select the content you want to live

7.Next go to VLC media studio to set up accept streaming media

Click Media, open Network streaming, enter rtmp:// in the URL (server ip+ app name + stream name), click Play

8.At this point an obs stream-nginx-rtmp live streaming-VLC streaming platform is built, this time in the browser input Ip+stat

will show our app name (MyTV), live streames (number of streaming media), stream name (test)

Using Nginx to build live streaming media platform

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.