linux vlc流媒体服务器,vlc media server rtsp 流媒体服务器搭建成功经验分享
vlc 由videolan.org 出品,開源免費的一款本地和網絡播放器,支持個音視頻格式非常多,還可以用來搭建 rtsp 流媒體服務器,非常好用,支持的平臺很多:windows、mac、linux都可以用,可以做點播、多播(組播)、單播服務器。通過命令設定引用文件后就可以通過rtsp協議訪問這些音視頻。我用的centos6.5,搭建 rtsp 流媒體服務器的時候遇到諸多問題,現在記錄下來以方便其它同學少走彎路。
1.安裝vlc
cd /etc/yum.repos.d/
wget http://pkgrepo.linuxtech.net/el6/release/linuxtech.repo //我試了3次才下載下來
yum list *vlc*
yum -y install vlc
我這里需要149個依賴項,共150個安裝包,100多兆,可能需要下載一會,每人可能不同。
2.驗證vlc是否安裝成功
直接敲vlc,會提示
VLC is not supposed to be run as root. Sorry.
If you need to use real-time priorities and/or privileged TCP ports
you can use vlc-wrapper (make sure it is Set-UID root and
cannot be run by non-trusted users first).
不支持root用戶運行,用useradd vlcuser添加了一個名為vlcuser的用戶,然后su vlcuser,再次運行vlc,成功看到版本和其它很多信息。驗證成功。
useradd vlcuser
su vlcuser
vlc
3.防火墻放行幾個后面要用到的端口
iptables -I INPUT -p TCP --dport 4212 -j ACCEPT
iptables -I INPUT -p TCP --dport 5554 -j ACCEPT
iptables -I INPUT -p TCP --dport 1234 -j ACCEPT
其中4212是telnet端口,配置操作vlc搭建的rtsp流媒體服務器,都需要telnet上去之后進行,我這里是為了演示,生產當中大家要主意安全限定規則或者不開該端口使用本地telnet登陸。5554是rtsp協議使用的端口,可以設置和修改,這點相對上篇文章live555 media server rtsp 流媒體服務器搭建成功經驗分享來說要好很多。1234端口是組播端口,也是可以自己隨意設置的。
4.開啟vlc rtsp流媒體服務
vlc --ttl 12 -vvv --color -I telnet --telnet-password videolan --rtsp-host 0.0.0.0 --rtsp-port 5554
看到大量信息,然后中斷了,仔細排查發現如下錯誤提示:
process 91744: D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open “/var/lib/dbus/machine-id”: No such file or directory
See the manual page for dbus-uuidgen to correct this issue.
D-Bus not built with -rdynamic so unable to print a backtrace
Aborted
上網查了之后,執行如下命令,問題解決,再次運行開啟vlc rtsp流媒體服務的命令,服務成功啟動
su root
dbus-uuidgen > /var/lib/dbus/machine-id
su vlc
vlc --ttl 12 -vvv --color -I telnet --telnet-password videolan --rtsp-host 0.0.0.0 --rtsp-port 5554
注意上面的ip地址0.0.0.0要替換成你自己的ip,按理說0.0.0.0代表監聽本地任何ip,這樣你改了ip還是能用,但我實際測試發現點播不了。而且,端口要用–rtsp-port指定,用0.0.0.0:5554的方式會有錯誤提示,實際監聽到554的端口去了,然后554端口被live555mediaserver占用,關掉live555mediaserver才正常。后面telnet上去配置vod服務的時候會在vlc rtsp 流媒體服務器的狀態中看到如下信息:
main vod server error: Ignoring port 5554 (using 554)
main vod server: Specify port 5554 separately with the rtsp-port option instead.
main vod server debug: net: listening to 0.0.0.0 port 554
main vod server error: socket bind error (Permission denied)
main vod server error: cannot create socket(s) for HTTP host
看到這句?[telnet] main interface debug: net: listening to localhost port 4212 說明telnet監聽正常。
當然可能還會看到一些錯誤,但是暫時不影響服務的正常使用,可以忽略:
inhibit interface error: Failed to connect to the D-Bus session daemon: /bin/dbus-launch terminated abnormally without any error message
main interface error: no suitable interface module
main interface error: no suitable interface module
main libvlc error: interface “globalhotkeys,none” initialization failed
還有一些警告,應該也不影響:
stream warning: unknown box type btrt (incompletely loaded)
demux warning: CTTS table
5.進入telnet添加點播項目,先安裝telnet客戶端
yum -y install telnet
telnet 127.0.0.1 4212
輸入前面設定的密碼:videolan,就進入vlc rtsp 流媒體服務器配置的telnet操作界面了。
a 架設點播服務vod
new vod1 vod enabled
setup vod1 input /home/01.avi
解釋: new 新建了一個名字叫vod1的vod點播服務,設置vod1的input 輸入文件為/home/01.avi。你可以通過這種方式添加很多個點播服務。
b 架設組播服務ch1
new ch1 broadcast enabled
setup ch1 input /home/02.avi loop
setup ch1 output #duplicate{dst=rtp{dst=0.0.0.0,mux=ts,port=1234}}
control ch1 play
上面的0.0.0.0換成你自己的組播服務器ip地址。解釋下:new 新建了一個名字叫ch1的broadcast組播。設置ch1的input輸入文件為/home/02.avi,loop可選,表示循環播放。設置ch1的output輸出為#duplicate{dst=rtp{dst=0.0.0.0,mux=ts,port=1234}},表示rtp協議的ts流發送到組播地址為0.0.0.0,端口1234。控制ch1開始播放。
擴充:
1) output后面可以跟sout參數。具體可以參考vlc->媒體->流->流輸出界面的已生成的流輸出字符串。
2) control ch1后面還可以加stop,pause,seek 百分比。表示停止,暫停和跳轉到百分之幾的位置。
c 架設單播服務
前面組播命令中output換成單播的地址就行了。其他的都一樣的。注意不要new重名了。
可能會看到這些警告和錯誤:
demux warning: track[0x2] will be disabled (eof?)
stream_out_rtp vod server error: cannot add this stream (unsupported codec: RV40)
這表明你的視頻格式vlc不支持,比如這個rv40就是rmvb格式的視頻所用的編碼,vlc不支持,這種情況就會出現該視頻通過rtsp播放畫面是黑的,但是有聲音,因為聲音使用的vlc支持的某種格式。同理,如果有畫面,沒有聲音,說明你的視頻使用的視頻編碼格式受到vlc的支持,而音頻編碼格式不受vlc支持。需要你去手動轉碼或者采用別的處理方式。
d 保存以上配置,下次重啟可以直接加載,不需要全部重新輸入一遍,試想你提供了100個點播和組播服務,每次都手動輸入。。。
save /home/vlc.vod.cfg
load /home/vlc.vod.cfg
實際我測試這個沒成功,報錯:save : Unable to save to file
6.測試vlc rtsp流媒體服務器
在另一臺電腦開啟一個vlc,打開rtsp://127.0.0.1:5554/vod1。應該就可以以rtsp協議串流的方式播放/home/01.avi這個文件了。127.0.0.1可以換成自己的ip。
打開rtp://127.0.0.1:1234。應該就可以以直播的方式觀看/home/02.avi了。但是這個我沒有實驗成功。目前還不清楚問題出在哪里。
參考鏈接:
總結
以上是生活随笔為你收集整理的linux vlc流媒体服务器,vlc media server rtsp 流媒体服务器搭建成功经验分享的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《侠客行》——李白
- 下一篇: 惠普打印机故障代码_惠普打印机故障代码