Second, the installation of Nginx related modules
1. Environmental preparedness
Yum Install–y pcre Pcre-devel
Yum install–y zlib Zlib-devel
2. Download Nginx and rtmp module
wget http://nginx.org/download/nginx-1.6.2.tar.gz
Tar xzvf nginx_1.6.2.tar.gz
git clone git://github.com/arut/nginx-rtmp-module.git
3. Compiling nginx-rtmp
./configure--prefix=/usr/local/nginx--add-module=.. /nginx-rtmp-module--with-http_stub_status_module
Make
Make install
After the installation is complete, Nginx is located in the/usr/local/nginx/sbin directory, the configuration file nginx.conf in the/usr/local/nginx/conf directory
++++++++ test if Nginx is installed correctly +++++++++++
#cd/usr/local/nginx
#./sbin/nginx-c./conf/nginx.conf
Open the Web page http://localhost, if the display welcome means the installation is correct, if not shown, please check the Nginx log.
++++++++ Test rtmp+++++++++++
Modify the contents of the/usr/local/nginx/conf/nginx.conf as follows:
#debug
Daemon off;
Master_process off;
Error_log./error.log Debug;
events{
Worker_connections 1024;
}
rtmp{
server {
Listen 1935;
Chunk_size 4000;
#live
Application MyApp {
Live on;
}
}
Download an rtmp push flow tool from the Internet, I use the OBS (Open broadcaster Software), start pushing the stream rtmp://your_ip/myapp/test, using the player (http://www.cutv.com/demo/ LIVE_TEST.SWF) to see if it is OK.
++++++++ test HLS slicing function +++++++++++
Modify the contents of the/usr/local/nginx/conf/nginx.conf as follows:
#debug
Daemon off;
Master_process off;
Error_log./error.log Debug;
events{
Worker_connections 1024;
}
rtmp{
server {
Listen 1935;
Chunk_size 4000;
#live
Application MyApp {
Live on;
HLS on;
Hls_path/tmp/hls;
hls_fragment 2s;
Hls_playlist_length 6s;
}
}
}
#HTTP
http{
server {
Listen 80;
#welcome
location/{
root html;
index index.html index.htm;
}
#hls
Location/hls {
Types {
APPLICATION/VND.APPLE.MPEGUSR m3u8;
VIDEO/MP2T ts;
}
root/tmp;
Add_header Cache-control No-cache;
}
}
}
Use the player on the VLC or ipad to view the http://yourip/hls/test.m3u8.
++++++++ testing ffmpeg transcoding function +++++++++++
Modify the contents of the/usr/local/nginx/conf/nginx.conf as follows:
#debug
Daemon off;
Master_process off;
Error_log./error.log Debug;
events{
Worker_connections 1024;
}
rtmp{
server {
Listen 1935;
Chunk_size 4000;
#live
Application MyApp {
Live on;
Exec/opt/ffmpeg/bin/ffmpeg-i rtmp://localhost/myapp/$name
-c:a copy-c:v libx264-b:v 512k-g 30-f flv rtmp://localhost/hls/$name _low;
}
Application HLS {
Live on;
HLS on;
Hls_path/tmp/hls;
Hls_nested on;
hls_fragment 2s;
Hls_playlist_length 6s;
Hls_variant _hi bandwidth=640000;
}
}
}
#HTTP
http{
server {
Listen 80;
#welcome
location/{
root html;
index index.html index.htm;
}
#hls
Location/hls {
Types {
APPLICATION/VND.APPLE.MPEGUSR m3u8;
VIDEO/MP2T ts;
}
root/tmp;
Add_header Cache-control No-cache;
}
}
}
When using FFmpeg transcoding,
Exec/opt/ffmpeg/bin/ffmpeg-i rtmp://localhost/myapp/$name
-c:a copy-c:v libx264-b:v 512k-g 30-f flv rtmp://localhost/hls/$name _low;
Only transcoding the video, not processing the audio, while the stream from MyApp to HLS, Hls_variant will generate a multi-bitrate m3u8 file, while the tile file into the Test_low directory, access to multi-bitrate, direct access to Http://yourip/hls /test.m3u8, the corresponding bitstream is accessed based on the content implemented in this m3u8, in this case the actual stream URL is http://yourip/hls/test_low/index.m3u8
Nginx rtmp HLS Live