命令行下怎樣遠(yuǎn)程控制VLC播放

開宗明義,在Headless ( i.e. without a monitor or input device)的服務(wù)器(例如,各類嵌入式「玩具板子」)上如果架起VLC進(jìn)行多媒體播放,怎樣才是最方便的控制方式?

同時,因?yàn)橄M强梢阅_本控制,所以最好是可以做到非互動式的指令。

如下是簡單的步驟:

使能VLC的Remote Control接口

VLC實(shí)際上擁有靈活強(qiáng)大的控制方式,由于我們上來就限定了Headless,那么命令行顯然是先決條件,VLC文檔中已經(jīng)列出了支持的幾種Remote方式:

  • rc interface
  • ncurses interface
  • telnet interface

考慮到三者中rc應(yīng)該是最強(qiáng)大和靈活的(ncurses需要configure,telnet更多的是互動型,何況rc本身就可以支持telnet訪問),我們就focus在rc 接口上。

使能方法非常簡單,調(diào)用vlc的時候,用:

cvlc -I rc --rc-fake-tty --rc-host <ip>:<port>

選項(xiàng) 意義
'-I rc' 啟動rc接口;
'--rc-fake-tty' 強(qiáng)迫將標(biāo)準(zhǔn)輸入當(dāng)做tty
'--rc-host' 選定的監(jiān)聽地址和端口

注意:如果需要局域網(wǎng)內(nèi)訪問,請?zhí)顚懕緳C(jī)ip,如果只要本機(jī)訪問,用localhost就可以了

得到如下信息(忽略那些錯誤吧,畢竟Headless么,很多接口對VLC來說都缺失,但是不影響使用)

cvlc -I rc --rc-fake-tty --rc-host localhost:8888
VLC media player 2.0.3 Twoflower (revision 2.0.2-93-g77aa89e)
[0x11eed70] inhibit interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[0x11eed70] main interface error: no suitable interface module
[0x11eed70] main interface error: no suitable interface module
[0x10858f0] main libvlc error: interface "globalhotkeys,none" initialization failed
[0x11eed70] [cli] lua interface: Listening on host "localhost:8888".

RC 接口指令

直接借助幫助文件, 可見還是非常強(qiáng)大的:

