概要
Raspberry piにインストールされているVLCプレイヤーでYouTube動画を再生する内容について説明して行きたいと思います。
目的
Raspbery piを利用して特定YouTubeのURL一覧を再生するのが目的です。
勿論特定動画ファイルもリストに追加して再生するのも可能です。
事前設定
VLCプレイヤーでTelnet機能を有効化する必要があります。
①VLCプレイヤーで[Tools]-[Preferences]をクリックしてください。
②[Simple Preferences]画面で以下の[Show settings]タブ内容で
Simple→Allにラジオボタンをクリックしてください。
③[Main interfaces]-[Extra interface modules]-[Telnet]にチェックを入れた後、「Save」ボタンをクリックします。
④[Main interfaces]-[Lua]をクリックします。「Lua Telnet」タブに該当する情報を入力した後、「Save」ボタンをクリックします。
⑤これで事前設定は完了です。
VLCプレイヤーへTelnetで接続
①SSHでRaspbery Piへ接続をします。
pi@raspberry:~ $
②TelnetでVLCプレイヤーへ接続します。
pi@raspberry:~ $ telnet localhost 4142
Trying ::1...
Connected to localhost.
Escape character is '^]'.
VLC media player 3.0.11 Vetinari
Password:
Welcome, Master
>
③YoutubeのURLをプレイヤーに追加します。
参照URL
https://www.youtube.com/watch?v=zTOXdULHNsA
https://www.youtube.com/watch?v=oOFJKlgYi_8
pi@raspberry:~ $ telnet localhost 4142
Trying ::1...
Connected to localhost.
Escape character is '^]'.
VLC media player 3.0.11 Vetinari
Password:
Welcome, Master
> add https://www.youtube.com/watch?v=zTOXdULHNsA
> add https://www.youtube.com/watch?v=oOFJKlgYi_8
④登録したYouTubeのURLを再生します。
pi@raspberry:~ $ telnet localhost 4142
Trying ::1...
Connected to localhost.
Escape character is '^]'.
VLC media player 3.0.11 Vetinari
Password:
Welcome, Master
> add https://www.youtube.com/watch?v=zTOXdULHNsA
> add https://www.youtube.com/watch?v=oOFJKlgYi_8
> play
⑤全体画面に再生したい場合は以下のコマンドを実行します。
コマンドラインで次のコマンドでOn|Offが可能です。
f on | off
pi@raspberry:~ $ telnet localhost 4142
Trying ::1...
Connected to localhost.
Escape character is '^]'.
VLC media player 3.0.11 Vetinari
Password:
Welcome, Master
> add https://www.youtube.com/watch?v=zTOXdULHNsA
> add https://www.youtube.com/watch?v=oOFJKlgYi_8
> play
> f on
★VNCから再生する場合は、VNC画面では真っ暗ですが、実際の画面には全体画面で再生されていると思います。デフォルト再生を「全体画面表示」にしておくのも良いかもしれません。★
VLCプレイヤーのコマンド一覧
コマンド一覧を確認する「help」コマンドを実行します。
次のコマンドをTelnetで実行するとリモコンのような操作が出来ます。
+----[ 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)
| delete [X] . . . . . . . . . . . . . . . . delete item X in playlist
| move [X][Y] . . . . . . . . . . . . move item X in playlist after Y
| 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 [X] . . information about the current stream (or specified id)
| stats . . . . . . . . . . . . . . . . show statistical information
| get_time . . . . . . . . . seconds elapsed since streams 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
| achan [X] . . . . . . . . . . . . set/get stereo audio output mode
| 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 deinterlace
| vdeinterlace_mode [X] . . . . . . . set/get video deinterlace mode
| snapshot . . . . . . . . . . . . . . . . . . . . take video snapshot
| strack [X] . . . . . . . . . . . . . . . . . set/get subtitle 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 ]
Python, Telnet, Pexpectを利用してコマンド自動化
環境設定及び説明資料は下記のサイトを参照してください。
参照サイト:pexpect - 対話アプリの自動運転
コマンド実行用のサンプルソース
Telnetパッケージはインストールされてない可能性もありますので、
次のコマンドでTelnetとpexpectをインストールした後、
以下のサンプルソースを実行してみてください。
★実行する前にはVLCプレイヤーを実行する必要があります。★
●パッケージインストール
sudo apt-get install telnet
pip install pexpect
●サンプルソース
# !/usr/bin/python
import pexpect
import sys
host = "localhost"
port = "4142"
passwd = "●●●●●●"
ret = "\n"
prompt = u">"
def exe_cmd(cmd):
p = pexpect.spawn("telnet " + host + " " + port)
p.send(passwd + ret)
p.expect(prompt)
print "> " + p.before + '"' + p.after + '"'
p.send(cmd + ret)
p.expect(prompt)
print "> " + p.before + '"' + p.after + '"'
p.terminate()
p.expect(pexpect.EOF)
if __name__ == "__main__":
args = sys.argv
if len(args) > 1:
print(args[1])
exe_cmd(args[1])
終わりに
上記のリモコンコマンドを用意して実際のリモコンをRaspbery Piに付けて試してみたいですね。
この内容にWEBまたはAndroid,iPhoneのAPPからYoutube一覧を登録するシステムがあればパソコンを使わずに展示会用の動画再生するものが簡単にできます。勿論動画を事前にRaspberry Piに保存してあればそれも再生可能です。
今度リモコンが届いたら動画を再生するものを作ってみます。