流媒體平臺搭建

1       目標

希望建設一個流媒體平臺(類似音樂平臺),通過流媒體平臺維護相關流媒體資源。

2       主要功能要求

         主要功能可以包括:流媒體內容維護(信息維護、流媒體文件上傳等)、支持RTSP(Real-Time Streaming Protocol,實時流媒體協議)和RTP/RTCP(Real-Time TranCPort Protocol/RTP Control Protocol,實時傳輸協議/RTP控制協議)進行流媒體播放。DSS給出的性能參數爲:默認1000用戶同時在線,可以修改爲最高9999,前提是帶寬足夠大。

3       設計實現方案

         由於部門沒有類似的項目建設案例,項目組人員不能掌握流媒體技術。要想在工期內完成項目的建設工作。通過互聯網搜索。找到一款開源流媒體平臺項目Darwin Streaming Server。通過對DSS相關功能的二次開發,利用其串流播放能力。根據DSS項目給出的性能指標滿足需求文檔中的要求(未通過LR驗證)。

3.1     DSS開源產品介紹

         Darwin Streaming Server簡稱DSS。DSS是Apple公司提供的開源實時流媒體播放服務器程序。整個程序使用C++編寫,在設計上遵循高性能,簡單,模塊化等程序設計原則,務求做到程序高效,可擴充性好。並且DSS是一個開放源代碼的,基於標準的流媒體服務器,可以運行在Windows NT和Windows 2000,以及幾個UNIX實現上,包括Mac OS X,Linux,FreeBSD,和Solaris操作系統上的。Darwin Streaming Server,提供音樂 (mp3) 與影音 (3gp、mp4、mov) 串流播放功能。

         較爲詳細的功能介紹參見:

    http://hi.baidu.com/dmkj2008/item/a2085a30e0738e80c3cf2956

         轉發功能:如果服務器壓力較大或功能擴展,可以使用DSS Relay功能,視壓力測試結果而定。

         參考資源:

http://www.jsjyedu.cn/zxlw/48254_2.html

http://www.jtben.com/document/1120414

3.2     DSS搭建

2.1  安裝命令

tar zxf DarwinStreamingSrvr5.5.5-Linux.tar.gz

cd DarwinStreamingSrvrlinux-Linux

./Install

Please enter a new administrator user name: admin

Please enter a new administrator Password: your_password

2.2  查看是否安裝成功

id qtss

uid=501(qtss)  gid=502(qtss)  groups=502(qtss)

ps aux | grep Darwin

root ... ... ... /usr/local/sbin/DarwinStreamingServer

qtss ... ... ... /usr/local/sbin/DarwinStreamingServer

netstat -ntulp | grep Darwin

tcp 0.0.0.0:8001

tcp 0.0.0.0:554

tcp 0.0.0.0:7070

udp 127.0.0.1:6970

udp 192.168.0.1:6970

udp 127.0.0.1:6971

udp 192.168.0.1:6971

udp 127.0.0.1:6976

udp 127.0.0.1:6977

udp 127.0.0.1:6978

udp 127.0.0.1:6979

2.3  啓動命令

啓動服務(安裝已經啓動,不需要再啓動)

啓動 Darwin Streaming Server

/usr/local/sbin/DarwinStreamingServer

啓動 Web 管理接口 (tcp port 1220) (安裝已經啓動,不需要再啓動)

/usr/local/sbin/streamingadminserver.pl

2.4  關閉命令

Kill -9 Darwin Streaming Server進程

2.5 error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

 

建議:在/etc/ld.so.conf.d/上新建動態庫相應的文件配置文件*.conf, 

在該文件中填上該動態庫的絕對路徑 

此例: 

vim /etc/ld.so.conf.d/ld.Darwin.so.conf 

/usr/local/lib

同時copy libstdc++.so.6 到/usr/local/lib

 

運行:ldconfig /etc/ld.so.cache

3          管理界面配置3.1  連入管理接口進行設定

開啓瀏覽器, 連入 http://darwin.streaming.server:1220/

第一次進入管理接口, 需進行以下設置:

MP3 Broadcast Password: 設定 MP3 廣播密碼

Secure Administration: Web 管理接口是否啓用 SSL 安全聯機 (視需求,本次設置爲否)

