LIRCではプログラムごとにリモコンキーを割り当てることができます。従来はmplayerにのみ対応させていましたが、追加でVLCにも対応させました。
LIRC参考サイト
https://wiki.archlinux.jp/index.php/LIRC
対象ハードとOS
OrangePi PC: ARMBIAN 5.38 stable Ubuntu 16.04.4 LTS 3.4.113-sun8i
VLCには様々なコマンドが用意されているためインストールするVLCはvlc-noxとします。(デスクトップインターフェイスは不要の為)
VLCコマンド一覧:VLC command-line help - VideoLAN Wiki
vlc-noxのインストール
$ sudo apt install vlc-nox
注) vlc-noxはvlc-bin+vlc-plugin-baseへ移行したため下記パッケージをインストール
$ sudo apt install vlc-bin vlc-plugin-base
プログラム毎にLIRC用設定ファイルを用意します。上記LIRC参考サイトに従いユーザディレクトリか、/etc/lircディレクトリに作成します。
/etc/lircに作成する場合
lircrcファイル内に新たに作成するインクルードファイルを指定します。(このファイル内でmplayer用にリモコンキーを割当てた内容は全て/etc/lirc/mplayerに移行します)
$ sudo pico /etc/lirc/lircrc
include "/etc/lirc/mplayer"
include "/etc/lirc/vlc"
lirc/mplayerはLIRCでmplayerをコントロールするリモコンキーを割当てたファイルです。
lirc/vlcで使用するリモコンキーの割当てについては以下を参照して下さい。
https://wiki.videolan.org/VLC_HowTo/Use_with_lirc/
VLCキーコード割当て例)
# This is an example .lircrc file that shows the different config strings that
# vlc understand. Button names are from an animax remote, and these may change
# with different remotes.
# The current full list of config strings vlc understands is always in vlc's
# src/libvlc.h file. Look for lines like:
# add_key( "key-fullscreen", KEY_FULLSCREEN, FULLSCREEN_KEY_TEXT,
# FULLSCREEN_KEY_LONGTEXT )
# You will need the first argument of these lines. in this case: key-fullscreen
begin
prog = vlc
button = PLAY_UP
config = key-play
end
begin
prog = vlc
button = PAUSE_UP
config = key-pause
This file has been truncated. show original
VLCによる再生とLIRCによる動作確認
$ cvlc --control=lirc xxx.mp3
音楽が再生されたら、/etc/lirc/vlcで割当てたリモコンキーを押下し動作を確認して下さい。
VLC User Documentation
https://vlc-user-documentation.readthedocs.io/en/latest/index.html
Where does VLC store its config file?
https://vlc-user-documentation.readthedocs.io/en/latest/support/faq/vlcmediaplayer.html#where-does-vlc-store-its-config-file
VLCは管理者ユーザでは動作しません。このためシステムデーモンとして動作しているlircではirexecによる起動はできません。vlcのみユーザレベルで起動するようにします。
以下NHKラジオストリームの再生スクリプトnhk.shです。管理者権限でユーザuserを指定してvlcを起動します。
#!/bin/bash
# if no command line arg given
# set rental to Unknown
if [ -z $1 ]
then
rental="*** Unknown NHK channel ***"
elif [ -n $1 ]
then
# otherwise make first arg as a rental
nhk=$1
fi
# use case statement to make decision for rental
case $nhk in
"ch1") sudo killall mplayer rtmpdump vlc; sudo -H -u user bash -c 'cvlc -q --control=lirc https://nhkradioakr1-i.akamaihd.net/hls/live/511633/1-r1/1-r1-01.m3u8 &';;
"ch2") sudo killall mplayer rtmpdump vlc; sudo -H -u user bash -c 'cvlc -q --control=lirc /home/user/music/nhk.m3u &';;
"fm") sudo killall mplayer rtmpdump vlc; sudo -H -u user bash -c 'cvlc -q --control=lirc https://nhkradiobkfm-i.akamaihd.net/hls/live/512070/1-fm/1-fm-01.m3u8 &';;
esac
管理者権限にて起動するかテスト
$ sudo bash ~/music/nhk.sh ch1
$ sudo bash ~/music/nhk.sh ch2
/etc/asound.conf内のdmixの以下の箇所はコメントアウトして下さい。
# ipc_key_add_uid false # let multiple users share
# ipc_perm 0666 # IPC permissions for multi-user sharing (octal, default 0600)
VLCコマンド制御
netcat(nc)によりターミナル経由でもVLCをコントロール出来ます。
vlc lirc
https://wiki.videolan.org/VLC_HowTo/Use_with_lirc/
netcat
$ vlc -I rc --rc-host localhost:12345 /home/ondra/playlist.m3u
$ echo “pause” | netcat localhost 12345 -q 1
$ echo “play” | netcat localhost 12345 -q 1
-q 1 —> netcat 1sec後quit
ボリューム設定
gain=1.00に指定しないとボリュームアップした時に音が割れるかもしれません。
.config/vlcrc
[alsa] # ALSA audio output
# Audio output device (string)
#alsa-audio-device=default
# Audio output channels (integer)
alsa-audio-channels=2
# Software gain (float)
alsa-gain=1.000000
..........................................................
# Audio gain (float)
gain=1.000000
# Audio output volume step (float)
#volume-step=12.800000
# Remember the audio volume (boolean)
volume-save=0 ボリューム設定の上書き無効
...........................................................
# Audio output module (string)
aout=ALSA
ALSAボリュームコントロール
irexecによるvlcのボリュームコントロールはゲインが上書きされるため音割れ発生の原因になります。
ボリュームコントロールにはALSAコマンドを利用します。
$ sudo pico /etc/lirc/irexec.lircrc
begin
prog = irexec
button = vol+
config = amixer set Master 2%+ > /dev/null 2>&1 &
repeat = 1
end
begin
prog = irexec
button = vol-
config = amixer set Master 2%- > /dev/null 2>&1 &
repeat = 1
end
cvlcによるYouTube再生
再生アドレスにはYouTubeのウェブページアドレスではなく、"share"をクリックして表示されるアドレスを指定します。
併せてビデオ再生が必要ない場合 --no-video
を指定します。
https://wiki.videolan.org/VLC_command-line_help/
Video
These options allow you to modify the behavior of the video output subsystem. You can for example enable video filters (deinterlacing, image adjusting, etc.). Enable these filters here and configure them in the "video filters" modules section. You can also set many miscellaneous video options.
--video, --no-video Enable video
(default enabled)
You can completely disable the video output. The video decoding stage
will not take place, thus saving some processing power.
command-line, vlc
$ cvlc --no-video -q --control=lirc -I rc --rc-host localhost:12345 https://youtu.be/share_link_address
VLC でYouTube が再生不可になったため、ソースからのビルド・インストールを試みたが、最新版のLuaによるYouTube再生スクリプトをダウンロードして指定のディレクトリに格納することで対応可。
VLCビルド・コンパイル
VLC media player - All pull requests are ignored, please follow https://wiki.videolan.org/Sending_Patches_VLC/ - GitHub - videolan/vlc: VLC media player - All pull requests are ignored, please foll...
手順
https://wiki.videolan.org/UnixCompile/
Lua in VLC
Lua Playlist
https://wiki.videolan.org/Documentation:Building_Lua_Playlist_Scripts/
最新のLua によるYouTube再生スクリプト をダウンロードし以下ディレクトリに格納 (Ubuntu20.04) 。
~/.local/share/vlc/lua/playlist
OSによる格納先
C:\Program Files\VideoLAN\VLC\lua\playlist\ on Windows;
VLC.app/Contents/MacOS/share/lua/playlist/ on Mac OS X;
/usr/share/vlc/lua/playlist/ on Linux.
Lua
https://www.lua.org/