Nginx to build HLS streaming media server

Source: Internet
Author: User

http://blog.csdn.net/cjsafty/article/details/7922849

Introduction: HTTP Live streaming (abbreviated as HLS) is an HTTP-based streaming network Transfer protocol proposed by Apple.

is part of Apple's QuickTime X and iphone software system. It works by dividing the entire stream into small, HTTP-based

Files to download, download only some at a time. When the media stream is playing, the client can choose from many different standby sources at different speeds

rate to download the same resources, allowing streaming sessions to accommodate different data rates. When you start a streaming session, the client downloads a package

A extended m3u (m3u8) playlist file with metadata to find the available media streams.


HLS only requests basic HTTP messages, unlike real-time Transport Protocol (RTP), which can pass through any HTTP-enabled data

Firewall or proxy server. It is also easy to use a content distribution network to transfer media streams.

For details of this agreement, please refer to Apple's official website: https://developer.apple.com/resources/http-streaming/

There are two ways of building hlsserver,

One is to use the Apple SDK,

One is to use Adobe's fms,4.5 version to support HLS, reference,

Http://www.adobe.com/products/flash-media-streaming/features._sl_id-contentfilter_sl_featuredisplaytypes_sl_new.html

Adobe's FMS is now powerful, but business requires licence. Interested can be studied under.

One is the use of opensouce. I like this one better.

Method:

The main method of opensource is to use M3u8-segmenter+ffmpeg to shard TS files.

So the idea is:

1, using the compiled ffmpeg to make the required TS file,

2, install the Libavformat-dev version,

3, compiling M3u8-segmenter,

4, deploy to Nginx

5, advanced features, stream switching

6, page

Process

1, originally want to download FFmpeg source code compilation, but because to involve Faac,x264,lame library. Sometimes the FFmpeg version has the minimum version requirement for these libraries, and the compilation

FAAC encountered the following issues

[Plain]View PlainCopy 
    1. install support library   
    2. apt-get install automake autoconf  m4 libtool  
    3.   
    4. -bash: ./bootstrap: /bin/sh^m:  bad interpreter: no such file or directory  
    5.   
    6. convert character:   
    7. DOS2UNIX BOOTSTRAP  
    8. make  
    9.   
    10. error:mpeg4ip.h:126:58: error: new declaration  ' Char* strcasestr (const char*,  const char*) '   
    11.   
    12. Workaround: remove line 126  containing strcasecmp from mpeg4ip.h as a temporary workaround   
    13.   
    14. Make install encountered   
    15. usr/local The/share/man/man1 folder could not create the problem.   


The last problem can not be solved, as if Linux (Ubuntu) under a directory, if you already have a file, you cannot create a folder with the same name, then discard the compilation,

Download the compiled ffmpeg static file directly from the FFmpeg website: http://ffmpeg.org/download.html, the Linux download page. The main purpose of this static file is to

In order to convert the various documents into Apple's prescribed documents. Therefore, aac,mp3,x264 Library support is required.

Or simply follow the 2 method. Apt-get install FFmpeg. This will get ffmpeg feasibility file.

2, install FFmpeg Support library, mainly used for compiling m3u8-segmenter, here ffmpeg Support Library, its purpose is to provide libavformat support for Segmenter. Codec is not involved.

Apt-get install Libavformat-dev.

[Plain]View PlainCopy  
  1. Reading Package Lists ... Done
  2. Building Dependency Tree
  3. Reading state information ... Done
  4. The following extra packages'll be installed:
  5. Libavcodec-dev libavcodec53 libavformat53 libavutil-dev libavutil51 libgsm1 libogg0 liborc-0.4-0
  6. libschroedinger-1.0-0 libspeex1 libtheora0 libva1 libvorbis0a libvorbisenc2 libvpx1
  7. Suggested Packages:
  8. Libfaad-dev libgsm1-dev libogg-dev libschroedinger-dev libspeex-dev libtheora-dev libvorbis-dev Libx11-dev
  9. Libxext-dev Libraw1394-dev Libdc1394-22-dev Speex
  10. The following NEW packages'll be installed:
  11. Libavcodec-dev libavcodec53 libavformat-dev libavformat53 libavutil-dev libavutil51 libgsm1 libogg0 liborc-0.4-0
  12. libschroedinger-1.0-0 libspeex1 libtheora0 libva1 libvorbis0a libvorbisenc2 libvpx1


This will automatically install FFMEPG several related libraries.

3, download m3u8-segmenter from Https://github.com/johnf/m3u8-segmenter

After downloading do not use its repeated compilation, directly fetch M3U8-SEGMENTER.C file,

