Using Nginx to build live streaming media platform

Source: Internet
Author: User

Tags: IDE pen ali log Environment Live platform Fire system DDC

Demo Environment
    • CentOS 7
    • nginx-1.8.1
    • Nginx-rtmp-module
    • OBS Studio
    • VLC Media Player
Build nginx-rtmp Live server-obs record push stream-VLC video stream playback
  1. First Compile and install Nginx
    [[email protected] ~]# tar xvf nginx-1.8.1.tar.gz [[email protected] ~]# unzip nginx-rtmp-module-master.zip [[email protected] ~]# cd nginx-1.8.1[[email protected] ~]# yum -y install zlib zlib-devel openssl* pcre pcre-devel gd-devel #nginx的依赖包[[email protected] nginx-1.8.1]# ./configure --add-module=../nginx-rtmp-module-master[[email protected] nginx-1.8.1]# make -j 4 && make install
  2. Test whether the installation was successful
    [[email protected] nginx-1.8.1]# cd /usr/local/nginx[[email protected] nginx ]# ./sbin/nginx #启动服务

    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
    [[email protected](cyn) nginx ]# vim /usr/local/nginx/conf/nginx.conf#在配置文件最后加上这段rtmp的配置rtmp { #rtmp配置的块,这个地方就是直播的配置的根    server { #服务器的实例                listen 1935;#监听并且接受的端口                application mytv { #应用/实例的三种类型(1)rtmp录播(vod),(2)rtmp直播(live),(3)hls直播(hls)                        live on; #开启直播直播模式,一对多广播                        hls on; #开启直播                        hls_path /usr/local/nginx/html/hls;#录制视频文件的目录/路径                        hls_fragment 2s;#后面接时间,用来设置每一个块的大小。默认是5秒。只能为整数                }        }}

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

    hls_playlist_length:  设置播放列表的长度,单位是秒hls_sync:  音视频的同步时间hls_continuous:  on|off 设置连续模式,是从停止播放的点开始还是直接跳过hls_nested:  on|off 默认是off。打开后的作用是每条流自己有一个文件夹hls_base_url: 设置基准URL,对于m3u8中使用相对URL有效hls_cleanup:  on|off 默认是开着的,是否删除列表中已经没有的媒体块hls_fragment_naming: sequential(使用增长式的整数命名) | timestamp(使用媒体块的时间戳) | system(使用系统时间戳)命名方式 hls_fragment_naming_granularity: 如果使用时间戳命名时时间戳的精度hls_fragment_slicing:  
  4. Create a directory/path to a video file
    [[email protected] nginx]# mkdir /usr/local/nginx/html/hls
  5. Restarting the service, shutting down the firewall and SELinux
    [[email protected] nginx]#./sbin/nginx -s stop[[email protected] nginx]#./sbin/nginx[[email protected] nginx]# iptables -F[[email protected] 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://172.18.252.106/mytv (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://172.18.252.106/mytv/test 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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: