nginx+ffmpeg搭建rtmp转播rtsp流的flash服务器
本文概要:
nginx是非常优秀的开源服务器,用它来做hls或者rtmp流媒体服务器是非常不错的选择。本文介绍了一种简易方法快速搭建rtmp流媒体服务器,也叫rtsp转播,数据源不是读取文件,而是采用获取rtspNal流后使用ffmpeg转播。csdn固本培元:leoluopy@gmail.com
开发环境:centos6.4 (主流的linux服务器选择,30%以上的市场占有率)
需要这几个包。
版本号:nginx 1.7.3 openssl 1.0.2 rtmp-module(版本未知)
资源:这些都是公网下载的资源,有需要的朋友,可以给我email或者评论留言。email:leoluopy@gmail.com
注意:先编译openssl 然后编译nginx
编译选项:
./configure --add-module=../nginx-rtmp-module-master --without-http_rewrite_module --with-openssl=../openssl-1.0.2-beta2
一路通过
启动时可能出现错误:
Starting nginx: nginx: [emerg] unknown directive "rtmp" in /etc/nginx/nginx.conf:9
没有识别rtmp模块。
另外一种可能,原有centos从源安装了nginx,它不带rtmp模块,需要卸载。
安装编译好的nginx后:
进入:
/usr/local/nginx/sbin
./nginx -c /usr/local/nginx/conf/nginx.conf
(注意:后面的需要是绝对地址)
ffmpeg推流 (如果没有flv文件,可以用264,ts这些文件转换,ffmpeg的常用命令本博客另一篇文章也有简要介绍)
ffmpeg -re -i IpCam.flv -f flv rtmp://localhost/myapp/test1
ffmpeg -re -i IpCam.flv -f flv -b 20000000 rtmp://localhost/myapp/test1
实时rtsp转rtmp直播流(其实转了rtmp之后会多几秒钟的延迟,不同客户端还不一定一致,我们这里测试的是JWplayer 3秒左右(后面用了个flex的方案,时间延迟提升到2s),稳定时可以在1秒左右,vlc播放器更长了10秒 ~_~! ,客户端的话还是就用rtsp吧,这样很快,一般延迟可以忽略不计,rtmp本来就是为web端设计的)
rtsp流的获取方法可以参考另外一篇文章:http://blog.csdn.net/gubenpeiyuan/article/details/19072223
ffmpeg -re -i RealStream.fifo -f flv -b 20000000 rtmp://localhost/myapp/test1
RealStream.fifo 是创建的fifo。 命令: mkfifo RealStream.fifo
启动rtsp获取Nal添加sps和pps位,之后打开fifo实时写入即可。
使用vlc测试如下:
此后可以将实时流推送到rmp了。
我的方案是live555接收流,串流方式推送至fifo,做rtmp的转发。可能有些延迟,哪位朋友有更好的方案,欢迎交流评论。
其框架如下:非常简单,并容易集成入大流媒体框架。
Flex方案截图:
附录:
RTMP配置如下:
- #user nobody;
- worker_processes 1;
- #error_log logs/error.log;
- #error_log logs/error.log notice;
- #error_log logs/error.log info;
- #pid logs/nginx.pid;
- events {
- worker_connections 1024;
- }
- rtmp {
- server {
- listen 1935;
- application myapp {
- live on;
- #record keyframes;
- #record_path /tmp;
- #record_max_size 128K;
- #record_interval 30s;
- #record_suffix .this.is.flv;
- #on_publish http://localhost:8080/publish;
- #on_play http://localhost:8080/play;
- #on_record_done http://localhost:8080/record_done;
- }
- application hls {
- live on;
- hls on;
- hls_path /tmp/app;
- hls_fragment 5s;
- }
- }
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- # '$status $body_bytes_sent "$http_referer" '
- # '"$http_user_agent" "$http_x_forwarded_for"';
- #access_log logs/access.log main;
- sendfile on;
- #tcp_nopush on;
- #keepalive_timeout 0;
- keepalive_timeout 65;
- #gzip on;
- 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;
- }
- # proxy the PHP scripts to Apache listening on 127.0.0.1:80
- #
- #location ~ \.php$ {
- # proxy_pass http://127.0.0.1;
- #}
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- #
- #location ~ \.php$ {
- # root html;
- # fastcgi_pass 127.0.0.1:9000;
- # fastcgi_index index.php;
- # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
- # include fastcgi_params;
- #}
- # deny access to .htaccess files, if Apache's document root
- # concurs with nginx's one
- #
- #location ~ /\.ht {
- # deny all;
- #}
- }
- # another virtual host using mix of IP-, name-, and port-based configuration
- #
- #server {
- # listen 8000;
- # listen somename:8080;
- # server_name somename alias another.alias;
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
- # HTTPS server
- #
- #server {
- # listen 443 ssl;
- # server_name localhost;
- # ssl_certificate cert.pem;
- # ssl_certificate_key cert.key;
- # ssl_session_cache shared:SSL:1m;
- # ssl_session_timeout 5m;
- # ssl_ciphers HIGH:!aNULL:!MD5;
- # ssl_prefer_server_ciphers on;
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
- }
参考文章:
nginx的RTMP协议服务器
http://www.cnblogs.com/aHuner/p/3247068.html
用开源nginx-rtmp-module搭建flash直播环境
http://www.rosoo.net/a/201307/16696.html
http://blog.csdn.net/cjsafty/article/details/7922849
基于nginx的hls直播系统(记录了rtmp的问题和解决方法)
http://blog.csdn.net/cjsafty/article/details/9108587
C++实现RTMP协议发送H.264编码及AAC编码的音视频
http://www.cnblogs.com/haibindev/archive/2011/12/29/2305712.html
Centos安装FLASHPlayer插件
http://www.linuxidc.com/Linux/2013-03/81073.htm
ffmpeg推流
ffmpeg -re -i ~/2012.flv -f flv rtmp://192.168.1.102/myapp/test1
ffmpeg -re -i IpCam.h264 -vcodec copy -f flv -b 20000000 rtmp://localhost/myapp/test1
nginx+ffmpeg搭建rtmp转播rtsp流的flash服务器的更多相关文章
- Windows使用Nginx+ffmpeg搭建RTMP服务器
简介Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.nginx-rmtp-module是Nginx服务器的流媒体插件.nginx通过rtmp模块提供r ...
- ffmpeg处理rtmp/文件/rtsp的推流和拉流
ffmpeg处理rtmp/文件/rtsp的推流和拉流 本demo演示了利用ffmpeg从服务器拉流或本地文件读取流,更改流url或文件类型名称发送回服务器或存到本地的作用. 由于本程序只写了3个小 ...
- 基于Nginx+nginx-rtmp-module+ffmpeg搭建rtmp、hls流媒体服务器
上篇文章是基于Red5与ffmpeg实现rtmp处理NVR或摄像头的监控视频处理方案,有兴趣的朋友可以查看. Nginx及nginx-rtmp-module安装 新建目录 mkdir /usr/loc ...
- 使用ffmpeg向crtmpserver发布rtsp流
ffmpeg的调用命令如下: ffmpeg -re -i xxx.mp4 -vcodec copy -acodec copy -f rtsp rtsp://127.0.0.1/live/mystre ...
- 基于Nginx+nginx-rtmp-module+ffmpeg搭建rtmp、hls流媒体服务器(二)
前言 Nginx-rtmp-module插件针对RTMP协议中一些命令,实现了事件通知和exec外部脚本处理.这里我通过一个简单的SpringBoot项目和Python代码,快速搭建一个HTTP服务来 ...
- nginx::基于Nginx+nginx-rtmp-module+ffmpeg搭建rtmp、hls流媒体服务器
待续 ffmpeg -re -i "/home/bk/hello.mp4" -vcodec libx264 -vprofile baseline -acodec aac -ar 4 ...
- 使用Nginx+FFMPEG搭建HLS直播转码服务器
目的:使Nginx支持Rtmp协议推流,并支持hls分发功能及FFMPEG转码多码率功能. 一.准备工作 模块:nginx-rtmp-module-master(支持rtmp协议) 下载地址: htt ...
- 利用nginx搭建RTMP视频点播、直播、HLS服务器(转)
开发环境 Ubuntu 14.04 server nginx-1.8.1 nginx-rtmp-module nginx的服务器的搭建 安装nginx的依赖库 sudo apt-get update ...
- 利用nginx搭建RTMP视频点播、直播、HLS服务器
开发环境 Ubuntu 14.04 server nginx-1.8.1 nginx-rtmp-module nginx的服务器的搭建 安装nginx的依赖库 sudo apt-get update ...
随机推荐
- angular中的orderBy过滤器使用
一 orderBy过滤器 AngularJS中orderBy进行排序,第一个参数可以有三种类型,分别为:function,string,array: 第一种:function,如果是func ...
- 树莓派实现TimeMachine以及samba服务
最近一段时间感觉用移动硬盘备份Mac电脑很不方便,因为要把移动硬盘拿出来,还要插上电脑备份,看了一下AirPort,但是价钱太贵,况且只能用于Mac备份并不能用于其他的Samba服务等,感觉不太划算, ...
- xml simpleXML_load_file(), simpleXML_load_string()
xml.xml文件 <?xml version='1.0'?><man> <att> <name>lin3615</name& ...
- springdata整合mongodb一些方法包括or,and,regex等等《有待更新》
这几天接触mongodb以及springdata,自己英语比较戳,所以整理这些方法花的时间多了点,不过也是我第一次在外国网站整理技术 不多说,直接上代码,这里只是给出一些操作方法而已,如果有需要源码的 ...
- javascript中的变量作用域以及变量提升详细介绍
在javascript中, 理解变量的作用域以及变量提升是非常有必要的.这个看起来是否很简单,但其实并不是你想的那样,还要一些重要的细节你需要理解变量作用域 “一个变量的作用域表示这个变量存在的上下文 ...
- 推荐:PHPCMS v9 安全防范教程!
一.目录权限设置很重要:可以有效防范黑客上传木马文件. 如果通过 chmod 644 * -R 的话,php文件就没有权限访问了. 如果通过chmod 755 * -R 的话,php文件的权限就高了. ...
- Python工程文件中的名词解释---Module与Package的区别
当我们在已有的Python工程文件中创建新的内容是,通常会有两种类型文件供你选择---Module和Package,对于初学者来说会搞不清楚这两种文件直接的关系.这里就来解释一下这两者之间的关系. M ...
- Codeforces 612E - Square Root of Permutation
E. Square Root of Permutation A permutation of length n is an array containing each integer from 1 t ...
- Hive 自定义函数(转)
Hive是一种构建在Hadoop上的数据仓库,Hive把SQL查询转换为一系列在Hadoop集群中运行的MapReduce作业,是MapReduce更高层次的抽象,不用编写具体的MapReduce方法 ...
- Sqlmap下载安装与基础命令使用
本文介绍一下Sqlmap的安装跟配置环境变量. 顺便附上一些常用的命令 SQLMAP-64位.Python 下载链接:http://pan.baidu.com/s/1c0D82fm 密码:d7ec P ...