記一次流媒體互動直播的項目

項目:主播-。- 要求主播和玩家有互動,並且主播分佈在全國各地 通過發佈視頻流達到直播

目前應用軟件 fms4.5 當做流發佈服務器 目前未採用fms集羣形式,高可用的源和邊緣節點都未建立

待一步步摸索,因目前CDN廠商基本都可進行FMS加速,使用FMS流共享 部署邊緣服務器 並使用智能

DNS分配用戶請求 所以如果不記成本和使用不廣泛的話 個人感覺還是交付給CDN廠商做較好

說下FMS4.5.的建立過程

Flash Media Server 4.5
OSMF Simple Player For Http Dynamic Streaming

下載地址:http://www.osmf.org/downloads/OSFMPlayer_zeri2.zip

Apache2 FMS4.5安裝過程中會安裝一個Apache2 方便web管理,安裝好後可看demo

下面是安裝配置過程:
安裝FMS4.5,默認安裝到/opt/adobe/fms/

tar -zxvf FlashMediaServer4.5_x64.tar.gz

cd FMS_4_5_5_r4013

./installFMS

Do you agree with the license agreement? (y/n): y

Please enter your Adobe Flash Media Server 4.5 serial number. 輸入序列號~~~如果沒有就默認吧 可以從網上找個 默認的話回到開發版

Default [/opt/adobe/fms]:  默認安裝路徑

Please enter the administrative username: 管理員用戶名,搭建完成後可通過web管理
Please enter the administrative password: 管理員密碼
Default user [fms]:  默認啓動用戶
User "fms" does not exist. Do you want to create it?(y/n) 如無fms用戶則創建
Default [y]:  默認Y
Please enter a valid user group for the "fms" user. 創建組
Default group [fms]:

Do you want to install apache? (y/n) fms安裝會內嵌安裝apache 可選是否安裝
Default [y]:
You have chosen to install Apache.
Would you like for Apache or FMS to listen on port 80?
Enter 'y' for Apache, 'n' for FMS. (y/n)
Default [y]:
Please enter the Adobe Flash Media Server port(s), comma-separated
Default [1935,80]: FMS 監聽端口 1935 80
Please enter the port to use for the Admin service. You can only specify one
admin port.
Default [1111]:     FMSadmin 管理端口 默認1111
Do you want the Adobe Flash Media Server service to run as a
daemon? (y/n)  後臺運行 之後還會讓你選擇是否安裝完後自動啓動
Default [y]:    
Proceed with the installation? (y/n/q):  確認信息

