FLV 的另类实现方法

 

 

    还有一种方法是通过nginx_mod_h264_streaming来实现的,我们看一下。

 

下载nginx_mod_h264_streaming模块

 

[root@flv ~]wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz

[root@flv ~]# tar -zxvf nginx_mod_h264_streaming-2.2.7.tar.gz

   

修改Makefile

 

可能需要修改Makefile文件,根据实际情况修改:

 

[root@mail nginx_mod_h264_streaming-2.2.7]# vi Makefile

 

# vim:noexpandtab:sw=2 ts=2

 

.PHONY: all dist install clean

 

HOME=$(shell echo ~)

PWD=$(shell pwd)

#NGINX=$(HOME)/nginx-0.8.29/

#NGINX=$(HOME)/nginx-0.7.33/

 NGINX=/root/nginx-1.0.2/

 

VERSION=`./version.sh`

DIST_NAME=nginx_mod_h264_streaming-$(VERSION)

 

all:

        cd $(NGINX) && ./configure --sbin-path=/usr/local/sbin --add-module=/root/nginx_mod_h264_streaming-2.2.7 --with-debug --with-http_flv_module

        make --directory=$(NGINX)

 

……//省略

 

注意黑体字部分,它使用了HttpFlvStreamModule模块,即--with-http_flv_module参数

 

编译安装

 

[root@flv nginx-1.0.2]# ./configure  --prefix=/usr/local/nginx-1.0.2-h264-flv   --add-module=/root/nginx_mod_h264_streaming-2.2.7

[root@flv nginx-1.0.2]#make

[root@flv nginx-1.0.2]#make install

 

如果在configure过程中出现以下错误:

 

/root/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c: In function ‘ngx_streaming_handler’:

/root/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c:158: error: ‘ngx_http_request_t’ has no member named ‘zero_in_uri’

make[1]: *** [objs/addon/src/ngx_http_h264_streaming_module.o] Error 1

make[1]: Leaving directory `/root/nginx-0.8.54'

make: *** [build] Error 2

 

 

那么将src/ngx_http_streaming_module.c文件中以下代码删除或者是注释掉就可以了:

 

/* TODO: Win32 */

if (r->zero_in_uri)

{

return NGX_DECLINED;

}

   

    如果你没有对这个文件做个更改,那么应该在源码的第157-161行。这个问题是由于版本原因引起,在此不再讨论。

  

修改完之后,记得先执行make clean,然后再进行重新执行configuremake,最后make install

 

nginx_mod_h264_streaming模块的用法

 

    另外,我们再看一下src/ngx_http_streaming_module.c这个文件,看以下部分:

 

[root@flv nginx_mod_h264_streaming-2.2.7]# vi  src/ngx_http_streaming_module.c

 

 

#if 0

/* Mod-H264-Streaming configuration

 

server {

  listen 82;

  server_name  localhost;

 

  location ~ \.mp4$ {

    root /var/www;

    mp4;

  }

}

 

*/

 

/* Mod-Smooth-Streaming configuration

 

server {

  listen 82;

  server_name localhost;

 

  rewrite ^(.*/)?(.*)\.([is])sm/[Mm]anifest$ $1$2.$3sm/$2.ismc last;

  rewrite ^(.*/)?(.*)\.([is])sm/QualityLevels\(([0-9]+)\)/Fragments\((.*)=([0-9]+)\)(.*)$ $1$2.$3sm/$2.ism?bitrate=$4&$5=$6 last;

 

  location ~ \.ism$ {

    root /var/www;

    ism;

  }

}

*/

#endif

   

添加配置

 

    在这个源码文件中嵌入了该模块的用法,注意黑体字部分,因此我们的配置文件应该这么写:

 

server {

 listen       80;

 server_name  192.168.1.105;

 root    html;

 limit_rate_after 5m;   

 limit_rate 512k;        

index   index.html;

 location ~ \.flv$ {

    root /var/www/flv;

  mp4;

location ~ \.mp4$ {

    root /var/www/mp4;

    mp4;

  }

 

}

   

访问测试

   

启动Nginx,访问http://flv.xx.com/player.swf?type=http&file=4315.mp4

 

 

    如果我们在执行configure时使用了--with-http_flv_module选项,例如:

 

[root@flv nginx-1.0.2]# ./configure  --prefix=/usr/local/nginx-1.0.2-mp4-flv   --add-module=/root/nginx_mod_h264_streaming-2.2.7 --with-http_flv_module

   

    那么在Nginx的配置文件中可以这么配置:

 

 location ~ \.flv$ {

    root /var/www/flv;

  flv;

}  

location ~ \.mp4$ {

    root /var/www/mp4;

    mp4;

  }

   

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27043155/viewspace-735288/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27043155/viewspace-735288/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值