本文概要:

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配置如下:

[plain] view plain copy
  1. #user  nobody;
  2. worker_processes  1;
  3. #error_log  logs/error.log;
  4. #error_log  logs/error.log  notice;
  5. #error_log  logs/error.log  info;
  6. #pid        logs/nginx.pid;
  7. events {
  8. worker_connections  1024;
  9. }
  10. rtmp {
  11. server {
  12. listen 1935;
  13. application myapp {
  14. live on;
  15. #record keyframes;
  16. #record_path /tmp;
  17. #record_max_size 128K;
  18. #record_interval 30s;
  19. #record_suffix .this.is.flv;
  20. #on_publish http://localhost:8080/publish;
  21. #on_play http://localhost:8080/play;
  22. #on_record_done http://localhost:8080/record_done;
  23. }
  24. application hls {
  25. live on;
  26. hls on;
  27. hls_path /tmp/app;
  28. hls_fragment 5s;
  29. }
  30. }
  31. }
  32. http {
  33. include       mime.types;
  34. default_type  application/octet-stream;
  35. #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  36. #                  '$status $body_bytes_sent "$http_referer" '
  37. #                  '"$http_user_agent" "$http_x_forwarded_for"';
  38. #access_log  logs/access.log  main;
  39. sendfile        on;
  40. #tcp_nopush     on;
  41. #keepalive_timeout  0;
  42. keepalive_timeout  65;
  43. #gzip  on;
  44. server {
  45. listen       80;
  46. server_name  localhost;
  47. #charset koi8-r;
  48. #access_log  logs/host.access.log  main;
  49. location / {
  50. root   html;
  51. index  index.html index.htm;
  52. }
  53. #error_page  404              /404.html;
  54. # redirect server error pages to the static page /50x.html
  55. #
  56. error_page   500 502 503 504  /50x.html;
  57. location = /50x.html {
  58. root   html;
  59. }
  60. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  61. #
  62. #location ~ \.php$ {
  63. #    proxy_pass   http://127.0.0.1;
  64. #}
  65. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  66. #
  67. #location ~ \.php$ {
  68. #    root           html;
  69. #    fastcgi_pass   127.0.0.1:9000;
  70. #    fastcgi_index  index.php;
  71. #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
  72. #    include        fastcgi_params;
  73. #}
  74. # deny access to .htaccess files, if Apache's document root
  75. # concurs with nginx's one
  76. #
  77. #location ~ /\.ht {
  78. #    deny  all;
  79. #}
  80. }
  81. # another virtual host using mix of IP-, name-, and port-based configuration
  82. #
  83. #server {
  84. #    listen       8000;
  85. #    listen       somename:8080;
  86. #    server_name  somename  alias  another.alias;
  87. #    location / {
  88. #        root   html;
  89. #        index  index.html index.htm;
  90. #    }
  91. #}
  92. # HTTPS server
  93. #
  94. #server {
  95. #    listen       443 ssl;
  96. #    server_name  localhost;
  97. #    ssl_certificate      cert.pem;
  98. #    ssl_certificate_key  cert.key;
  99. #    ssl_session_cache    shared:SSL:1m;
  100. #    ssl_session_timeout  5m;
  101. #    ssl_ciphers  HIGH:!aNULL:!MD5;
  102. #    ssl_prefer_server_ciphers  on;
  103. #    location / {
  104. #        root   html;
  105. #        index  index.html index.htm;
  106. #    }
  107. #}
  108. }

参考文章:

nginx的RTMP协议服务器

http://www.cnblogs.com/aHuner/p/3247068.html

用开源nginx-rtmp-module搭建flash直播环境

http://www.rosoo.net/a/201307/16696.html

nginx上搭建HLS流媒体服务器

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

from:http://blog.csdn.net/gubenpeiyuan/article/details/38089013

