Nginx搭建rtmp流媒体服务器

康 林(2013年10月20日星期日)

1       功能:... 1

2       代码下载:... 1

3       编译:... 2

3.1             Linux下:... 2

3.2           windows下:... 2

3.2.1         官网提供的编译方法:... 2

3.2.1.1     预备:... 2

3.2.1.2     编译步骤:... 2

3.2.2         Cygwin下:... 3

4       Windows下的限制:... 3

5       访问URL格式:... 3

6       配置:... 3

6.1             点播配置:3

6.2             直播配置:... 5

1        功能:

1.1         视频、音频直播流(Live streaming of video/audio)

1.2         Flv、mp4视频需求,从本地或HTTP播放(Video ondemand FLV/MP4, playing from local filesystem or HTTP)

1.3         支持分布式流中继:推或拉模式(Stream relay support for distributed streaming: push & pullmodels)

1.4         录制FLVS流(Recording streams in multiple FLVs)

1.5         支持H264/AAC

1.6         在线用ffmpeg转码(Online transcoding with FFmpeg)

1.7         HLS (HTTP Live Streaming) 支持

1.8         基于http的操作(发布、播放、录制)(HTTP callbacks (publish/play/record/update etc))

1.9         在一定的事件中执行应用程序(Running external programs on certain events (exec))

1.10      HTTP control module forrecording audio/video and dropping clients

1.11      高级内存管理技术,快速流和低内存占用(Advanced buffering techniques to keep memory allocations at aminimum level for faster streaming and low memory footprint)

1.12      实践证明可以在下列产品中工作: Wirecast,FMS,Wowza, JWPlayer,FlowPlayer,StrobeMediaPlayback,ffmpeg,avconv,rtmpdump,flvstreamer and many more

1.13      Statistics in XML/XSL in machine-& human- readable form

1.14      Linux/FreeBSD/MacOS/Windows

2        代码下载:

Nginx:

官网:http://nginx.org/

下载:hg clone http://hg.nginx.org/nginx

nginx-rtmp-module:

官网:https://github.com/arut/nginx-rtmp-module

下载:git clone https://github.com/arut/nginx-rtmp-module.git

3        编译:

3.1         Linux下:

进入nginx源码根目录:

auto/configure--add-module=<path-to-nginx-rtmp-module>

make -f objs/Makefile

make -f objs/Makefile install

增加:http_ssl_module:

auto/configure--add-module=<path-to-nginx-rtmp-module> --with-http_ssl_module

3.2   windows下:

3.2.1 官网提供的编译方法:

http://nginx.org/en/docs/howto_build_on_win32.html

3.2.1.1 预备:

l  Microsoft Visual C compiler.Microsoft Visual Studio® 8 and 10

l  Msys

l  Perl(如果要编译OpenSSL并且nginx支持SLL),例如:ActivePerl 或 Strawberry Perl.

l  PCRE,zlib and OpenSSLlibraries sources.

3.2.1.2    编译步骤:

l  设置MSYS、Perl、VC环境变量

运行vc设置环境变量脚本vcvarsall.bat(默认安装路径:C:\Program Files\MicrosoftVisual Studio 9.0\VC)

l  开始MSYS

l  建立编译和库目录

mkdir objs

mkdir objs/lib

cd objs/lib

tar -xzf ../../pcre-8.32.tar.gz

tar -xzf ../../zlib-1.2.7.tar.gz

tar -xzf ../../openssl-1.0.1e.tar.gz

l  运行配置脚本:

auto/configure --with-cc=cl --builddir=objs--prefix= \

--conf-path=conf/nginx.conf--pid-path=logs/nginx.pid \

--http-log-path=logs/access.log--error-log-path=logs/error.log \

--sbin-path=nginx.exe--http-client-body-temp-path=temp/client_body_temp \

--http-proxy-temp-path=temp/proxy_temp \

--http-fastcgi-temp-path=temp/fastcgi_temp\

--with-cc-opt=-DFD_SETSIZE=1024--with-pcre=objs/lib/pcre-8.32 \

--with-zlib=objs/lib/zlib-1.2.7--with-openssl=objs/lib/openssl-1.0.1e \

--with-select_module --with-http_ssl_module--with-ipv6

运行脚本:

nmake –f objs/Makefile

3.2.2 Cygwin下:

linux

4        Windows下的限制:

Windows下下列功能不支持:

l  execs

l  static pulls

l  auto_push

windows下用的是select模式:

events{

worker_connections  30; #默认为(1024),windows默认为64,所以需要修改此值小于64

}

5        访问URL格式:

rtmp://rtmp.example.com/app[/name]

