Use Nginx to build the FLV, MP4 streaming media server based on RTMP or HTTP

Source: Internet
Author: User
Tags flv file

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 mhash.x 86_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 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 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 80;
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)

Use Nginx to build the FLV, MP4 streaming media server based on RTMP or HTTP

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.