nginx搭建流媒体服务器的方法详解

 

一、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或者Red5的RTMP/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

说明: #我的ip是192.168.1.105

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

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

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

时间: 2024-08-24 16:51:07

nginx搭建流媒体服务器的方法详解的相关文章

一步步安装nginx搭建流媒体服务器

先安装: apt-get install g++ apt-get install g++ apt-get install build-essential 一般已经安装了 在网上下载以下的包.后面我把这些包上传到csdn资源里,以后就不用找了. nginx-1.2.3.tar.gz      :应用服务器主程序 nginx_mod_h264_streaming-2.2.7.tar.gz      :MP4流媒体支持模块. openssl-1.0.1c.tar.gz                

centos 7下nginx搭建流媒体服务器【动态添加模块】

1.安装nginx依赖包 yum install gcc gcc-c++ openssl-devel zlib-devel pcre pcre-devel yamdi 2.下载解压nginx_mod_h264_streaming,让nginx支持flv,mp4流播放 wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz 解压后需要修改src目录下的ngx_http_streaming_modul

基于CentOS 7.x搭建OpenVPN服务器与配置详解

一.服务器程序安装: 1.安装依赖程序: 因为OpenVPN软件包不在CentOS标准Yum源里,所以需要安装先通过yum安装epel源才能正常安装相关软件包! [[email protected]~]# yum install epel-release [[email protected]~]# yum -y install lzo lzo-devel [[email protected] ~]# rpm -qa | grep "lzo" lzo-devel-2.06-8.el7.x

nginx-rtmp-module搭建流媒体服务器

nginx搭建流媒体服务器 进入新建的文件夹prog 1.下载nginx-rtmp-modulegit clone https://github.com/arut/nginx-rtmp-module.git 2.下载nginxwget http://nginx.org/download/nginx-1.14.0.tar.gz 3.下载nginx依赖模块gzip模块需要 zlib 库.rewrite模块需要 pcre 库.ssl 功能需要openssl库 ①安装pcre,只需要装开发库libpcr

nginx + rtmp 搭建流媒体服务器

一.安装nginx服务器 1.路径说明: 路径:/usr/local/src 2.下载nginx-rtmp-module (我这里的目录是在/usr/local/src/下面) cd /usr/local/src nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module git clone https://github.com/arut/nginx-rtmp-module.git ( 如果没有git进行安装,yu

Windows下Nginx Virtual Host多站点配置详解

Windows下Nginx Virtual Host多站点配置详解 此教程适用于Windows系统已经配置好Nginx+Php+Mysql环境的同学. 如果您还未搭建WNMP环境,请查看 windows7配置Nginx+php+mysql教程. 先说明一下配置多站点的目的:在生产环境中,如果将系统所有代码文件都放在公开目录中,则很容易被查看到系统源码,这样是很不安全的,所以需要只公开index.php的入口文件目录.而同一个服务器中,可能运行多个系统,这样就必须公开多个入口文件目录,以便用不同的

Android应用盈利广告平台的嵌入方法详解

一.如何学习Android   android开发(这里不提platform和底层驱动)你需要对Java有个良好的基础,一般我们用Eclipse作为开发工具.对于过多的具体知识详细介绍我这里不展开,我只说我个人的学习方法和本人以为的好的步骤.   1.搭建环境:包括对Java和Eclipse及模拟器(有真机再好不过)的熟悉,对于android的tools和adb命令可以放到后面熟悉了解.   2.从helloworld开始:了解一个基本的android应用代码包含哪些,各部分做什么用.(这里只要

centos6.5搭建流媒体服务器

下面开始介绍CentOS 6.5 64位上安装Darwin Streaming Server搭建RTSP流媒体服务器的方法:一.首先说明下我的系统环境:CentOS 6.5 64位最小化安装(用的CentOS-6.5-x86_64-minimal.iso),关闭iptables和SELINUX:# chkconfig iptables off# vi /etc/sysconfig/selinux(把enforcing修改为disabled,然后重启系统) 二.安装后至少需要安装以下5个组件,确保

obs nginx-rtmp-module搭建流媒体服务器实现直播 ding

接下来我就简单跟大家介绍一下利用nginx来搭建流媒体服务器. 我选择的是腾讯云服务器 1.下载nginx-rtmp-module: nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module 使用命令: [php] view plain copy git clone https://github.com/arut/nginx-rtmp-module.git 将nginx-rtmp-module下载到linux中.