app-应该是配置文件中的application块

name-可以为空

6        配置:

在源码要目下有个test目录。其中有测试配置文件和脚本。

6.1         点播配置:

l  环境:

服务器IP为:192.168.10.4。

安装根路径:/usr/local/nginx

在你的配置时,需要把IP换成你的服务器IP或域名。

l  建立媒体文件夹:

mkdir /usr/local/nginx/vod/flvs

l  准备媒体文件:

把媒体文件 a.flv 复制到 /usr/local/nginx/vod/flvs目录下。

l  准备网页

下载jwplayer:http://www.longtailvideo.com/players/jw-flv-player/

下载后,解压到:/usr/local/nginx/html/

建立测试页面test.html,也放到上面目录下。

<html>

<head>

<scriptsrc="/jwplayer/jwplayer.js"></script>

</head>

<body>

<divid='my-video'></div>

<scripttype='text/javascript'>

jwplayer('my-video').setup({

file:'rtmp://192.168.10.4/vod/a.flv',

width:'50%',

aspectratio:'3:2',

fallback:'false',

primary:'flash'

});

</script>

</body>

</html>

l  在nginx中配置http

#配置事件工作线程数

events {

worker_connections  30; #默认为(1024),windows默认为64,所以需要修改此值小于64

}

#配置http

http {

include       mime.types;

default_type application/octet-stream;

#配置访问web页

server {

listen       80;

server_name  localhost;

#charset koi8-r;

#access_log logs/host.access.log  main;

location / {

root   html;

index  index.html index.htm;

}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html

#

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

}

#配置rtmp状态页

server {

listen      8080;

location /stat {

rtmp_stat all;

rtmp_stat_stylesheet stat.xsl;

}

location /stat.xsl {

root /usr/local/nginx/nginx-rtmp-module/;  #在nginx-rtmp-module源码根目录

}

}

}

#rtmp点播配置

rtmp {

server {

listen 1935;

chunk_size 4000;

application  vod {

play /usr/local/nginx/vod/flvs;  #点播媒体文件存放目录

}

}

}

l  启动nginx

./nginx

l  从客户端访问网页:

http://192.168.10.4/test.html

l  访问rtmp状态页(非必须):

http://192.168.10.4:8080/stat

6.2         直播配置:

l

l  在配置文件nginx.conf中加入

#rtmp直播配置

rtmp {

server {

listen 1935;

chunk_size 4000;

application  live {

live on;

}

}

}

#配置访问web页

