Article Title: Build a flv Streaming Media Server using nginx. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
I, Introduction to FLV video publishing methods
There are two methods to publish FLV videos.
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 server resources,
II, Use nginx to build a flv Streaming Media Server
1. Introduction to using nginx to build a flv Streaming Media Server
The Flv Stream module in nginx can implement the flv streaming media function, and supports drag and drop of the flv video progress bar, in addition, the nignx can also act as a proxy Server to the back-end RTMP/RTMP Streaming Media Server Based on Flash Media Server or Red5.
2, Next we will build a complete nginx Streaming Media Server.
1) install the Nginx Server
# Installing zlib
Tar xzvf zlib-1.2.3.tar.gz
Cd zlib-1.2.3
./Configure
Make & make install
# Install pcre
Tar zxvf pcre-7.9.tar.gz
Cd pcre-7.9
./Configure -- prefix =/usr/local/pcre
Make & make install
# Install nginx
Groupadd www
Useradd-g www
Tar xzvf nginx-0.8.34.tar.gz
Cd nginx-0.8.34
. /Configure -- with-http_ssl_module -- with-pcre =/root/zhang/nginx/pcre-7.9 -- with-zlib =/root/zhang/nginx/zlib-1.2.3 -- user = www -- group = www -- prefix =/usr/local/webserver/nginx -- with-http_flv_module
Make & make install
2) 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.
3) Configure nginx
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/flv_file /;
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;
}
Error_page 500 502 503 x.html;
Location =/50x.html {
Root html;
}
}
}
4) The configuration has basically been completed, but we need a flash Player that supports drag-and-drop playback during the test. The open-source JW Player can implement this function, I will upload the compiled player for you to download:
Download link: http://blogimg.chinaunix.net/blog/upfile2/100607142612.rar
After downloading the player, upload it to the/usr/local/nginx/html/flv_file/directory set above, and close the file to put the flv video file in this directory!
5) Start nginx and test:
Http: // 192.168.1.105/player.swf? Type = http & file = test1.flv
Note: # My ip address is 192.168.1.105
Javasplayer.swf is my JW Player.
# Http indicates that the http distribution mode is used.
# Test1.flv is my flv video file
The effect is as follows:
Reprint please indicate the source http://blog.chinaunix.net/u3/93755/showart.php? Id = 2248589