[Plain]View PlainCopy 
    1. Gcc-wall-g Segmenter.c-o Segmenter-lavformat

From the source view, because only use the Avformat library, so only link this one can. Generate the Segmenter file, with the Help command, you can see that it has been successful.

[Plain]View PlainCopy 
  1. HTTP Live streaming-segments TS file and creates m3u8 index.
  2. -I,--input file TS file to segment (Use-for stdin)
  3. -D,--duration SECONDS duration of each segment (Default:10 SECONDS)
  4. -p,--output-prefix prefix prefix for the TS segments, would be appended
  5. With-1.ts, -2.ts etc
  6. -M,--m3u8-file file m3u8 output filename
  7. -u,--url-prefix prefix prefix for web address of segments, e.g. http://example.org/video/
  8. -N,--num-segment number number of segments to keep on disk
  9. -H,--help this Help


From the point of view, the grammar is very simple, here to paste one I use.

[Plain]View PlainCopy  
    1. ./segmenter-i test.ts-n 30-p sample_test-m stream-test.m3u8-u http://192.168.1.10:8080/hls/


I represents the input file, n means 30 cuts, and p indicates the prefix of the cut file. M represents the generated m3u8 file name, u indicates which directory of the Web server the post-cut files are in, and this must match the web directory

4, deploy to Nginx.

Nginx related deployment I have explained in detail in the first two blogs, where HLS is deployed based on the Jwplayer blog.

1) directory Issues:

In the Html/jwplayer directory, set up the HLs folder, copy the m3u8 file and all the TS files after the cut to this directory,

In VLC player or ipad safie browser or in Ffplayer (I'm using the 0.11 version of the Windows compilation version)

The access path on the http://192.168.1.10:8080/hls/stream-test.m3u8 should be

2) file type problem: Edit the/usr/local/nginx/conf/mime.types file, add the following type

[Plain]View PlainCopy 
    1. Application/x-mpegurl m3u8;
    2. VIDEO/MP2T ts;

3) Restart Nginx

Enter the above path and you should see the video.

5, advanced features, stream switching

The m3u8 file above has only one stream and does not have a stream switching function. On Youku, if it is an ipad client, you can see that there are SD, HD, Ultra-clear buttons, in fact, that is the corresponding different standards

(single) m3u8 files for streaming, and don't know if Apple is doing this, Apple seems to be asking for "smart" stream switching. That does not require the user to choose, but according to the network condition adaptive.

The flow switch for sample from Apple is to write the m3u8 of each stream in a m3u8 file.

Similar to this, in fact the principle is the same.

[Plain]View PlainCopy 
    1. #EXTM3U
    2. #EXT-x-stream-inf:program-id=1, bandwidth=100000
    3. Video1/index1.m3u8
    4. #EXT-x-stream-inf:program-id=1, bandwidth=200000
    5. Video2/index2.m3u8


6, page,

If you continue to build a page, the above address embedded in the page, so with CSS is more beautiful. Page can be on this basis, with Webpy to do.



Page reference:

Apple Development Network: https://developer.apple.com/resources/http-streaming/

Blog: http://www.nginxs.com/linux/459.html

FFmpeg Development Network: http://ffmpeg.org/download.html

Segmenter Source: Https://github.com/johnf/m3u8-segmenter

Adboe FMS Introduction: Http://www.adobe.com/products/flash-media-streaming/features._sl_id-contentfilter_sl_ Featuredisplaytypes_sl_new.html


2014.02 notes:

There may be a problem with the slicing software described in this article, you can choose this

Https://code.google.com/p/httpsegmenter/downloads/list

//--------------------------------------------------------------------------------

Objective: To enable the Nginx support RTMP protocol to push the stream, and support HLS distribution function and FFmpeg transcoding multi-bit rate function.

First, the preparatory work
Module: Nginx-rtmp-module-master (rtmp protocol support)
:
http://nginx.org
Https://github.com/arut/nginx-rtmp-module

1. Install the dependent package:
#yum-y install gcc glibc glibc-devel make nasm pkgconfig lib-devel openssl-devel expat-devel gettext-devel libtool mhash. x86_64 perl-digest-sha1.x86_64 gcc-c++

2. Install the Git tool:
#mkdir Soft-source
#cd Soft-source
#wget http://www.codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.gz
#tar XZVF git-latest.tar.gz
#cd git-2013-02-04
#autoconf
#./configure
#make && make Install
# git--version
git version 1.8.1.GIT
#cd:

"Error Handling"

If the git-latest.tar.gz size is 0, please download GIT-LATEST-TAR.XZ

