Live Server Nginx

Source: Internet
Author: User
Tags nginx server

Mac Live Server Nginx configuration support for HLS

In the previous article on the Mac to build a live server nginx+rtmp, we have built a nginx+rtmp live server. The following need to add support to the Nginx server for HLS. In Nginx addition to the support of the HLS more simple, just simple modification under the configuration file nginx.conf .

Installing Nginx and RTMP modules

For the installation of Nginx is relatively simple, please refer to the previous article on the Mac to build a live server nginx+rtmp. Here are some tips:

(1) After installing Nginx, open the configuration file:

/usr/local/nginx/conf/nginx.conf

(2) command to start Nginx:

$ sudo/usr/local/nginx/sbin/nginx-s stop$ Sudo/usr/local/nginx/sbin/nginx
HLS Live stream Configurationfind Http-->server, add in curly braces
    server {        listen       8080;        server_name  localhost;        #charset Koi8-r;        #access_log  logs/host.access.log  main;        Location/{            root   html;            Index  index.html index.htm;        }       #HLS配置开始, this configuration is for the ' client ' to be able to get HLS's pull stream with the HTTP protocol        Location/hls {            # Serve HLS fragments            types {                application/ Vnd.apple.mpegurl m3u8;                VIDEO/MP2T ts;            }            root html;            Add_header Cache-control no-cache;        }       #HLS配置结束        #error_page  404              /404.html;        # REDIRECT Server error pages to the static page/50x.html        #        error_page   502 503 504/50x.html;
   location =/50x.html {            root   html;        }    }
Found it rtmpUnder the serverAdd in curly Braces
#在http节点下面 (i.e. the end of the file) plus rtmp configuration: rtmp {    server {        listen 1935;        Application Zbcs {                live on;                Record off;            }        #增加对HLS支持开始        application HLs {            live on;            HLS on;            Hls_path/usr/local/var/www/hls;            Hls_fragment 5s;         }        #增加对HLS支持结束    }}

Description

    1. Live on; Turn on real-time
    2. HLS on; Open HLS
    3. Hls_path; TS File Storage Path
    4. Hls_fragment 5s; Each TS file contains 5 Seconds of video content

HLS Live delay

We know that the HLS protocol is to divide the live stream into a segment of the video to download playback, so assume that the list contains 5 TS files, each TS file contains 5 Seconds of video content, then the overall delay is 25 seconds. Because when you see these videos, the host has recorded the video and uploaded it, so the delay occurs. Of course, you can shorten the length of the list and the size of a single TS file to reduce latency, the extreme can be reduced to a list length of 1, and ts length of 1s, but this will increase the number of requests, increase the server pressure, when the slow speed back to cause more buffering, so the official recommended TS length of 10s, So it's going to be a big 30s delay. Resources:

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/StreamingMediaGuide/ Frequentlyaskedquestions/frequentlyaskedquestions.html

Save the configuration file, reload the Nginx configuration
Nginx-s Reload
to push a stream

FFmpeg the same as in the previous article, however, we need to push into the new configuration of HLS, the movie keyword can be any replacement

Ffmpeg-re-i/users/jiangys/documents/document/demo.mp4-vcodec copy-f flv Rtmp://localhost:1935/hls/movie

Then, we can be in this directory (this is also nginx under the HTML default configuration file)

/usr/local/var/www/hls

When you see the generated ts files, you also generate a " 你的m3u8的文件名称.m3u8“ file

Test Pull Stream

With the above configuration, we can see the streamed stream in both rtmp and HLS two modes. Note that if you use HTTP, you are listening on port 8080, which is written in the config file.

(1) Using rtmp: (use VLC to verify playback)

Rtmp://192.168.1.100/hls/movie

(2) Play with HLS

Http://192.168.1.100:8080/hls/movie.m3u8

For HLS pull stream, we can also use the above address to play directly in the Safari browser, in addition to using VLC, or by using the ipad or Safari on the iphone (the IP address of the computer where you need to change localhost to nginx)

Add

1. In HLS, we want to store the TS file generated by the push stream in the specified directory, such as "/tmp/hls"

    Application HLs {      live on;      HLS on;      Hls_path/tmp/hls;    }

Then, we also need to change the root path in Http-->server to:/tmp. Otherwise, the stream will not be pulled.

Root HTML refers to the location of the current Nginx server root directory, pointing to the/usr/local/var/www directory

Live Server Nginx

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.

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.