天天看點

nginx+ffmpeg搭建rtmp轉播rtsp流的flash伺服器 nginx+ffmpeg搭建rtmp轉播rtsp流的flash伺服器 原文連結:http://blog.csdn.net/gubenpeiyuan/article/details/38089013本文概要:

nginx+ffmpeg搭建rtmp轉播rtsp流的flash伺服器

<div class="article_manage clearfix">
    <div class="article_l">
        <span class="link_categories">
        标簽:
          <a href="http://www.csdn.net/tag/nginx" target="_blank" rel="external nofollow"  target="_blank" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_tag']);">nginx</a>
        </span>
    </div>
    <div class="article_r">
        <span class="link_postdate">2016-01-23 11:04</span>
        <span class="link_view" title="閱讀次數">1272人閱讀</span>
        <span class="link_comments" title="評論次數"> <a href="#comments" target="_blank" rel="external nofollow"  onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_pinglun'])">評論</a>(0)</span>
        <span class="link_collect tracking-ad" data-mod="popu_171"> <a href="javascript:void(0);" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  onclick="javascript:collectArticle('nginx%2bffmpeg%e6%90%ad%e5%bb%bartmp%e8%bd%ac%e6%92%adrtsp%e6%b5%81%e7%9a%84flash%e6%9c%8d%e5%8a%a1%e5%99%a8','50568999');return false;" title="收藏" target="_blank">收藏</a></span>
         <span class="link_report"> <a href="#report" target="_blank" rel="external nofollow"  onclick="javascript:report(50568999,2);return false;" title="舉報">舉報</a></span>

    </div>
</div>    <style type="text/css">        
        .embody{
            padding:10px 10px 10px;
            margin:0 -20px;
            border-bottom:solid 1px #ededed;                
        }
        .embody_b{
            margin:0 ;
            padding:10px 0;
        }
        .embody .embody_t,.embody .embody_c{
            display: inline-block;
            margin-right:10px;
        }
        .embody_t{
            font-size: 12px;
            color:#999;
        }
        .embody_c{
            font-size: 12px;
        }
        .embody_c img,.embody_c em{
            display: inline-block;
            vertical-align: middle;               
        }
         .embody_c img{               
            width:30px;
            height:30px;
        }
        .embody_c em{
            margin: 0 20px 0 10px;
            color:#333;
            font-style: normal;
        }
</style>
<script type="text/javascript">
    $(function () {
        try
        {
            var lib = eval("("+$("#lib").attr("value")+")");
            var html = "";
            if (lib.err == 0) {
                $.each(lib.data, function (i) {
                    var obj = lib.data[i];
                    //html += '<img src="' + obj.logo + '"/>' + obj.name + "&nbsp;&nbsp;";
                    html += ' <a href="' + obj.url + '" target="_blank" rel="external nofollow"  target="_blank">';
                    html += ' <img src="' + obj.logo + '">';
                    html += ' <em><b>' + obj.name + '</b></em>';
                    html += ' </a>';
                });
                if (html != "") {
                    setTimeout(function () {
                        $("#lib").html(html);                      
                        $("#embody").show();
                    }, 100);
                }
            }      
        } catch (err)
        { }

    });
</script>
  <div class="category clearfix">
    <div class="category_l">
       <img src="http://static.blog.csdn.net/images/category_icon.jpg">
        <span>分類:</span>
    </div>
    <div class="category_r">
                <label onclick="GetCategoryArticles('6079159','zhangxiao93','top','50568999');">
                    <span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_fenlei']);">Nginx<em>(18)</em></span>
                  <img class="arrow-down" src="http://static.blog.csdn.net/images/arrow_triangle _down.jpg" style="display:inline;">
                  <img class="arrow-up" src="http://static.blog.csdn.net/images/arrow_triangle_up.jpg" style="display:none;">
                    <div class="subItem">
                        <div class="subItem_t"><a href="http://blog.csdn.net/zhangxiao93/article/category/6079159" target="_blank" rel="external nofollow"  target="_blank">作者同類文章</a><i class="J_close">X</i></div>
                        <ul class="subItem_l" id="top_6079159">                            
                        </ul>
                    </div>
                </label>                    
    </div>
</div>
           

目錄(?)[+]

  1. 原文連結httpblogcsdnnetgubenpeiyuanarticledetails38089013
  2. 本文概要

原文連結:http://blog.csdn.net/gubenpeiyuan/article/details/38089013

本文概要:

        nginx是非常優秀的開源伺服器,用它來做hls或者rtmp流媒體伺服器是非常不錯的選擇。本文介紹了一種簡易方法快速搭建rtmp流媒體伺服器,也叫rtsp轉播,資料源不是讀取檔案,而是采用擷取rtspNal流後使用ffmpeg轉播。csdn固本培元:[email protected]

開發環境:centos6.4 (主流的linux伺服器選擇,30%以上的市場占有率)

需要這幾個包。

版本号:nginx 1.7.3  openssl 1.0.2   rtmp-module(版本未知)

資源:這些都是公網下載下傳的資源,有需要的朋友,可以給我email或者評論留言。email:[email protected]

注意:先編譯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測試如下:

nginx+ffmpeg搭建rtmp轉播rtsp流的flash伺服器 nginx+ffmpeg搭建rtmp轉播rtsp流的flash伺服器 原文連結:http://blog.csdn.net/gubenpeiyuan/article/details/38089013本文概要:

此後可以将實時流推送到rmp了。

我的方案是live555接收流,串流方式推送至fifo,做rtmp的轉發。可能有些延遲,哪位朋友有更好的方案,歡迎交流評論。

其架構如下:非常簡單,并容易內建入大流媒體架構。

nginx+ffmpeg搭建rtmp轉播rtsp流的flash伺服器 nginx+ffmpeg搭建rtmp轉播rtsp流的flash伺服器 原文連結:http://blog.csdn.net/gubenpeiyuan/article/details/38089013本文概要:

Flex方案截圖:

nginx+ffmpeg搭建rtmp轉播rtsp流的flash伺服器 nginx+ffmpeg搭建rtmp轉播rtsp流的flash伺服器 原文連結:http://blog.csdn.net/gubenpeiyuan/article/details/38089013本文概要:

附錄:

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&nbsp;-&nbsp;remote_user [time_local]&nbsp;"request” ’  
  36.     #                  ’status&nbsp;body_bytes_sent ”$http_referer” ’  
  37.     #                  ’”http_user_agent"&nbsp;"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+ffmpeg搭建rtmp轉播rtsp流的flash伺服器 nginx+ffmpeg搭建rtmp轉播rtsp流的flash伺服器 原文連結:http://blog.csdn.net/gubenpeiyuan/article/details/38089013本文概要:

參考文章:

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

document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000)

<div id="digg" articleid="50568999">
        <dl id="btnDigg" class="digg digg_enable" onclick="btndigga();">

             <dt>頂</dt>
            <dd>0</dd>
        </dl>


        <dl id="btnBury" class="digg digg_enable" onclick="btnburya();">

              <dt>踩</dt>
            <dd>0</dd>               
        </dl>

    </div>
 <div class="tracking-ad" data-mod="popu_222"><a href="javascript:void(0);" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  target="_blank">&nbsp;</a>   </div>
<div class="tracking-ad" data-mod="popu_223"> <a href="javascript:void(0);" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  target="_blank">&nbsp;</a></div>
<script type="text/javascript">
    function btndigga() {
        $(".tracking-ad[data-mod='popu_222'] a").click();
    }
    function btnburya() {
        $(".tracking-ad[data-mod='popu_223'] a").click();
    }
        </script>
           

繼續閱讀