開宗明義,在headless(i.e.withoutamonitororinputdevice)的伺服器(例如,各類嵌入式「玩具板子」)上如果架起vlc進行多媒體播放,怎樣才是最方便的控制方式?
同時,因為希望是可以指令碼控制,所以最好是可以做到非互動式的指令。
如下是簡單的步驟:
使能vlc的remotecontrol介面
vlc實際上擁有靈活強大的控制方式,由於我們上來就限定了headless,那麼命令列顯然是先決條件,vlc文件中已經列出了支援的幾種remote方式:
rcinterface
ncursesinterface
telnetinterface
考慮到三者中rc應該是最強大和靈活的(ncurses需要configure,telnet更多的是互動型,何況rc本身就可以支援telnet訪問),我們就focus在rc介面上。
使能方法非常簡單,呼叫vlc的時候,用:
cvlc-irc--rc-fake-tty--rc-host
選項
意義
"-irc"啟動rc介面;
"--rc-fake-tty"強迫將標準輸入當做tty
"--rc-host"選定的監聽地址和埠
注意:如果需要區域網內訪問,請填寫本機ip,如果只要本機訪問,用localhost就可以了
得到如下資訊(忽略那些錯誤吧,畢竟headless麼,很多介面對vlc來說都缺失,但是不影響使用)
cvlc-irc--rc-fake-tty--rc-hostlocalhost:8888
vlcmediaplayer2.0.3twoflower(revision2.0.2-93-g77aa89e)
[0x11eed70]inhibitinterfaceerror:failedtoconnecttothed-bussessiondaemon:unabletoautolaunchadbus-daemonwithouta$displayforx11
[0x11eed70]maininterfaceerror:nosuitableinterfacemodule
[0x10858f0]mainlibvlcerror:interface"globalhotkeys,none"initializationfailed
[0x11eed70][cli]luainterface:listeningonhost"localhost:8888".
rc介面指令
直接藉助幫助檔案,可見還是非常強大的:
+----[clicommands]
|addxyz....................addxyztoplaylist
|enqueuexyz.................queuexyztoplaylist
|playlist.............showitemscurrentlyinplaylist
|search[string]..searchforitemsinplaylist(orresetsearch)
|sortkey.....................sorttheplaylist
|sd[sd].............showservicesdiscoveryortoggle
|play..........................playstream
|stop..........................stopstream
|next......................nextplaylistitem
|prev....................previousplaylistitem
|goto,gotoitem.................gotoitematindex
|repeat[on|off]..............toggleplaylistrepeat
|loop[on|off]................toggleplaylistloop
|random[on|off]..............toggleplaylistrandom
|clear.....................cleartheplaylist
|status...................currentplayliststatus
|title[x]..............set/gettitleincurrentitem
|title_n................nexttitleincurrentitem
|title_p..............previoustitleincurrentitem
|chapter[x]............set/getchapterincurrentitem
|chapter_n..............nextchapterincurrentitem
|chapter_p............previouschapterincurrentitem
|
|seekx...........seekinseconds,forinstance`seek12"
|pause........................togglepause
|fastforward..................settomaximumrate
|rewind.....................settominimumrate
|faster..................fasterplayingofstream
|slower..................slowerplayingofstream
|normal..................normalplayingofstream
|rate[playbackrate]..........setplaybackratetovalue
|frame.....................playframebyframe
|fullscreen,f,f[on|off]............togglefullscreen
|info.............informationaboutthecurrentstream
|stats................showstatisticalinformation
|get_time.........secondselapsedsincestream"sbeginning
|is_playing............1ifastreamplays,0otherwise
|get_title.............thetitleofthecurrentstream
|get_length............thelengthofthecurrentstream
|volume[x]..................set/getaudiovolume
|volup[x]...............raiseaudiovolumexsteps
|voldown[x]..............loweraudiovolumexsteps
|adev[x]...................set/getaudiodevice
|achan[x].................set/getaudiochannels
|atrack[x]...................set/getaudiotrack
|vtrack[x]...................set/getvideotrack
|vratio[x]...............set/getvideoaspectratio
|vcrop,crop[x]................set/getvideocrop
|vzoom,zoom[x]................set/getvideozoom
|vdeinterlace[x].............set/getvideodeintelace
|vdeinterlace_mode[x]........set/getvideodeintelacemode
|snapshot....................takevideosnapshot
|strack[x].................set/getsubtitlestrack
|vlm.........................loadthevlm
|description.................describethismodule
|help,?[pattern].................ahelpmessage
|longhelp[pattern]..............alongerhelpmessage
|lock....................lockthetelnetprompt
|logout..............exit(ifinasocketconnection)
|quit........quitvlc(orlogoutifinasocketconnection)
|shutdown.......................shutdownvlc
+----[endofhelp]
如何訪問:
這樣可以用類似於形如下面指令的方法來模擬socket訪問(作者以osx為例,應當是沒有問題的):
echonormal|nc-u/users/vlc.sock
我的例子,debian中,nc似乎是不適用,更多人推薦用socat(需要安裝)
echo“pause”|socat–unix-connect:/users/vlc.sock
上面可以理解成將管道化之後的echo字元向這個unix的socket傳送。可是在我這裡死活都會遇到檔案connectionrefused,作為菜鳥,實在無力解決,特別是看到有強者遇到類似問題交叉比較得出可能和特定版本的kernelstock存在bug有關之後,不管看不看得懂,我都理直氣壯的放棄了——直接轉向了上面提到的host:port的方案。
所以:
osx
如果是互動式,直接nc
$nc192.168.199.1058888
vlcmediaplayer2.0.3twoflower
commandlineinterfaceinitialized.type`help"forhelp.
$status
(newinput:file:///home/user/test.mp3)
(audiovolume:256)
(stateplaying)
$info
+----[stream0]
|bitrate:160kb/s
|type:audio
|channels:stereo
|samplerate:44100hz
|codec:mpegaudiolayer1/2/3(mpga)
+----[endofstreaminfo]
如果不需要互動:
參考上節:
echostatus|nc-w0
-w是指示說該命令之後,立刻退出,實際上osx下並不一定需要,只是為了和下面linux對照一下。
linux
大致相同,區別只是在非互動式下,
echostatus|nc-q0
兩者區別只是一個用了"wait"之意,另外一個是"quit"罷了,想想還挺風趣....風趣個妹啊,這不是折騰跨平臺使用者嗎?!
結論
至此,該問題解決,不論是想在遠端控制無輸入(顯示)裝置上的播放,還是想用指令碼對其他執行緒的vlc播放進行自動化的干預控制,都不成問題了。
開宗明義,在headless(i.e.withoutamonitororinputdevice)的伺服器(例如,各類嵌入式「玩具板子」)上如果架起vlc進行多媒體播放,怎樣才是最方便的控制方式?
同時,因為希望是可以指令碼控制,所以最好是可以做到非互動式的指令。
如下是簡單的步驟:
使能vlc的remotecontrol介面
vlc實際上擁有靈活強大的控制方式,由於我們上來就限定了headless,那麼命令列顯然是先決條件,vlc文件中已經列出了支援的幾種remote方式:
rcinterface
ncursesinterface
telnetinterface
考慮到三者中rc應該是最強大和靈活的(ncurses需要configure,telnet更多的是互動型,何況rc本身就可以支援telnet訪問),我們就focus在rc介面上。
使能方法非常簡單,呼叫vlc的時候,用:
cvlc-irc--rc-fake-tty--rc-host
選項
意義
"-irc"啟動rc介面;
"--rc-fake-tty"強迫將標準輸入當做tty
"--rc-host"選定的監聽地址和埠
注意:如果需要區域網內訪問,請填寫本機ip,如果只要本機訪問,用localhost就可以了
得到如下資訊(忽略那些錯誤吧,畢竟headless麼,很多介面對vlc來說都缺失,但是不影響使用)
cvlc-irc--rc-fake-tty--rc-hostlocalhost:8888
vlcmediaplayer2.0.3twoflower(revision2.0.2-93-g77aa89e)
[0x11eed70]inhibitinterfaceerror:failedtoconnecttothed-bussessiondaemon:unabletoautolaunchadbus-daemonwithouta$displayforx11
[0x11eed70]maininterfaceerror:nosuitableinterfacemodule
[0x11eed70]maininterfaceerror:nosuitableinterfacemodule
[0x10858f0]mainlibvlcerror:interface"globalhotkeys,none"initializationfailed
[0x11eed70][cli]luainterface:listeningonhost"localhost:8888".
rc介面指令
直接藉助幫助檔案,可見還是非常強大的:
+----[clicommands]
|addxyz....................addxyztoplaylist
|enqueuexyz.................queuexyztoplaylist
|playlist.............showitemscurrentlyinplaylist
|search[string]..searchforitemsinplaylist(orresetsearch)
|sortkey.....................sorttheplaylist
|sd[sd].............showservicesdiscoveryortoggle
|play..........................playstream
|stop..........................stopstream
|next......................nextplaylistitem
|prev....................previousplaylistitem
|goto,gotoitem.................gotoitematindex
|repeat[on|off]..............toggleplaylistrepeat
|loop[on|off]................toggleplaylistloop
|random[on|off]..............toggleplaylistrandom
|clear.....................cleartheplaylist
|status...................currentplayliststatus
|title[x]..............set/gettitleincurrentitem
|title_n................nexttitleincurrentitem
|title_p..............previoustitleincurrentitem
|chapter[x]............set/getchapterincurrentitem
|chapter_n..............nextchapterincurrentitem
|chapter_p............previouschapterincurrentitem
|
|seekx...........seekinseconds,forinstance`seek12"
|pause........................togglepause
|fastforward..................settomaximumrate
|rewind.....................settominimumrate
|faster..................fasterplayingofstream
|slower..................slowerplayingofstream
|normal..................normalplayingofstream
|rate[playbackrate]..........setplaybackratetovalue
|frame.....................playframebyframe
|fullscreen,f,f[on|off]............togglefullscreen
|info.............informationaboutthecurrentstream
|stats................showstatisticalinformation
|get_time.........secondselapsedsincestream"sbeginning
|is_playing............1ifastreamplays,0otherwise
|get_title.............thetitleofthecurrentstream
|get_length............thelengthofthecurrentstream
|
|volume[x]..................set/getaudiovolume
|volup[x]...............raiseaudiovolumexsteps
|voldown[x]..............loweraudiovolumexsteps
|adev[x]...................set/getaudiodevice
|achan[x].................set/getaudiochannels
|atrack[x]...................set/getaudiotrack
|vtrack[x]...................set/getvideotrack
|vratio[x]...............set/getvideoaspectratio
|vcrop,crop[x]................set/getvideocrop
|vzoom,zoom[x]................set/getvideozoom
|vdeinterlace[x].............set/getvideodeintelace
|vdeinterlace_mode[x]........set/getvideodeintelacemode
|snapshot....................takevideosnapshot
|strack[x].................set/getsubtitlestrack
|
|vlm.........................loadthevlm
|description.................describethismodule
|help,?[pattern].................ahelpmessage
|longhelp[pattern]..............alongerhelpmessage
|lock....................lockthetelnetprompt
|logout..............exit(ifinasocketconnection)
|quit........quitvlc(orlogoutifinasocketconnection)
|shutdown.......................shutdownvlc
+----[endofhelp]
如何訪問:
這樣可以用類似於形如下面指令的方法來模擬socket訪問(作者以osx為例,應當是沒有問題的):
echonormal|nc-u/users/vlc.sock
我的例子,debian中,nc似乎是不適用,更多人推薦用socat(需要安裝)
echo“pause”|socat–unix-connect:/users/vlc.sock
上面可以理解成將管道化之後的echo字元向這個unix的socket傳送。可是在我這裡死活都會遇到檔案connectionrefused,作為菜鳥,實在無力解決,特別是看到有強者遇到類似問題交叉比較得出可能和特定版本的kernelstock存在bug有關之後,不管看不看得懂,我都理直氣壯的放棄了——直接轉向了上面提到的host:port的方案。
所以:
osx
如果是互動式,直接nc
$nc192.168.199.1058888
vlcmediaplayer2.0.3twoflower
commandlineinterfaceinitialized.type`help"forhelp.
$status
(newinput:file:///home/user/test.mp3)
(audiovolume:256)
(stateplaying)
$info
+----[stream0]
|
|bitrate:160kb/s
|type:audio
|channels:stereo
|samplerate:44100hz
|codec:mpegaudiolayer1/2/3(mpga)
|
+----[endofstreaminfo]
如果不需要互動:
參考上節:
echostatus|nc-w0
-w是指示說該命令之後,立刻退出,實際上osx下並不一定需要,只是為了和下面linux對照一下。
linux
大致相同,區別只是在非互動式下,
echostatus|nc-q0
兩者區別只是一個用了"wait"之意,另外一個是"quit"罷了,想想還挺風趣....風趣個妹啊,這不是折騰跨平臺使用者嗎?!
結論
至此,該問題解決,不論是想在遠端控制無輸入(顯示)裝置上的播放,還是想用指令碼對其他執行緒的vlc播放進行自動化的干預控制,都不成問題了。