Build nginx Streaming Media server (HLS support)

Source: Internet
Author: User
Tags nginx server

Environment construction

(a) Download the source code

Nginx, Address: http://nginx.org/You can choose the version you want to download

nginx_mod_h264_streaming-2.2.7.tar.gz, support MP4 stream, specific instructions on this page below

Http://h264.code-shop.com/trac/wiki/Mod-H264-Streaming-Nginx-Version2

M3u8-segmenter:hls Shard Tool, Https://github.com/johnf/m3u8-segmenter

FFmpeg: Media codec tool, as a publishing tool for HLS live streaming

(ii) Installation of Nginx

TAR-ZXVF nginx_mod_h264_streaming-2.2.7.tar.gz

TAR-ZXVF nginx-1.4.4.tar.gz

CD nginx-1.4.4

./configure--prefix=/usr/local/nginx-stream--with-debug--with-http_dav_module--with-http_gzip_static_module-- With-http_ssl_module--with-ipv6--with-sha1=/usr/include/openssl--with-md5=/usr/include/openssl--add-module=. /nginx_mod_h264_streaming-2.2.7--with-http_flv_module--with-http_mp4_module

If no error occurs

Make

If an error occurs similar to: ' ngx_http_request_t ' does not have a member named ' Zero_in_uri ', then enter the nginx_mod_h264_streaming-2.2.7 directory, enter SRC, modify Ngx_http_ STREAMING_MODULE.C, comment out the TODO window32 module:

if (R->zero_in_uri) {

return ngx_declined;

}

Then make clean and then re-configure and make

If an error occurs similar to the following: [OBJS/ADDON/SRC/MP4_READER.O]. Enter the Obis directory in Nginx source code, modify makefile, delete--wrror

Then recompile make

After compiling the pass

sudo make install

(iii) Installation of M3u8-segmenter, this in the installation procedure.

(iv) Installation of FFmpeg, in other journals of this blog has the installation method.

Configuration

Under the server module, add the following:

Location/hls {

Alias/usr/local/media/hls;

Types {

Application/vnd.apple.mpegurl m3u8;

VIDEO/MP2T ts;

}

Add_header Cache-control No-cache;

expires-1;

}

Location ~* \.flv$ {

flv

root/usr/local/media/flv;

}

Location ~* \.mp4$ {

mp4;

Root/usr/local/media/mp4;

}

Then save the exit and start the Nginx server

On-demand Flv,mp4 video

The root directory (USR/LOCAL/MEDIA/FLV,/USR/LOCAL/MEDIA/MP4) of the FLV and MP4 are put in the test video test.flv and Test.mp4 respectively

Using the player Ffplay test in FFmpeg,

Ffplay http://ip:port/test.flv

Ffplay Http://ip:port/test.mp4

HLS on Demand

Use M3u8-segmenter to cut the video into a series of TS files and generate a playlist with a suffix of m3u8, and the video encoding needs to be H264/AAC or H264/mp3.

Enter/usr/local/media/hls, put in the test file test.ts, and then split with the following command,

M3u8-segmenter-i testvod.ts-d 10-p test-m testvod.m3u8-u http://ip:port/hls/

-I, input file

-D, the length of each shard

-p, prefix for the name of each shard

-M, playlist name

-u, URL prefix in playlist

Using the Ffplay test:

Ffplay http://ip:port/hls/test.m3u8

HLS Live

Use FFmpeg to publish live streams, where no devices are used to crawl video, use Ffmpe's-re option to simulate live streaming, and re to show the frame rate according to the input video

Ffmpeg-re-i Test.ts-codec Copy-hls_time testlive.m3u8

Using the Ffplay test

Ffplay http://ip:port/hls/testlive.m3u8

NOTE: MP4 turn ts, ffmpeg-i test.mp4-codec COPY-VBSF H264_mp4toannexb test.ts

The HLS protocol supports adaptive bitrate and can be nested using playlists, and Nginx-rtmp-module has similar support for HLS

Build nginx Streaming Media server (HLS support)

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.

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.