http {

include       mime.types;

default_type application/octet-stream;

#配置访问web页

server {

listen       80;

server_name  localhost;

#charset koi8-r;

#access_log logs/host.access.log  main;

location / {

root   html;

index  index.html index.htm;

}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html

#

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

#配置rtmp状态页

server {

listen      8080;

location /stat {

rtmp_stat all;

rtmp_stat_stylesheet stat.xsl;

}

location /stat.xsl {

root /usr/local/nginx/nginx-rtmp-module/;  #在nginx-rtmp-module源码根目录

}

}

}

l  访问rtmp状态页(非必须):

http://192.168.10.4:8080/stat

可以查看rtmp流的统计情况

l  准备网页

下载jwplayer:http://www.longtailvideo.com/players/jw-flv-player/

下载后,解压到:/usr/local/nginx/html/

建立测试页面test.html,也放到上面目录下。

<html>

<head>

<scriptsrc="/jwplayer/jwplayer.js"></script>

</head>

<body>

<divid='my-video'></div>

<scripttype='text/javascript'>

jwplayer('my-video').setup({

file:'rtmp://192.168.0.128/live/test', #live是applicatioin,test是直播缓存流文件

width:'50%',

aspectratio:'3:2',

fallback:'false',

primary:'flash'

});

</script>

</body>

</html>

l  启动服务

nginx

l  推流

用ffmpeg产生一个模拟直播源,向rtmp服务器推送

ffmpeg –i/usr/local/nginx/vod/flvs/a.flv-strict -2 -c:v libx264 -c:a aac -f flv rtmp://192.168.10.4/live/test

注意,源文件必须是H.264+AAC编码的。

192.168.10.4是运行nginx的服务器IP,l

ive是applicatioin,

test是直播缓存流文件,需要与配置文件中的直播缓存文件名一样。

l  从客户端访问网页:

http://192.168.10.4/test.html

nginx+rtmp实现视频直播相关推荐

  1. nginx RTMP FFmpeg 视频直播

    /***************************************************************************** nginx RTMP FFmpeg 视频直 ...

  2. 树莓派使用nginx+rtmp搭建音频直播流媒体服务器

    前言 想使用树莓派连接usb音频采集卡实时采集收音机接收到的音频,树莓派上运行着由nginx+RTMP 搭建的直播流媒体服务器,这样就可以在客户端上通过支持rtmp串流协议的播放器就可以正常接收到音频 ...

  3. 在直播软件搭建中,如何基于rtmp实现视频直播?

    最近几年直播软件搭建可谓大火,这也就导致了在视频直播领域,有不同的商家提供各种的商业解决方案,包括软硬件设备,摄像机,编码器,流媒体服务器等.本文要讲解的是在直播软件搭建中,如何基于rtmp实现视频直 ...

  4. 服务器搭建和使用 ubuntu_Ubuntu中使用Nginx+rtmp搭建流媒体直播服务

    一.背景 本篇文章是继上一篇文章<Ubuntu中使用Nginx+rtmp模块搭建流媒体视频点播服务>文章而写,在上一篇文章中我们搭建了一个点播服务器,在此基础上我们再搭建一个直播服务器, ...

  5. Android开发基于RTMP实现视频直播

    前言 近两年时间,视频直播可谓大火.在视频直播领域,有不同的商家提供各种的商业解决方案,包括软硬件设备,摄像机,编码器,流媒体服务器等.本文要讲解的是如何使用一系列免费工具,打造一套视频直播方案. 视 ...

  6. php 直播服务器搭建,基于Nginx搭建RTMP/HLS视频直播服务器

    1.Nginx环境搭建(基于lnmp环境)//下载并安装lnmp环境 wget -c http://soft.vpser.net/lnmp/lnmp1.3.tar.gz && tar ...

  7. nginx视频直播/点播服务干货分享

    近年互联网直播业务非常火热.我也研究了下,发现nginx上配置视频直播点播也很容易实现,特分享一下. 一.ubuntu14.04安装nginx及nginx_rtmp_module扩展 nginx根据是 ...

  8. nginx视频直播/点播服务干货分享 1

    近年互联网直播业务非常火热.我也研究了下,发现nginx上配置视频直播点播也很容易实现,特分享一下. 一.ubuntu14.04安装nginx及nginx_rtmp_module扩展  nginx根据 ...

  9. LiveQing视频点播RTMP推流直播服务支持H5无插件WebRTC超低延时视频直播

    LiveQing视频点播RTMP推流直播服务支持H5无插件WebRTC超低延时视频直播 1.WebRTC超低延时视频直播 2.WebRTC延时对比 3.LiveQing播放WebRTC流 4.分屏页面 ...

最新文章

  1. 习惯几乎可以绑住一切,只是不能绑住偶然。比如那只偶然尝了鲜血的老虎。...
  2. MFC指定位置画位图
  3. SqlServer修改数据库文件及日志文件存放位置
  4. 尚硅谷springcloud第二季笔记_外行人都能看懂的 Spring Cloud,错过了血亏
  5. C和指针之数组编程练习3(判断矩阵是否为单位矩阵)
  6. Android 开源优秀 Library 推荐
  7. 华为仿苹果字体_华为mate40系列再次霸榜DXO,网友:无敌是多么寂寞
  8. cv_bridge 调用ros自带的opencv版本的解决
  9. 基于jquery的复选树的插件
  10. 存储过程(简单入门)
  11. java简单数据类型的知识点
  12. [dotnet]以最小的成本,落地微服务特色的DevOps管道,持续集成/部署到kubernetes。...
  13. 在网页输入框输入角标_这个免费插件能帮我们把Excel内容快速填充到网页表单?...
  14. mysql报错You do not have the SUPER privilege and binary logging is enabled
  15. 《Windows核心编程》读书笔记二十五章 未处理异常,向量化异常处理与C++异常
  16. 日记侠:你真的想知道引流的方法吗?
  17. Ubuntu服务器设置简体中文
  18. web前端-HTML-表格
  19. 小程序商城怎么开?开发商城小程序流程步骤介绍
  20. Dingtalk 发送消息

热门文章

  1. 吊打A8X 英伟达Tegra X1性能测试出炉
  2. 使用SQL语句创建数据表(SQL Server)
  3. CycleBeads:App不仅能避孕,成功率还有95%
  4. [34期] 来兄弟连初感受
  5. 香港金管局正式推出商业数据通
  6. 安阳7中计算机绘画知识,美术基础知识测试题及答案
  7. Himall商城文件操作接口Images
  8. urllib库的使用(一篇就够了)
  9. impdp、expdp监控数据备份恢复完成进度(EXPDP/IMPDP/RMAN)
  10. 让我们搞搞清楚重写toString()到底是个什么玩意?