nginx搭建flv、mp4流媒体服务器

 

一、FLV视频发布方式简介

FLV视频有两总发布方式

1  HTTP方式

这种方式要下载FLV视频文件到本地播放,一旦FLV视频文件下载完成,就不会消耗服务器的资源和带宽,但是拖动功能没有RTMP/RTMP流媒体方式强大,很多视频网站都是用HTTP方式实现的,如:YouTube,土豆,酷6

2  RTMP/RTMP流媒体方式

这种方式不用下载FLV视频文件到本地,可以实时的播放flv文件,可以任意拖拽播放进度条,但是比较消耗服务器的资源,

 

 

二、使用nginx来搭建flv流媒体服务器

1、使用nginx来搭建flv流媒体服务器简介

nginx中的Flv Stream模块能实现flv流媒体的功能,而且支持flv视频进度条拖拽,另外nignx还可以作为方向代理服务器代理后端基于Flash Media Server或者Red5RTMP/RTMP流媒体服务器

 

2  下面我们就来搭建一个完整的nginx流媒体服务器

1)、Nginx服务器的安装

                     #安装zlib

tar xzvf zlib-1.2.3.tar.gz

                     cd zlib-1.2.3

                     ./configure

                     make && make install

                    #安装pcre

                     tar zxvf pcre-7.9.tar.gz

                     cd pcre-7.9

                     ./configure --prefix=/usr/local/pcre

                     make && make install

                     #添加mp4支持模块

                     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

                     #安装nginx

groupadd www

                     useradd -g www www

                  tar xzvf nginx-0.8.34.tar.gz

                  cd nginx-0.8.34

                         ./configure --add-module=../nginx_mod_h264_streaming-2.2.7 --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/nginx --with-http_flv_module --with-http_stub_status_module

                     make && make install

2)、安装yamdi

        yadmi的作用是为flv文件添加关键帧,才能实现拖动播放

                    #下载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

      使用方法:yamdi -i input.flv -o out.flv

      input.flv文件 添加关键帧,输出为out.flv文件

         3)、配置nginx

               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/flv_file/;

        limit_rate_after 5m;    ####flv视频文件下载了5M以后开始限速
        limit_rate 512k;         ####
速度限制为512K

        index   index.html;

        charset utf-8;

        location ~ \.flv {

            flv;

        }

        location ~ \.mp4$ {
                 mp4;
        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

 

}

}

 

4)、基本上已经设置完毕,但是此时我们测试的时候还需要一个支持拖拽播放的flash播放器,开源的JW Player就可以实现这样的功能,我将编译的播放器上传上来,供大家下载:

       下载链接:http://blogimg.chinaunix.net/blog/upfile2/100607142612.rar

       下载播放器后,上传到上面设置的/usr/local/nginx/html/flv_file/目录下,闭关把flv视频文件也放到该目录下!

 

5)、启动nginx后测试:

       http://192.168.1.105/player.swf?type=http&file=test1.flv

             说明: #我的ip192.168.1.105

                          #player.swf是我的JW Player播放器

                          #http是表示居于http分发方式

                          #test1.flv是我的flv视频文件

             效果如下图:

nginx搭建flvmp4流媒体服务器


<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->

-------转载请注明出处 http://blog.chinaunix.Net/u3/93755/showart.php?id=2248589
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->

 

一、FLV视频发布方式简介

FLV视频有两总发布方式

1  HTTP方式

这种方式要下载FLV视频文件到本地播放,一旦FLV视频文件下载完成,就不会消耗服务器的资源和带宽,但是拖动功能没有RTMP/RTMP流媒体方式强大,很多视频网站都是用HTTP方式实现的,如:YouTube,土豆,酷6

2  RTMP/RTMP流媒体方式

这种方式不用下载FLV视频文件到本地,可以实时的播放flv文件,可以任意拖拽播放进度条,但是比较消耗服务器的资源,

 

 

二、使用nginx来搭建flv流媒体服务器

1、使用nginx来搭建flv流媒体服务器简介

nginx中的Flv Stream模块能实现flv流媒体的功能,而且支持flv视频进度条拖拽,另外nignx还可以作为方向代理服务器代理后端基于Flash Media Server或者Red5RTMP/RTMP流媒体服务器

 

2  下面我们就来搭建一个完整的nginx流媒体服务器

1)、Nginx服务器的安装

                     #安装zlib

tar xzvf zlib-1.2.3.tar.gz

                     cd zlib-1.2.3

                     ./configure

                     make && make install

                    #安装pcre

                     tar zxvf pcre-7.9.tar.gz

                     cd pcre-7.9

                     ./configure --prefix=/usr/local/pcre

                     make && make install

                     #添加mp4支持模块

                     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
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->

                     #安装nginx

groupadd www

                     useradd -g www www

                  tar xzvf nginx-0.8.34.tar.gz

                  cd nginx-0.8.34

                         ./configure --add-module=../nginx_mod_h264_streaming-2.2.7 --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/nginx --with-http_flv_module --with-http_stub_status_module

                     make && make install

2)、安装yamdi

        yadmi的作用是为flv文件添加关键帧,才能实现拖动播放

                    #下载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

      使用方法:yamdi -i input.flv -o out.flv

      input.flv文件 添加关键帧,输出为out.flv文件

         3)、配置nginx

               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/flv_file/;

        limit_rate_after 5m;    ####flv视频文件下载了5M以后开始限速
        limit_rate 512k;         ####
速度限制为512K
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->

        index   index.html;

        charset utf-8;

        location ~ \.flv {

            flv;

        }

        location ~ \.mp4$ {
                 mp4;
        }
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

 

}

}

 

4)、基本上已经设置完毕,但是此时我们测试的时候还需要一个支持拖拽播放的flash播放器,开源的JW Player就可以实现这样的功能,我将编译的播放器上传上来,供大家下载:

       下载链接:http://blogimg.chinaunix.net/blog/upfile2/100607142612.rar

       下载播放器后,上传到上面设置的/usr/local/nginx/html/flv_file/目录下,闭关把flv视频文件也放到该目录下!

 

5)、启动nginx后测试:

       http://192.168.1.105/player.swf?type=http&file=test1.flv

             说明: #我的ip192.168.1.105

                          #player.swf是我的JW Player播放器

                          #http是表示居于http分发方式

                          #test1.flv是我的flv视频文件

 

          

 

-------转载请注明出处 http://blog.chinaunix.NET/u3/93755/showart.PHP?id=2248589

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值