Media Folder: 設定多媒體文件存放路徑 (默認 /usr/local/movies,本次設置爲默認,如若修改路徑不會對目標目錄產生影響)

Streaming on Port 80: 是否以 80 port 傳送串流數據 (視需求,本次設置爲否)

 

以上,DSS搭建完成。

3.3     音頻編碼

3.3.1  軟件安裝

3.3.1.1 Acc聲音編碼

tar xvfz faac-1.28.tar.gz

cd faac-1.28

./configure --prefix=/usr/local --enable-shared  --without-mp4v2

Make

FAQ:

make 時報錯

if g++ -DHAVE_CONFIG_H -I. -I. -I../.. -I../../include   -Wall -g -O2 -MT 3gp.o -MD -MP -MF ".deps/3gp.Tpo" -c -o 3gp.o 3gp.cpp; \

 then mv -f ".deps/3gp.Tpo" ".deps/3gp.Po"; else rm -f ".deps/3gp.Tpo"; exit 1; fi

mpeg4ip.h:126: error: new declaration ?.onst char* strcasestr(const char*, const char*)?

vim +126 common/mp4v2/mpeg4ip.h

將此行刪除,保存退出

char *strcasestr(const char *haystack, const char *needle); 

make clean

 

 

make install

 

3.3.1.2 amr_nb聲音編碼

tar xvf amrnb-7.0.0.2.tar.bz2

cd amrnb-7.0.0.2

./configure --prefix=/usr/local --enable-shared

make

make install

由於網絡問題安裝不上,請跳過此步驟。

3.3.1.3 ffmpeg

    1、tar xvfj ffmpeg-0.4.9-p20051120.tar.bz2

  得到解壓後的目錄是ffmpeg-0.4.9-p20051120,名字太長,利用mv命令改爲ffmpeg

mv ffmpeg-0.4.9-p20051120 ffmpeg

cd ffmpeg/libavcodec

mkdir amr_float   同時將解壓26104-700.zip的葉子文件cp到 amr_float中

執行:

     declare -x    LD_LIBRARY_PATH="/usr/local/lib:/u01/software/stream/faac-1.28:/u01/software/stream/amr  nb-7.0.0.2"    

 

  2、配置

./configure --prefix=/usr/local/ffmpeg --enable-shared --enable-faac --enable-amr_nb --disable-ffplay

  其中:--enable-shared 是允許其編譯產生動態庫,在以後的編程中要用到這個幾個動態庫。--prefix設置的安裝目錄。

 

  3、編譯並安裝

  make

  make install

  4、安裝之後在/usr/local/ffmpeg會看到有三個目錄

  lib 動態鏈接庫位置

  include 編程要用到頭文件

  bin 執行文件所在的目錄

  5、爲了以後方便編程,我們把lib中的三個鏈接庫libavcodec.so libavformat.so libavutil.so複製到/usr/lib下。把include目錄下的ffmpeg目錄複製到/usr/include下。

    6、ln -s  /usr/local/ffmpeg/bin/ffmpeg /usr/bin/ffmpeg

    7、 vi /etc/ld.so.conf  添加/usr/local/lib

        保存後,執行 ldconfig

3.3.1.4 安裝音頻流化軟件

音頻流化作用如下:

Hint tracks are a series of instructions in a mp4 container file that
tell a server how to transmit packets. Hint tracks always refer
to another track, most likely an audio or video media track.  

This series of instructions tells the server when to send the packet, 
what type of RTP header to add, if there is any extra data in the
packet, and how much data to send in the packet.  To save on space, 
a hint can contain a pointer to the media track, instead of duplicating
that data.

安裝流程:

 

tar  xvfz mpeg4ip-1.6.1.tar.gz

cd mpeg4ip-1.6.1

 

./bootstrap --prefix=/usr/local/mpeg4ip --enable-ffmpeg=/usr/local/ffmpeg --disable-player --disable-server

如果報錯如下:util/testnasm.sh: line 8: test: =: unary operator expected

Please:

Check for the following text in the "configure" file:

BILLSNASM_arg=`nasm -r | tr '.' ' '`

and replace the -r with -v

Save and run bootstrap again.

make

 

