それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

Airplayミラーリングをraspiでやる

appleTV が動かない

AppleTV(第3世代)とAppleTV(第2世代)でミラーリングしていたけど、先日、ついに動かなくなった。

ミラーリングメニューがiOSから出たり出なかったり、ミラーリング選択をしても映ったり映らなかったり。つまりAppleTVを初期化してもまともに動かなくなった。後方互換性を切り捨てるAppleさんですが、やはりインフラとしては不安定すぎて困る。

Raspi でミラーリング

Raspi3でミラーリングすることにした。

FireTVやAndroidスマホでは、ミラーリングができるソフトウェアがちらほらみられるので、Raspiにもないかなと探してみた。

RPiplayがあった。

配布元。 https://github.com/FD-/RPiPlay

インストールとビルド

rm -rf RPiPlay.git
git clone https://github.com/FD-/RPiPlay.git
mv RPiPlay RPiPlay.git
cd RPiPlay.git

sudo apt install cmake libavahi-compat-libdnssd-dev libplist-dev libssl-dev

mkdir build
cd build

cmake ..

make -j

sudo ln rpiplay /usr/local/bin/

apt にはないし、deb作成もないので、とにかく動くって感じだとおもう。OSアップデート追従しないので注意が必要

動作チェック

/usr/local/bin/rpiplay -n AirPiPlay -b auto -a hdmi -vr rpi -ar rpi -l

-lオプション で低レイテンシに対応させないとサウンド(音声)が同期ズレを起こして使い物にならなかった。

ただ、-l低レイテンシ対応させると、操作後のズレが気にはなるが、音が破壊されるよりはマシ。

-l の有無は、ネットワーク環境と機器性能に依存すると思う。私の環境(Raspi3)では低レイテンシにしたほうが安定した。

コマンドオプションはこちら

RPiPlay 1.2: An open-source AirPlay mirroring server for Raspberry Pi
Usage: /usr/local/bin/rpiplay [-n name] [-b (on|auto|off)] [-r (90|180|270)] [-l] [-a (hdmi|analog|off)] [-vr renderer] [-ar renderer]
Options:
-n name               Specify the network name of the AirPlay server
-b (on|auto|off)      Show black background always, only during active connection, or never
-r (90|180|270)       Specify image rotation in multiples of 90 degrees
-f (horiz|vert|both)  Specify image flipping (horiz = horizontal, vert = vertical, both = both)
-l                    Enable low-latency mode (disables render clock)
-a (hdmi|analog|off)  Set audio output device
-vr renderer          Set video renderer to use. Available renderers:
    rpi: Raspberry Pi OpenMAX accelerated H.264 renderer [Default]
    dummy: Dummy renderer; does not actually display video
-ar renderer          Set audio renderer to use. Available renderers:
    rpi: AAC renderer using fdk-aac for decoding and OpenMAX for rendering [Default]
    dummy: Dummy renderer; does not actually play audio
-d                    Enable debug logging
-v/-h                 Displays this help and version information

systemdでサービスにした

[Unit]
Description=AirTunes ミラーリング  receiver
Documentation=https://github.com/FD-/RPiPlay
After=sound.target
Requires=avahi-daemon.service
After=avahi-daemon.service

[Service]
Type=simple
Restart=on-failure
ExecStart=/usr/local/bin/rpiplay -n AirPiPlay -b auto -a hdmi -vr rpi -ar rpi -l
#User=takuya
#Group=takuya

[Install]
WantedBy=multi-user.target

Airplay1,2 のバージョン

Airplay2 は使えないので、アプリ内からのミラーリング指定・ボリュームからの出力指定ができない。基本的に「ミラーリング」だけである。

将来的に使えなくなるとは思うが、あと数年は行けるかなと思う。

https://github.com/FD-/RPiPlay#airplay-protocol-versions

https://qiita.com/SogoK/items/6a32eb13769c081680d3#rpiplay%E3%81%8C%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6%E3%81%84%E3%82%8B%E3%83%97%E3%83%AD%E3%83%88%E3%82%B3%E3%83%AB%E3%81%AF%E5%B0%86%E6%9D%A5%E7%9A%84%E3%81%AB%E3%82%B5%E3%83%9D%E3%83%BC%E3%83%88%E5%A4%96%E3%81%A8%E3%81%AA%E3%82%8A%E3%81%86%E3%82%8B

参考資料