centos 安装 STREAMING h264 视频的流播放 关于如何配置APACHE的STREAMING播放MP4的视频.

编程入门 行业动态 更新时间:2024-10-28 16:30:02

centos 安装 STREAMING h264 <a href=https://www.elefans.com/category/jswz/34/1771437.html style=视频的流播放 关于如何配置APACHE的STREAMING播放MP4的视频."/>

centos 安装 STREAMING h264 视频的流播放 关于如何配置APACHE的STREAMING播放MP4的视频.

确定已经安装httpd-devel,如果还没有安装的话,可以使用下面的命令安装:

yum install httpd-devel

下载apache_mod_h264_streaming
cd /usr/src

wget .2.7.tar.gz
tar zxvf  apache_mod_h264_streaming-2.2.7.tar.gz

cd mod_h264_streaming-2.2.7/
./configure –with-apxs=’which apxs’
make
make install


配置apache_mod_h264_streaming

 

vi /etc/httpd/conf/httpd.conf
增加下面两行

AddHandler h264-streaming.extensions .mp4
LoadModule h264_streaming_module /usr/local/apache/modules/mod_h264_streaming.so
重启apache :
/etc/init.d/httpd restart
Testing the H264 Streaming Module
To test and make sure the modules is working properly, try a mp4 video download to your document root directory:

cd /usr/local/apache/htdocs
wget -O test.mp4 “:8080/trailer2.mp4″
And then wget http://<your-server-ip/test.mp4?start=55.5 or access the url in your web browser.

This saves a file (test.mp4) on your local disk that will have the first 55.5 seconds removed from the original video file. Which you can check with your favorite video player.

You can also move the progress bar to forward and you should be able to see the videos are playing from where you seeked so this saves lot of bandwidth and time.

 参考文章:/

 

 

为nginx添加mp4支持模块

DDownloading and building the H264 Streaming Module for Nginx (version 2) ¶

Dependencies

For more information on downloading and installing Nginx, please read the official ​getting started instructions.

We will be using version 0.7.9 of Nginx.

cd ~
wget .7.9.tar.gz
tar zxvf nginx-0.7.9.tar.gz

Download

Download the source of the H264 Streaming Module for Nginx.

cd ~
wget .2.7.tar.gz
tar -zxvf nginx_mod_h264_streaming-2.2.7.tar.gz

Build

Run configure in the Nginx directory with the following additions to the commandline.

cd ~/nginx-0.7.9
./configure --add-module=$HOME/nginx_mod_h264_streaming-2.2.7 --sbin-path=/usr/local/sbin --with-debug

Make and install Nginx.

make
sudo make install

Configuration

Edit the configuration file (in /usr/local/nginx/conf/nginx.conf) so that file requests ending in ".mp4" are handled by the 'mp4' command. Add the following lines (around line 43).

location ~ \.mp4$ {mp4;
}

Start Nginx.

sudo /usr/local/sbin/nginx

License

This version is free if you agree to the ​noncommercial license. Please mention its use on your website, in the lines of 'This website uses H264 pseudo video streaming technology by ​CodeShop'.

Our commercial license is very inexpensive, see the following page to check if you need a commercial license.

Testing

Continue to the testing page to verify your setup.

Demo

See ​:83/demo/nginx/testlist.html for a demo running Nginx.




nginx可以作为流媒体来使用,但是需要相应的模块支持,如果要使用mp4模块,你需要安装nginx_mod_h264_streaming-2.2.7。

下面我们来进行安装
首先下载模块
你可以在官方网站上找到下载链接,官方网站地址

或者

 

1
2
wget .2.7.tar.gz
tar -zxvf nginx_mod_h264_streaming-2.2.7.tar.gz

 


补充一下:
nginx的编译安装的模块分为三种类型,标准模块(安装即启动)、参数模块(需要带参数启动)和第三方模块及补丁。
标准模块需要带without参数才能关闭,参数模块需要带with才能启动,需要下载源码用–add-module=PATH安装。

编译时要先拿到上次nginx编译的配置参数,以防止过多的改动。
nginx -v #查看nginx版本
nginx -V #查看编译配置参数

然后添加配置
–add-module=/data/download/nginx_mod_h264_streaming-2.2.7
重新编译安装:
sudo make && sudo make install

服务器配置实例:
location ~ .*.mp4${
mp4;
}

 

Nginx下搭建flv视频服务器且支持视频拖动进度条播放

.html

.html

.htm

目前,由于Flash的流行,网络上绝大多数的微视频网站都采用了Flv格式来播放视频。

在互联网上播放视频,有两种方式,一种是文件方式,即通过HTTP协议访问视频文件,这种方式的缺点是不能从特定的帧开始播放;另外一种就是采用专门的流媒体服务器,这种方式的缺点是要搭建复杂的流媒体服务器。不过,现在有了一种集合了以上两种方式优点的一种解决方案,即通过HTTP来实现伪流媒体。本文描述的就是这样的一种解决方案。

首先配置nginx服务支持flv模块功能

⑴查看你的nginx是否已支持flv功能模块

[root@localhost ~]# /usr/local/nginx/sbin/nginx -V  //查看nginx服务支持

结果:

nginx version: nginx/0.8.24

built by gcc 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC) 

configure arguments: --prefix=/usr/local/nginx --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module

分析:我的nginx版本0.8.24,http_flv_module已经开启,支持flv服务

⑵安装支持flv模块的nginx服务器:

#tar zxvf nginx-0.8.24.tar.gz

#cd nginx-0.8.24

#./configure --prefix=/usr/local/nginx  --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module //开启flv模块

#make && make install

#/usr/local/nginx/sbin/nginx       //启Nginx