下載安裝OSMF Simple Player,將下載到的Player解壓並放到: /opt/adobe/fms/webroot/OSFMPlayer 目錄中
默認情況向, FMS監聽80端口接收traffic然後傳遞給Apache的8134端口(FMS自帶的Apache被配成了監聽8134端口),這個傳遞過程在高網絡負載下會帶來性能的問題,因此,做以下配置來解決這個問題。
修改fms.ini, 將其中的ADAPTOR.HOSTPORT = :1935,80 一行改爲ADAPTOR.HOSTPORT = :1935; 不讓FMS監聽80端口;
同時,將其中 HTTPPROXY.HOST = :8134一行改爲:  HTTPPROXY.HOST =
這樣便去掉了以上的代理轉發過程。
rootinstall/Apache2.2/conf/httpd.conf文件中的 Listen 8134 一行不用更改,這樣便讓FMS 安裝的Apache繼續監聽8134端口,而我們系統中的Apache仍監聽80端口,這樣便不會衝突。(當然這樣帶來的壞處就是後面任何HTTP訪問都需要帶8134

HTTP Origin Module 不用配置,FMS4.5自帶安裝的Apache都已經配置好了這些支持Http Dynamic Streaming的模塊 主要用於點播 和直播時下發流媒體數據到觀看端;

客戶端錄製測試

Flash Media Live Encoder 3.2
打開其子目錄Conf下面的config.xml文件
修改/flashmedialiveencoder_config/mbrconfig/streamsynchronization/enable節點值爲true.
   (使用絕對時間)
     <mbrconfig>
        <streamsynchronization>
             <enable>true</enable>

配置FMS server在直播時使用絕對時間,打開rootinstall/applications/livepkgr/Application.xml
    修改/Application/StreamManager/Live/AssumeAbsoluteTime節點爲true.
    <Application>
       <StreamManager>
         <Live>
           <AssumeAbsoluteTime>true</AssumeAbsoluteTime>
         </Live>
       </StreamManager>
    </Application>

配置rootinstall/conf/Server.xml,修改
   <Root>
     <Server>
       <ResourceLimits>
          <RecBuffer>
             <MaxFlushTime> 3 <MaxFlushTime>
    將<MaxFlushTime>的值改爲1.

驗證直播和點播
  cd rootinstall
  ./fmsmgr server fms restart  -- 重新啓動FMS
  ./fmsmgr adminserver restart -- 重新啓動Admin Server

證VOD 是按Dynmaic Http Streaming   http://yourserverip:8134/
進入可看到默認主頁

“Launch Flash Media Administration Console”,可以通過此入口來管理FMS server(用安裝時創建的用戶名和密碼)
“(HDS) HTTP Dynamic Streaming sample” 點擊進去,可以看到視頻播放界面 可測試視頻播放是否分段 即驗證HTTP Dynamic Streaming VOD方式是成功的。


啓動上面安裝的Flash Media Live Encoder 3.2,選preset Custom, 視頻選H264,29.9fps,分辨率352x288
碼率可選3個100, 200, 350,H264可設置每2秒一個關鍵幀等,選MP3做音頻等。
在右邊的Stream to Flash Media Server的FMS URL 裏面填上:rtmp://yourserverip/livepkgr
在Stream一欄填上:livestream%i?adbe-live-event=liveevent (如果上面選了MBR3個碼率直播),如果選了一個碼率直播則填上:livestream?adbe-live-event=liveevent  stream項寫頻道名
然後點開始即可發佈直播
http://yourserverip:8134/OSFMPlayer/OSMFPlayer.html
然後用OSMFPlayer播放以下地址即可看到直播圖像:

*.f4m -- Flash Media Manifest file. Contains information about codec, resolution, and the availability of
multi-bitrate files.類似於蘋果HLS方案中的m3u8,是mainfest索引文件,裏面包括編碼,分辨率碼率等
*.f4x -- Index file. Contains the location of specific fragments within a stream.
*.f4f -- A segment. The tool outputs one or more F4F files. Each file contains a segment of the sourcefile. Each segment contains one or more fragments of content. A player can use a URL to address eachfragment.


將rootinstall/samples目錄下的videoPlayer目錄拷貝到rootinstall/webroot/下,這是一個支持RTMP協議播放的Flash播放器,類似於上面的OSMF播放器。
在Flash Media Live Encoder3.2那裏的FMS URL那裏填上: rtmp://yourserviceip/live
在下面的stream那裏填上livestream
觀看端用瀏覽器打開:http://yourserverip:8134/videoPlayer/videoPlayer.html, 然後在頁面下部的stream URL那裏輸入:
rtmp://yourserverip/live/livestream,並勾選中LIVE,然後點擊Play Stream即可觀看。
這裏觀看者用的是RTMP下載方式而不是HTTP下載方式。

關於FMS分流

另找一臺fms服務器

在main.asc中寫入

  1. //程序啓動時執行

  2. application.onAppStart = function() {

  3. this.myNC= new NetConnection();  

  4. this.myNC.onStatus = NC_onStatus;

  5. this.myNC.connect("rtmp://cuplayer.com/tvSet");

  6. };

  7. function NC_onStatus(info){    

  8.     switch (info.code) {

  9.   case "NetConnection.Connect.Success" :

  10. application.myStream = Stream.get("cctv1");

  11. application.myStream.onStatus = NS_onStatus;

  12.    if (application.myStream){

  13.     application.myStream.play("cctv1",-2, -1,false,application.myNC);

  14.    }

  15.      trace("CuPlayer.com提示:連接成功!");    

  16.    break;

  17.   case "NetConnection.Connect.Failed" :

  18.    trace("CuPlayer.com提示:連接失敗!");

  19.    break;

  20.   case "NetConnection.Connect.Rejected" :

  21.    trace("CuPlayer.com提示:連接失敗!");

  22.    break;

  23. }

  24. }

  25. function NS_onStatus(info){  

  26.   trace(info.code);    

  27. }

注:cctv1爲流名稱


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章