報錯如:t char* strcasestr(const char*, const char*

操作:

vim +126  include /mpeg4ip.h

 

make install

添加默認命令

[root@localhost ~]# cd /usr/bin/

[root@localhost bin]# ln -s /usr/local/mp

 [root@localhost bin]# ln -s /usr/local/mpeg4ip/bin/mp4info /usr/bin//mp4info

 

 

tar zxvf gpac-0.5.0.tar.gz

tar zxvf gpac_extra_libs-0.4.5.tar.gz

cd gpac

cp -r ../gpac_extra_libs/* extra_lib/

chmod +x configure

./configure

make

make lib

make apps

make install

whereis MP4Box

添加默認命令

[root@localhost bin]# cd /usr/bin

[root@localhost bin]# ln -s /usr/local/bin/MP4Box MP4Box

[root@localhost bin]# ll M*

Mail    MP4Box 

[root@localhost bin]# ll MP4Box

lrwxrwxrwx. 1 root root 26  3月 27 17:04 MP4Box -> /usr/local/gpac/bin/MP4Box

[root@localhost bin]# cd /home/tapapp/DarwinStreamingSrvrlinux-Linux/

[root@localhost DarwinStreamingSrvrlinux-Linux]# MP4Box -hint outfile.mp4

Hinting file with Path-MTU 1450 Bytes

Hinting track ID 1 - Type "mp4a:mp4a" (mpeg4-generic) - BW 56 kbps

Saving outfile.mp4: 0.500 secs Interleaving   

[root@localhost DarwinStreamingSrvrlinux-Linux]# mp4info outfile.mp4

./mp4info version 2.0.0

/home/tapapp/DarwinStreamingSrvrlinux-Linux/outfile.mp4:

ReadAtom: "/home/tapapp/DarwinStreamingSrvrlinux-Linux/outfile.mp4": atom type 〆nc is suspect

Track   Type    Info

1       audio   MPEG-4 AAC LC, 88.960 secs, 0 kbps, 8000 Hz

65536   hint    Payload (null) for track 1

ReadAtom: "/home/tapapp/DarwinStreamingSrvrlinux-Linux/outfile.mp4": atom type 〆nc is suspect

 

 

說明:對於一些特殊的文件,先ffmpeg -i xxx.mp4 -vcodec copy -acodec copy xxx_new.mp4然後在執行MP4Box -hint xxx_new.mp4

3.3.2   Mp3格式音頻轉碼

轉成音頻編碼爲aac的mp4格式文件

ffmpeg -i sample.mp3 -acodec aac -ac 2 -ar 8000 -ab 96 -vol 200 outfile.mp4

轉成音頻編碼爲amr_nb的mp4格式文件

ffmpeg -i sample.mp3 -ac 1 -acodec amr_nb -ar 8000 -ab 96 -vol 200 test_amr.mp4

 

具體操作流程:

 wKioL1esGUeDhYjkAAAtyb_1-9M814.png-wh_50

 

3.3.3   VLC生成sdp文件

vlc -vvv sample_100kbit.mp4 --sout '#rtp{dst=10.4.121.194, msx=ts, port=1234, sdp=rtsp://10.4.121.194:554/test.sdp}'

3.4     音頻文件存儲

按照linux文件目錄存儲:

$DSS_HOME/音頻編碼格式(amr,acc)/音頻分類編碼1(文史、搞笑等)/音頻分類二級編碼(詩詞散文、國外名著等)/書籍名稱編碼/產品包(可選)/音頻文件.mp4

樣例:$DSS_HOME /acc/1001/1001001/01/01.mp4

缺點:不支持中文

3.5      RTSP服務控制

         存在問題!

  已經通過socket轉發方式處理

3.6     性能測試

3.6.1  StreamingLoadTool

命令:./ StreamingLoadTool –n203

自帶測試工具,用戶達到203後,測試命令報錯。

PS:-u 命令不好用,必須修改streamingloadtool.conf  的url

 

 

3.6.2  Live555

安裝live555 使用其工具rstpCLIENT 測試性能。

  ./genMakefiles           linux

    make

   make install

調用壓力工具腳本./test2.sh 1000    test2爲無提示成功腳本  較快。可以通過DSS平臺查看

                ./test1.sh 1000   test1 每2秒執行一次,較慢,有提示成功失敗。

3.6.3  LR測試

未測試。

可用的播放地址:

rtsp://10.4.121.56/sample_300kbit.mp4

 

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