⑶nginx服务器配置(nginx.conf文件)

server

  {

listen       80;

server_name  localhost;   

charset utf-8;

 location / {

            root   html;

            index  index.php index.html index.htm;

        }

  location ~ \.flv {

            flv;

   limit_rate_after 10m;

   limit_conn one 1;   

   limit_rate 85k;

        }

  }

使用location 将 .flv的文件指向flv模块即可。

以上使用了limit_rate 是为了限速,当 flv视频下载超过10M,则限速到85K,只允许用户开1个进程,也就是先快速缓存可以播放,后面的慢慢下载。

⑷安装支持flv拖放进度条的播放器

上面三步都是安装支持nginx服务支持flv功能的,现在需要支持flv拖放进度条的播放器.

你需要有一个能够播放Flv视频的播放器,很显然,它还需要能够嵌入到网页中。目前比较流行的,功能上也还比较完善的一个Flv播放器就是 JW FLV Media Player(也称为 jwplayer)。它的网址是:

/

这个播放器支持视频加入广告和视频节目单功能,

下载包里面有很全的实例和使用方式,

将包中的player.swf(如果是带有Viral插件的,就是player-viral.swf)放到你的网站内,这就是用来提供视频播放的播放器。至于包中其它的文件,都可以不要。

接下来,将播放器嵌入到你的视频播放网页中:

直接嵌入,使用Object/Embed代码嵌入:

<embed  

        type="application/x-shockwave-flash"  

        id="player2"  

        name="player2"  

        src="player.swf"   

        width="328"   

        height="200"  

        allowscriptaccess="always"   

        allowfullscreen="true"  

        flashvars="file=http://192.168.40.135/test.flv&image=http://192.168.40.135/preview.jpg&autostart=false&type=http&streamer=start"   

    >  </embed>

file:"video.flv", // FLV视频地址

type:"http",        // 数据类型,本文是基于http模式的,这个必须写滴

image:"preview.jpg",// 开始播放之前的预览图

autostart:"false",  // 是否自动播放

streamer:"start",   // 参数为 “start”,这个参数用于传递给服务器从特定的关键帧开始播放,nginx编译了 flv 模块 所以是支持的。。

⑸添加关键帧

如果一个Flv视频要能够被拖到特定点播放,该Flv需要在其metadata中有关键帧的信息。如果你的Flv视频制作的时候没有这些信息,也是不能拖放播放的。可以使用yamdi来为你的视频加上关键帧信息 :

安装:

1 [root@localhost ~]#wget .4/yamdi-1.4.tar.gz/download

2 [root@localhost ~]#tar zxvf yamdi-1.4.tar.gz

3 [root@localhost ~]#cd yamdi-1.4/

4 [root@localhost yamdi-1.4]#make && make install

使用方法:

yamdi -i source.flv -o dest.flv //原视频 输出视频

 

 

 

 

 

 

 

因为是编译安装,所以需要系统中装有gcc相关的包。

需要用到的源码包有nginx-1.0.4.tar.gz(.0.4.tar.gz)、pcre-8.12.tar.gz(.12.tar.gz)、nginx_mod_h264_streaming-2.2.7.tar.gz()。其中pcre-8.12是与perl兼容的正则表达式库模块,nginx-1.0.4是应用服务器主程序,nginx_mod_h264_streaming-2.2.7是MP4流媒体支持模块。

安装步骤如下:

1:解压缩各个压缩包

tar zxvf nginx-1.0.4.tar.gz

tar zxvf nginx_mod_h264_streaming-2.2.7.tar.gz

tar zxvf pcre-8.12.tar.gz

2:cd pcre-8.12

./configure

make

make install

3:cd nginx_mod_h264_streaming-2.2.7

根据实际情况修改Makefile文件中的NGINX项的值。NGINX=$(HOME)/nginx-1.0.4/ 版本的修改,查看$home $pwd路径对不对,不对修改之

4:cd nginx-1.0.4

./configure --sbin-path=/usr/local/sbin --without-http-cache --with-http_stub_status_module --with-http_gzip_static_module --with-pcre=/u02/software/nginx/pcre-8.12 --add-module=/u02/software/nginx/nginx_mod_h264_streaming-2.2.7

我安装时候的./configure --prefix=/home/zq/local/nginx --add-module=../nginx_mod_h264_streaming-2.2.7 --sbin-path=/home/zq/local/nginx/sbin --with-debug

之后make,

会报错【ngx_http_streaming_module.c:158: 错误:‘ngx_http_request_t’ 没有名为 ‘zero_in_uri’ 的成员】之类的错误。这需要修改nginx_mod_h264_streaming-2.2.7的源代码:修改ngx_http_streaming_module.c,注释掉

if (r->zero_in_uri)

  {

    return NGX_DECLINED;

  }

这一段。

之后make clean,之后重新configure,重新make,之后make install。

之后执行命令nginx,启动nginx服务器。访问http://ip:80出现Welcome to nginx! 时证明nginx安装成功。

Nginx安装完成之后安装路径在/usr/local/nginx。打开/usr/local/nginx/conf,修改nginx.conf配置文件,添加MP4支持。在server配置中添加如下配置即可

location ~ \.mp4$ {
mp4;
}

测试的话如下:

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

       下载链接:.rar

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

 

5)、启动nginx后测试:

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

             说明: #我的ip是192.168.1.105

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

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

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

 

 

更多推荐

centos 安装 STREAMING h264 视频的流播放 关于如何配置APACHE的STREAMING播放MP4的视频.

本文发布于:2024-03-09 00:04:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1722950.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视频   STREAMING   centos   APACHE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!