+----[ CLI commands ]
| add XYZ . . . . . . . . . . . . . . . . . . . . add XYZ to playlist
| enqueue XYZ . . . . . . . . . . . . . . . . . queue XYZ to playlist
| playlist . . . . . . . . . . . . . show items currently in playlist
| search [string] . . search for items in playlist (or reset search)
| sort key . . . . . . . . . . . . . . . . . . . . . sort the playlist
| sd [sd] . . . . . . . . . . . . . show services discovery or toggle
| play . . . . . . . . . . . . . . . . . . . . . . . . . . play stream
| stop . . . . . . . . . . . . . . . . . . . . . . . . . . stop stream
| next . . . . . . . . . . . . . . . . . . . . . . next playlist item
| prev . . . . . . . . . . . . . . . . . . . . previous playlist item
| goto, gotoitem . . . . . . . . . . . . . . . . . goto item at index
| repeat [on|off] . . . . . . . . . . . . . . toggle playlist repeat
| loop [on|off] . . . . . . . . . . . . . . . . toggle playlist loop
| random [on|off] . . . . . . . . . . . . . . toggle playlist random
| clear . . . . . . . . . . . . . . . . . . . . . clear the playlist
| status . . . . . . . . . . . . . . . . . . . current playlist status
| title [X] . . . . . . . . . . . . . . set/get title in current item
| title_n . . . . . . . . . . . . . . . . next title in current item
| title_p . . . . . . . . . . . . . . previous title in current item
| chapter [X] . . . . . . . . . . . . set/get chapter in current item
| chapter_n . . . . . . . . . . . . . . next chapter in current item
| chapter_p . . . . . . . . . . . . previous chapter in current item
|
| seek X . . . . . . . . . . . seek in seconds, for instance `seek 12'
| pause . . . . . . . . . . . . . . . . . . . . . . . . toggle pause
| fastforward . . . . . . . . . . . . . . . . . . set to maximum rate
| rewind . . . . . . . . . . . . . . . . . . . . . set to minimum rate
| faster . . . . . . . . . . . . . . . . . . faster playing of stream
| slower . . . . . . . . . . . . . . . . . . slower playing of stream
| normal . . . . . . . . . . . . . . . . . . normal playing of stream
| rate [playback rate] . . . . . . . . . . set playback rate to value
| frame . . . . . . . . . . . . . . . . . . . . . play frame by frame
| fullscreen, f, F [on|off] . . . . . . . . . . . . toggle fullscreen
| info . . . . . . . . . . . . . information about the current stream
| stats . . . . . . . . . . . . . . . . show statistical information
| get_time . . . . . . . . . seconds elapsed since stream's beginning
| is_playing . . . . . . . . . . . . 1 if a stream plays, 0 otherwise
| get_title . . . . . . . . . . . . . the title of the current stream
| get_length . . . . . . . . . . . . the length of the current stream
|
| volume [X] . . . . . . . . . . . . . . . . . . set/get audio volume
| volup [X] . . . . . . . . . . . . . . . raise audio volume X steps
| voldown [X] . . . . . . . . . . . . . . lower audio volume X steps
| adev [X] . . . . . . . . . . . . . . . . . . . set/get audio device
| achan [X] . . . . . . . . . . . . . . . . . set/get audio channels
| atrack [X] . . . . . . . . . . . . . . . . . . . set/get audio track
| vtrack [X] . . . . . . . . . . . . . . . . . . . set/get video track
| vratio [X] . . . . . . . . . . . . . . . set/get video aspect ratio
| vcrop, crop [X] . . . . . . . . . . . . . . . . set/get video crop
| vzoom, zoom [X] . . . . . . . . . . . . . . . . set/get video zoom
| vdeinterlace [X] . . . . . . . . . . . . . set/get video deintelace
| vdeinterlace_mode [X] . . . . . . . . set/get video deintelace mode
| snapshot . . . . . . . . . . . . . . . . . . . . take video snapshot
| strack [X] . . . . . . . . . . . . . . . . . set/get subtitles track
|
| vlm . . . . . . . . . . . . . . . . . . . . . . . . . load the VLM
| description . . . . . . . . . . . . . . . . . describe this module
| help, ? [pattern] . . . . . . . . . . . . . . . . . a help message
| longhelp [pattern] . . . . . . . . . . . . . . a longer help message
| lock . . . . . . . . . . . . . . . . . . . . lock the telnet prompt
| logout . . . . . . . . . . . . . . exit (if in a socket connection)
| quit . . . . . . . . quit VLC (or logout if in a socket connection)
| shutdown . . . . . . . . . . . . . . . . . . . . . . . shutdown VLC
+----[ end of help ]

如何訪問:

實(shí)際上,在一些討論中看到,如果只是需要本機(jī)訪問,更高效的辦法是借助一個unix socket文件,從而通過socket文件來訪問,簡單說就是將上面提到的-rc-host選項(xiàng)變成-rc-unix然后用一個文件作為輸入;

這樣可以用類似于形如下面指令的方法來模擬socket訪問 (作者以O(shè)SX為例,應(yīng)當(dāng)是沒有問題的):

echo normal | nc -U /Users/vlc.sock

我的例子,Debian中,nc似乎是不適用,更多人推薦用socat (需要安裝)

echo “pause” | socat – UNIX-CONNECT:/Users/vlc.sock

上面可以理解成將管道化之后的ECHO字符向這個Unix的Socket發(fā)送??墒窃谖疫@里死活都會遇到文件connection refused,作為菜鳥,實(shí)在無力解決,特別是看到有強(qiáng)者遇到類似問題交叉比較得出可能和特定版本的kernel stock存在bug有關(guān)之后,不管看不看得懂,我都理直氣壯的放棄了——直接轉(zhuǎn)向了上面提到的host:port的方案。

所以:

OSX

如果是互動式,直接 nc <host> <port>,就可以進(jìn)入這個接口界面了:

$ nc 192.168.199.105 8888
VLC media player 2.0.3 Twoflower
Command Line Interface initialized. Type `help' for help.
$ status
( new input: file:///home/user/test.mp3 )
( audio volume: 256 )
( state playing )
$ info
+----[ Stream 0 ]
|
| Bitrate: 160 kb/s
| Type: Audio
| Channels: Stereo
| Sample rate: 44100 Hz
| Codec: MPEG Audio layer 1/2/3 (mpga)
|
+----[ end of stream info ]

如果不需要互動:

參考上節(jié):

echo status | nc -w 0 <ip> <port>

-w是指示說該命令之后,立刻退出,實(shí)際上OSX下并不一定需要,只是為了和下面Linux對照一下。

LINUX

大致相同,區(qū)別只是在非互動式下,

echo status | nc -q 0 <ip> <port>

兩者區(qū)別只是一個用了' wait'之意,另外一個是' quit'罷了,想想還挺風(fēng)趣....風(fēng)趣個妹啊,這不是折騰跨平臺用戶嗎?!

結(jié)論

至此,該問題解決,不論是想在遠(yuǎn)程控制無輸入(顯示)設(shè)備上的播放,還是想用腳本對其他線程的VLC播放進(jìn)行自動化的干預(yù)控制,都不成問題了。

——怪不得有那么多人喜歡用VLC啊,我恍然。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容