: This article mainly introduces how to use nginx to build flv and mp4 streaming media servers based on rtmp or http. if you are interested in PHP tutorials, refer to it. Http://itindex.net/detail/48702-nginx-rtmp-http
I. streaming media playback mode
1. HTTP
In this way, you need to download the FLV video file and play it locally. Once the FLV video file is downloaded, the server's resources and bandwidth will not be consumed. However, the drag function is not as powerful as the RTMP/RTMP streaming media, many video websites use HTTP, such as YouTube, Tudou, and cool 6.
2. RTMP/RTMP streaming media
In this way, you do not need to download the FLV video file to the local device. you can play the flv file in real time and drag the playback progress bar at will, but it consumes resources on the server.
2. use nginx to build a flv streaming media server
1. install git
Yum install git
2. install the dependency package
Yum-y install gcc glibc-devel make nasm pkgconfig lib-devel openssl-devel expat-devel gettext-devel libtool mhash. x86_64 perl-Digest-SHA1.x86_64
3. install ffmpeg and its dependent packages (my dependent packages are installed under/usr/local/src, but the installation location can be determined according to your habits)
The following installation packages can be installed using yum. try to install them using yum. if not, use wget.
# 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: the courses on the libogg.pdf network are all installed using the .tar.gz package. However, after installing libvorbis and libvpx, you will find that the libogg installation location cannot be found, 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/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
3. 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 does not find the address. you can only download it manually and then upload it.
# 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
Install yamdi
Yadmi is used to add a key frame to the flv file for drag playback.
# Download yadmi
Wget http://sourceforge.net/projects/yamdi/files/yamdi/1.4/yamdi-1.4.tar.gz/download
# Install yadmi
Tar xzvf yamdi-1.4.tar.gz
Cd yamdi-1.4
Make & make install
Usage: yamdi-I input. flv-o out. flv
Add a key frame to the input. flv file and output it to the out. flv file.
4. modify the nginx main configuration file
Vi/usr/local/nginx/conf/nginx. conf
User www;
Worker_processes 30;
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 60;
Server_names_hash_bucket_size 128;
Client_header_buffer_size 32 k;
Large_client_header_buffers 4 32 k;
Access_log off;
Gzip on;
Gzip_min_length 1100;
Gzip_buffers 4 8 k;
Gzip_types text/plain;
Output_buffers 1 32 k;
Post pone_output 1460;
Client_header_timeout 3 m;
Client_body_timeout 3 m;
Send_timeout 3 m;
Sendfile on;
Tcp_nopush on;
Tcp_nodelay on;
Server {
Listen 80;
Server_name 192.168.1.105;
Root/usr/local/nginx/html /;
Limit_rate_after 5 m; #### the speed limit starts after the flv video file is downloaded for 5 MB.
Limit_rate 512 k; #### speed limit: 512 K
Index index.html;
Charset UTF-8;
Location ~ \. Flv {
Flv;
}
Location ~ \. Mp4 $ {
Mp4;
}
Error_page 500 502 503 x.html;
Location =/50x.html {
Root html;
}
}
}
5. start nginx
Check nginx. conf file configuration before Startup
/Usr/local/nginx/sbin/nginx-t-c/usr/nginx/conf/nginx. conf
Or
/Usr/nginx/sbin/nginx-t
If an error occurs, correct the error based on the number of lines reported.
If an error is reported: [error]: invalid PID number "" in "/var/run/nginx. pid"
Usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx. conf
Start nginx
/Usr/local/nginx/sbin/nginx-s reload
Test
Http: // 192.168.1.105/player.swf? Type = http & file = test1.flv
(Player.swf is the player and test1.flv is the video file)
The player must be put together with the video file.
The video file location corresponds to the configuration location in nginx. conf.
Download the attachment:
- Play.rar (89 KB)
- Nginx-0.8.55.tar.gz (632.6 KB)
The above describes how to use nginx to build a flv or mp4 streaming media server based on rtmp or http, including some content, and hope to help friends who are interested in PHP tutorials.