Then xz-d git-latest.tar.xz decompression to. Tar

Then tar xvf Git-latest.tar

3. Install ffmpeg and its dependent packages:
++++++++yasm+++++++++++
#wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
#tar XZVF yasm-1.2.0.tar.gz
#cd yasm-1.2.0
#./configure
#make
#make Install
#cd:
++++++++x264+++++++++++
#git Clone git://git.videolan.org/x264
#cd x264
#./configure--enable-shared
#make
#make Install
#cd:

++++++++lame+++++++++++
#wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
#tar XZVF lame-3.99.5.tar.gz
#cd lame-3.99.5
#./configure--enable-nasm
#make
#make Install
#cd:
++++++++libogg+++++++++++
#wget http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
#tar XZVF libogg-1.3.0.tar.gz
#cd libogg-1.3.0
#./configure
#make
#make Install
#cd:
++++++++libvorbis+++++++++++
#wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz
#tar XZVF libvorbis-1.3.3.tar.gz
#cd libvorbis-1.3.3
#./configure
#make
#make Install
#cd:
++++++++libvpx+++++++++++
#git Clone Http://git.chromium.org/webm/libvpx.git
#cd LIBVPX
#./configure--enable-shared
#make
#make Install
#cd:
++++++++faad2+++++++++++
#wget http://downloads.sourceforge.net/project/faac/faad2-src/faad2-2.7/faad2-2.7.tar.gz
#tar ZXVF faad2-2.7.tar.gz
#cd faad2-2.7
#./configure
#make
#make Install
#cd:
++++++++faac+++++++++++
#wget http://downloads.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz
#tar ZXVF faac-1.28.tar.gz
#cd faac-1.28
#./configure
#make
#make Install
#cd:

"Error Handling"

Error encountered while compiling FAAC-1.28:

Mpeg4ip.h:126:error:new declaration ' char* strcasestr (const char*, const char*) '

Workaround:

Start modifying this file from 123 lines to the end of line 129 mpeg4ip.h.
Before modification:
#ifdef __cplusplus
extern "C" {
#endif
Char *strcasestr (const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif

After modification:
#ifdef __cplusplus
extern "C + +" {
#endif
const char *STRCASESTR (const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif


++++++++xvid+++++++++++
#wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
#tar ZXVF xvidcore-1.3.2.tar.gz
#cd Xvidcore/build/generic
#./configure
#make
#make Install
Cd.. /.. /.. /


++++++++ffmpeg+++++++++++
#git Clone Git://source.ffmpeg.org/ffmpeg
#cd FFmpeg
#./configure--prefix=/opt/ffmpeg/--enable-version3--enable-libvpx--enable-libfaac--enable-libmp3lame-- Enable-libvorbis--enable-libx264--enable-libxvid--enable-shared--ENABLE-GPL--enable-postproc--enable-nonfree-- Enable-avfilter--enable-pthreads
#make && make Install
#cd:
"Error Handling"

If prompted LIBVPX decoder version must be >=0.91, please search for libvpx-v1.1.0.tar.bz download from Baidu.

Bzip2-d libvpx-v1.1.0.tar.bz2

Tar xvf libvpx-v1.1.0.tar.bz2

CD libvpx-v1.1.0

./configure--enable-shared--ENABLE-VP8

Make

Make install


Modify the/etc/ld.so.conf as follows:
Include ld.so.conf.d/*.conf
/lib
/lib64
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/opt/ffmpeg/lib
#ldconfig

Description

Dynamic loader finds shared libraries to rely on two files-/etc/ld.so.conf and/etc/ld.so.cache.

After the installation is complete, FFmpeg is located in the/opt/ffmpeg/bin directory.

Linux under compile ffmpeg download source files and compile http://www.linuxidc.com/Linux/2012-02/54565.htm

Linux compilation upgrade FFmpeg step http://www.linuxidc.com/Linux/2013-08/88190.htm

Install FFMPEG http://www.linuxidc.com/Linux/2011-09/42793.htm on CentOS 5.6

Install FFmpeg http://www.linuxidc.com/Linux/2012-12/75408.htm under Ubuntu

Ubuntu 12.04 under compilation FFmpeg http://www.linuxidc.com/Linux/2013-02/78857.htm

Ubuntu 14.04 under PPA installation FFmpeg 2.2.2 http://www.linuxidc.com/Linux/2014-05/101322.htm

for more details, please read on to the next page. Highlights : http://www.linuxidc.com/Linux/2015-01/111182p2.htm

Nginx to build HLS streaming media server

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.