Http://itindex.net/detail/48702-nginx-rtmp-http
One, streaming media playback mode
1. HTTP mode
this way to download the FLV video file to local playback, once the FLV video file download is complete, will not consume the server resources and bandwidth, but the drag function is not rtmp/rtmp streaming media powerful, many video sites are implemented in HTTP, such as: YouTube, potatoes, Cool 6 etc
2, rtmp/rtmp streaming media mode
This method does not download the FLV video file to the local, can play the FLV file in real-time, can drag and drop the progress bar, but compared to consume the resources of the server.
second, use Nginx to build FLV streaming Media server
1. Install git
yum install git
2. Installing dependent packages
yum-y Install gcc glibc glibc-devel make nasm pkgconfig lib-devel openssl-devel expat-devel gettext-devel libtool MH ash.x86_64 perl-digest-sha1.x86_64
3, install FFmpeg and its dependent package (my dependency package is installed under/USR/LOCAL/SRC, but the installation location can be determined according to personal habits)
The following installation package can be installed with Yum, as much as possible with Yum to install, no more wget to obtain.
#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:
#git Clone git://git.videolan.org/x264
#cd x264
#./configure--enable-shared
#make
#make Install
#cd:
#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:
#yum Install Libogg
Note: Libogg is based on online versions of the tutorials. tar.gz package to install, but install and then install LIBVORBIS,LIBVPX and so on will find no Libogg installation location, resulting in installation failure.
#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:
#git Clone Http://git.chromium.org/webm/libvpx.git
#cd libvpx
#./configure--enable-shared
#make
#make Install
#cd:
#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:
#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:
#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
Third, install the Nginx module
#wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
#tar zxvf nginx_mod_h264_streaming-2.2.7.tar.gz
#git Clone Git://github.com/arut/nginx-rtmp-module.git
#yum Install Pcre
Nginx did not find the address, can only be downloaded manually, and then uploaded.
#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
Installing Yamdi
The role of YADMI is to add keyframes to the FLV file to enable drag playback
#下载yadmi
wget http://sourceforge.net/projects/yamdi/files/yamdi/1.4/yamdi-1.4.tar.gz/download
#安装yadmi
tar xzvf yamdi-1.4.tar.gz
CD yamdi-1.4
Make && make install
How to use: Yamdi-i input.flv-o out.flv
add keyframes to the input.flv file, output as out.flv file
Four, modify the Nginx master configuration file
vi/usr/local/nginx/conf/nginx.conf
user www www;
worker_processes;
Error_log/usr/local/nginx/logs/error.log Crit;
Pid/usr/local/nginx/logs/nginx.pid;
Events {
Use epoll;
worker_connections 65535;
}
http {
include mime.types;
Default_type Application/octet-stream;
Log_format main ' $remote _addr-$remote _user [$time _local] '
" $request" $status $bytes _sent '
' "$http _referer" "$http _user_agent" '
' $gzip _ratio ';
keepalive_timeout;
server_names_hash_bucket_size;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
Access_log off;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types Text/plain;
output_buffers 1 32k;
Postpone_output 1460;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;
Tcp_nopush on;
tcp_nodelay on;
server {
Listen;
server_name 192.168.1.105;
root/usr/local/nginx/html/;
limit_rate_after 5m; # # #在flv视频文件下载了5M以后开始限速
limit_rate 512k; # # #速度限制为512K
index index.html;
CharSet Utf-8;
Location ~ \.flv {
flv;
}
Location ~ \.mp4$ {
mp4;
}
Error_page 502 503 504/50x.html;
Location =/50x.html {
root html;
}
}
}
Five, start Nginx
detect nginx.conf file configuration before starting
/usr/local/nginx/sbin/nginx-t-c/usr/nginx/conf/nginx.conf
or
/usr/nginx/sbin/nginx-t
If errors are corrected according to the number of error lines.
If error: [ERROR]: Invalid PID number "in"/var/run/nginx.pid "
usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf
nginx Boot
/usr/local/nginx/sbin/nginx-s Reload
Test
http://192.168.1.105/player.swf?type=http&file=test1.flv
(where player.swf is the player, test1.flv is a video file)
the player is to be put together with the video file.
the video file location corresponds to the location of the configuration in nginx.conf.
Download the attached article:
- Play.rar (KB)
- Nginx-0.8.55.tar.gz (632.6 KB)
The above describes the use of Nginx to build based on rtmp or HTTP flv, MP4 streaming media server, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.