nginx+ffmpeg搭建rtmp转播rtsp流的flash服务器相关推荐

  1. rtsp流php播放插件,nginx+ffmpeg搭建rtmp转播rtsp流的flash服务器

    nginx是非常优秀的开源服务器,用它来做hls或者rtmp流媒体服务器是非常不错的选择.本文介绍了一种简易方法快速搭建rtmp流媒体服务器,也 叫rtsp转播,数据源不是读取文件,而是采用获取rts ...

  2. 使用nginx临时搭建rtmp服务器

    使用nginx临时搭建rtmp服务器 文章目录 使用nginx临时搭建rtmp服务器 系统环境 搭建步骤 RTMP服务验证 由于需要研究rtmp协议交互方式及报数据格式,使用nginx临时搭建一个rt ...

  3. Unity下如何实现RTMP或RTSP流播放和录制

    技术背景 在探讨Unity平台RTMP或RTSP直播流数据播放和录制之前,我们先简单回顾下RTSP或RTMP直播流数据在Unity平台的播放流程: 通过Native RTSP或RTSP直播播放SDK回 ...

  4. FFmpeg 推送摄像头 rtsp 流

    FFmpeg 推送摄像头 rtsp 流 Windows 环境下使用 FFmpeg 推送本地 USB 摄像头为 rtsp 流,并使用 vlc 播放. 本文主要使用环境是 Windows 下的 FFmpe ...

  5. rtsp流通过ffmpeg+nginx转成rtmp以及http-flv流

    1.摄像头提供rtsp的视频流,使用VLC转成ogg格式虽然可以通过h5播放,但是延迟太高:最终决定将rtsp流通过ffmpeg+nginx-http-flv转成rtmp以及http-flv流,并通过 ...

  6. Nginx搭建RTMP推拉流服务器

    如题,今天就来实现一个推拉流服务器,模拟下推流后被客户端拉流看到效果. 详细步骤如下 - 安装Nginx - 安装FFmpeg - 安装VLC客户端 安装Nginx 在Mac上有一个很好用的包管理插件 ...

  7. nginx+ffmpeg搭建流媒体服务器

    安装ffmpeg: 下载FFmpeg和libx264的包 ffmpeg-2.4.1.tar.bz2  last_x264.tar.bz2 libx264需要yasm,所以先安装yasm apt-get ...

  8. 使用Nginx+FFMPEG搭建HLS直播转码服务器

    FROM:http://blog.csdn.net/wutong_login/article/details/42292787 目的:使Nginx支持Rtmp协议推流,并支持hls分发功能及FFMPE ...

  9. ffmpeg 本地视频推rtsp流

    一.安装ffmpeg和EasyDarwin ffmpeg网上很多教程 EasyDarwin下载就可以直接用:https://github.com/easydarwin/easydarwin/relea ...

最新文章

  1. Windows 2008 R2中的NAP新功能详解
  2. RecyclerView + SnapHelper实现炫酷ViewPager效果
  3. c语言程序设计0039大作业答案,2019西南大学0039C语言程序设计机考大作业答案.doc...
  4. MySQL高级 - 并发参数调整
  5. Java学习笔记十五
  6. 【C语言进阶深度学习记录】二十五 指针与数组的本质分析二
  7. 机器学习笔记(十一):支持向量机
  8. linux创建定时任务命令,linux设置定时任务的方法步骤
  9. 集群搭建预备操作:在私有云上创建与配置虚拟机
  10. 判断某点在多边形内——方法一
  11. Mac 上管理多个 java 版本
  12. 从直播CDN的原理说起,谈如何解决延时和连麦的老难题?
  13. Linux中用st_mode判断文件类型
  14. ArrayList类源码阅读
  15. HTML5高级之拖拽drag
  16. Golang中文字符串每个汉字的长度
  17. 如何万网域名解析亚马逊服务器,关于aws亚马逊dns域名解析route53的使用
  18. 网络管理与维护(5.2)RMON MIB
  19. android studio seekbar 简单音乐播放器
  20. C#与三菱FX5U PLC以太网通讯

热门文章

  1. ssh连接失败,排错经验
  2. 期望为线性的选择算法
  3. angular dynamic component 笔记
  4. EIGRP区域注入静态路由的三种方法--CCNP学习笔记
  5. 虚拟化系列-Windows server 2012 备份管理
  6. 怎样卸载连接老师的计算机软件,我的电脑里面solidworks无法卸载,,老师能帮我下吗...
  7. 大数据与BI的区别在哪
  8. 如何借助大数据进行社交媒体营销
  9. 大数据在新型智慧城市的作用
  10. mysql 备份的权限_Mysql 数据库备份权限