"Reprint" using Nginx to build HTTP and rtmp protocol streaming media server

Source: Internet
Author: User
Tags xsl
From//http://blog.chedushi.com/archives/6532?utm_source=tuicool

Using Nginx to build a streaming media server with HTTP and rtmp protocols

Experimental Purpose:
Allows Nginx to support FLV and MP4 format files while supporting RTMP protocol while opening the HLS function of rtmp
Information:
HTTP Live Streaming (abbreviated as HLS) is an HTTP-based streaming network Transfer protocol proposed by Apple.
HLS only requests basic HTTP messages, and unlike real-time Transport Protocol (RTP), HLS can pass through any firewall or proxy server that allows HTTP data to pass through. It is also easy to use a content distribution network to transfer media streams.
Use FFmpeg to complete the conversion of FLV, MP4, MP3 and other formats (on-demand experiments are not tested for the time being)
First, the preparatory work
Module: nginx_mod_h264_streaming (supports h264 encoded video)
Module: Http_flv_module Support flv
Module: Http_mp4_module support mp4
Module: Nginx-rtmp-module Support rtmp//2015-3-5 add
Download Address:
Http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
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
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:
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:
++++++++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..
#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:
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
Second, the installation of Nginx related modules
#tar ZXVF nginx_mod_h264_streaming-2.2.7.tar.gz
#git Clone Git://github.com/arut/nginx-rtmp-module.git
#tar ZXVF pcre-8.12.tar.gz
#cd pcre-8.12
#./configure
#make && make Install
#tar ZXVF nginx-1.2.6.tar.gz
#cd nginx-1.2.6
#./configure–prefix=/usr/local/nginx–add-module=. /nginx_mod_h264_streaming-2.2.7–with-http_flv_module–with-http_gzip_static_module–with-http_stub_status_module –with-http_mp4_module–add-module=. /nginx-rtmp-module–add-module=. /nginx-rtmp-module/hls–with-cc-opt=-i/opt/ffmpeg/include–with-ld-opt= '-l/opt/ffmpeg/lib-wl,-rpath=/opt/ffmpeg/ Lib
#make && make Install
Third, modify the nginx main configuration file, configure the virtual host (here we only configure and test on-demand, live, please see the Address for reference):
User nobody nobody;
Worker_processes 4;
Error_log Logs/nginx_error.log Info;
PID Logs/nginx.pid;
Worker_rlimit_nofile 51200;
Events
{
Use Epoll;
Worker_connections 51200;
}
#rtmp_auto_push on;
rtmp {
server {
Listen 1935;
Application VOD {
play/opt/media/nginxrtmp/flv;
}
}
}
http
{
Include Mime.types;
Default_type Application/octet-stream;
Server_names_hash_bucket_size 128;
Client_header_buffer_size 32k;
Large_client_header_buffers 4 32k;
Client_max_body_size 50m;
Limit_conn_zone $binary _remote_addr zone=perip:256k;
Limit_conn_log_level notice;
Sendfile on;
Tcp_nopush on;
Keepalive_timeout 6000; #测试并发临时调大
Tcp_nodelay on;
gzip on;
Gzip_min_length 1k;
Gzip_buffers 4 16k;
Gzip_http_version 1.0;
Gzip_comp_level 2;
Gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on;
#log format
Log_format Main ' $remote _addr– $remote _user [$time _local] "$request" '
' $status $body _bytes_sent ' $http _referer '
' "$http _user_agent" $http _x_forwarded_for ';
#支持flv
Server
{
Listen 8081;
server_name 192.168.0.33;
Root/opt/pub/media/nginx; #http协议时候, FLV video Location
Location ~. *. (flv|swf|mp4|wma|wmv) $ {
Valid_referers none blocked *.xxxx.com http://localhost;
if ($invalid _referer) {
return 403;
}
}
Location ~ \.flv$ {
flv
Limit_conn One, #限制客户端并发连接数
Limit_rate 200k; #限制每客户端最大带宽
}
Location ~ \.mp4$ {
flv
Limit_conn one 20;
Limit_rate 200k;
}
Access_log Logs/nginxflv_access.log Main;
}
Server
{
Listen 8082;
server_name 192.168.0.33;
Index index.html;
Location/{
root/opt/pub/media/nginx-rtmp;
}
Access_log Logs/nginxrtmpflv_access.log Main;
}
server {
Listen 8080;
Location/stat {
Rtmp_stat all;
Rtmp_stat_stylesheet stat.xsl;
}
location/stat.xsl {
Root/opt/pub/soft/nginx-rtmp-module;
}
Location/{
Root/opt/pub/soft/nginx-rtmp-module/test/rtmp-publisher;
}
}
Http://192.168.0.33:8080/stats View RTMP Customer request Information
http://192.168.0.33:8081/index.html flv video When viewing nginx HTTP protocol
http://192.168.0.33:8082/index.html flv video When viewing nginx rtmp protocol
Iv. Basic Functional Testing:
Player with open source player Jwplayer, place player in index.html sibling directory
Nginx-http test page index.html (remember to add keyframes to the video when HTTP is required)




<title>Test of Nginx-http</title>









Ndex.cgi? P1_prod_version=shockwaveflash "flashvars=" type=http&file=http://192.168.0.33:8081/2.flv&autostart=true "Wmode=" Opaq
UE "/>



NGINX-RTMP test Page index.html




<title>Nginx-rtmp</title>









Ndex.cgi? P1_prod_version=shockwaveflash "flashvars=" streamer=rtmp://192.168.0.33:1935/vod&file=2.flv&autostart= True "Wmode=" O
Paque "/>



The page can be turned on for normal playback to indicate that the configuration is correct.
V. Concurrent TESTING
Nginx-http with LoadRunner test (slightly)
NGINX-RTMP uses open source software FLAZR testing:
Prerequisites To install the JDK software
Client.bat Rtmp://192.168.0.33:1935/vod/2.flv-load 500
The 500 here is the number of concurrent

Due to the limitations of the local area network, bandwidth testing to a certain size when it is not to go, so step does not ignore.

The above describes the "reprint" using Nginx to build HTTP and rtmp protocol of the streaming media server, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.