Raspberry Pi 4 でMirakurunを動かしてWindowsで録画するための覚書
これまでずっとWindows機にPLEX社のPX-W3U4 2台を接続し、MirakurunとEDCBで録画してきたのですが、9月ごろにマシンのSSDを交換してからなぜか酷くドロップが発生するようになりました。
仕方がないのでもとのSSDに戻したものの改善せず。マシンが壊れたかとほかのマシンに切り替えてみるもののうまくいかず。
もともとPLEXのテレビチューナーのWindows用ドライバーはドロップが多いと評判が悪く、またMirakurunはLinuxで動かすことを前提としているため、どこかのタイミングでLinuxに切り替えようと思っていたこともあり、この際思い切ってRaspberry Pi 4に切り替えることを決意。
結果としてドロップが全くと言ってもいいほど発生しないようになったので今後環境を再構築するためのメモ。
前提
今回はRaspberry Pi 4上にUbuntu 20.10をインストールし、そこにMirakurunをインストール。
録画自体はWindows機でEDCBを用いる運用にしています。
通常はDTVチューナーサーバーであるMirakurunと、録画システムであるChinachuやEPGStationを一つのLinuxマシン上で動かすのがセオリーなのですが、
現時点ではEDCBのほうがEPGStationより高機能であり、かつ慣れていること、ドロップ対策が優先だったので、録画処理はできるだけそのまま再利用できることを求めた結果。
いつかは一つにまとめたいところ。
利用するチューナーはPX-W3U4。これを2台使っています。
また、ドロップ対策でRaspberry Pi側で放送の復号を行わず、Windows機側で復号しています。 Raspberry Pi 4のスペックならそんなに気にする必要はなさそうなので、折を見てRaspberry Pi側にB-CASカードリーダーを接続する予定。
MirakurunはメジャーバージョンアップしてからDocker利用が推奨されているんですが、今回の環境では正常に動かなかったので従来通りnpmインストールとしています。
環境構築
Linux側の設定
- SSHログイン時に鍵認証を用いるよう変更
- NTPDで時間同期
- ホストネーム設定
sudo hostnamectl set-hostname tvrasp
- タイムゾーンを Asia/Tokyoに設定
sudo timedatectl set-timezone Asia/Tokyo
- mDNSによる名前解決(オプション)
sudo apt install avahi-daemon
必要なライブラリ等のインストール
下記を実行。
sudo apt install -y build-essential autoconf libtool pcsc-tools pkg-config libpcsclite-dev libccid pcscd cmake dkms unzip apt-transport-https ca-certificates gnupg-agent software-properties-common
PX-W3U4のドライバーインストール
今回は非公式ドライバを利用します。こちらのほうが断然安定していると評判が良いので。
なお、PX-S1UDなど一部のチューナーはLinux標準ドライバーが対応しているのでそちらを使ったほうが良いです。
mkdir /tmp/workdir cd /tmp/workdir git clone https://github.com/nns779/px4_drv.git cd px4_drv/fwtool/ make wget http://plex-net.co.jp/plex/pxw3u4/pxw3u4_BDA_ver1x64.zip -O pxw3u4_BDA_ver1x64.zip unzip -oj pxw3u4_BDA_ver1x64.zip pxw3u4_BDA_ver1x64/PXW3U4.sys ./fwtool PXW3U4.sys it930x-firmware.bin sudo mkdir -p /lib/firmware sudo cp it930x-firmware.bin /lib/firmware cd ../ sudo cp -a ./ /usr/src/px4_drv-0.2.1 sudo dkms add px4_drv/0.2.1 sudo dkms install px4_drv/0.2.1
インストールしたらチューナーを接続後 ls /dev/px4video*
を実行すると、以下のようにチューナーが見えるはず。
/dev/px4video0 /dev/px4video1 /dev/px4video2 /dev/px4video3 /dev/px4video4 /dev/px4video5 /dev/px4video6 /dev/px4video7
今回はPX-W3U4を2台接続したので上記のような表示に。
0,1,4,5が衛星放送、2,3,6,7が地上デジタル放送のチューナーになります。
MULTI2復号ライブラリのインストール
今回B-CASカードの復号処理はWindows側でやるのですが、recpt1ビルド時に必要なので。(--enable-b25オプションを付けてビルドする場合のみ。)
cd /tmp/workdir git clone https://github.com/stz2012/libarib25.git cd libarib25 cmake . make sudo make install
録画コマンド recpt1のインストール
cd /tmp/workdir git clone https://github.com/stz2012/recpt1 cd ./recpt1/recpt1 ./autogen.sh ./configure --enable-b25 make sudo make install
--stripのオプションを利用する場合は --enable-b25
のオプション指定が必要。が、よく考えたらRaspberry Pi上で復号しないなら意味ないことに今更気づいた。
とはいえ今後Raspberry Pi上で復号する可能性もあるのでこれはこれで。
node.jsのインストール
curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt install -y nodejs sudo npm install pm2 -g
この記事を書いている時点では14.xがLTS版。今後は更新に伴って変更必要。
また、プロセスの永続化のためにpm2もこの時点でインストール。
Mirakurunのインストール
下記コマンドをたたくだけ。
sudo npm install mirakurun -g --unsafe-perm --production pm2 startup
Mirakurunの設定
まずは初期設定用のコマンドを実行
sudo mirakurun init
チューナー設定を変更
sudo nano /usr/local/etc/mirakurun/tuners.yml
- name: PX-W3U4-T1 types: - GR command: recpt1 --strip --device /dev/px4video2 <channel> - - decoder: ~ isDisabled: false - name: PX-W3U4-T2 types: - GR command: recpt1 --strip --device /dev/px4video3 <channel> - - decoder: ~ isDisabled: false - name: PX-W3U4-T3 types: - GR command: recpt1 --strip --device /dev/px4video6 <channel> - - decoder: ~ isDisabled: false - name: PX-W3U4-T4 types: - GR command: recpt1 --strip --device /dev/px4video7 <channel> - - decoder: ~ isDisabled: false - name: PX-W3U4-S1 types: - BS - CS command: recpt1 --strip --device /dev/px4video0 <channel> - - isDisabled: false - name: PX-W3U4-S2 types: - BS - CS command: recpt1 --strip --device /dev/px4video1 <channel> - - isDisabled: false - name: PX-W3U4-S3 types: - BS - CS command: recpt1 --strip --device /dev/px4video4 <channel> - - isDisabled: false - name: PX-W3U4-S4 types: - BS - CS command: recpt1 --strip --device /dev/px4video5 <channel> - - isDisabled: false
今回はPX-W3U4を2台構成なのでこんな感じに。
Mirakurunのサーバー側設定
sudo nano /usr/local/etc/mirakurun/server.yml
# logLevel: <number> # -2で極力ログを出さないように logLevel: -2 # path: <string> path: /var/run/mirakurun.sock # port: <number> # You can change this if port conflicted. # Don't expose this port on the internet, not even with NAPT. # Use this in LAN or VPN. # `~` to disable TCP port listening. port: 40772 disableEITParsing: true
今回ログレベルを-2にしています。USBメモリー上にシステムを構築している都合、極力書き込みを減らしたいため。
disableEITParsingをtrueにしているのも同様。こちらはEPG情報をMirakurun側で取得しない処理。そのあたりはEDCBでやるので不要。
このオプションはMirakurunのIssueに記載して対応いただいたもの。ありがたや・・・。
チャンネル設定
curl -X PUT "http://localhost:40772/api/config/channels/scan"
を実行することで(正しく設定がされているなら)Mirakurunが地上波放送のチャンネルスキャンを実施します。
衛星放送はスキャンされないですが、基本的に変わらないはずなので下記の記載から地上波の部分だけ自分の地域に置き換えて使ってください。
- name: NHKEテレ type: GR channel: '13' - name: CBC type: GR channel: '18' - name: 中京テレビ type: GR channel: '19' - name: NHK総合 type: GR channel: '20' - name: 東海テレビ type: GR channel: '21' - name: メーテレ type: GR channel: '22' - name: テレビ愛知 type: GR channel: '23' - name: NHK BS1 type: BS channel: BS15_0 serviceId: 101 - name: NHK BSプレミアム type: BS channel: BS03_1 serviceId: 103 - name: BS日テレ type: BS channel: BS13_0 serviceId: 141 - name: BS朝日 type: BS channel: BS01_0 serviceId: 151 - name: BS-TBS type: BS channel: BS01_1 serviceId: 161 - name: BSテレ東 type: BS channel: BS01_2 serviceId: 171 - name: BSフジ type: BS channel: BS13_1 serviceId: 181 - name: WOWOWプライム type: BS channel: BS03_0 serviceId: 191 - name: WOWOWライブ type: BS channel: BS05_0 serviceId: 192 - name: WOWOWシネマ type: BS channel: BS05_1 serviceId: 193 - name: スター・チャンネル1 type: BS channel: BS09_1 serviceId: 200 - name: スター・チャンネル2 type: BS channel: BS15_1 serviceId: 201 - name: スター・チャンネル3 type: BS channel: BS15_1 serviceId: 202 - name: BS11 type: BS channel: BS09_0 serviceId: 211 - name: TwellV type: BS channel: BS09_2 serviceId: 222 - name: 放送大学 BS1 type: BS channel: BS11_1 serviceId: 231 - name: 放送大学 BS2 type: BS channel: BS11_1 serviceId: 232 - name: グリーンチャンネル type: BS channel: BS21_2 serviceId: 234 - name: BSアニマックス type: BS channel: BS13_2 serviceId: 236 - name: BSスカパー! type: BS channel: BS11_0 serviceId: 241 - name: J SPORTS 1 type: BS channel: BS19_1 serviceId: 242 - name: J SPORTS 2 type: BS channel: BS19_2 serviceId: 243 - name: J SPORTS 3 type: BS channel: BS19_3 serviceId: 244 - name: J SPORTS 4 type: BS channel: BS19_0 serviceId: 245 - name: BS釣りビジョン type: BS channel: BS11_2 serviceId: 251 - name: シネフィルWOWOW type: BS channel: BS21_0 serviceId: 252 - name: 日本映画専門チャンネル type: BS channel: BS21_1 serviceId: 255 - name: ディズニー・チャンネル type: BS channel: BS03_2 serviceId: 256 - name: 東映チャンネル type: CS channel: CS8 serviceId: 218 - name: 衛星劇場 type: CS channel: CS10 serviceId: 219 - name: 映画ch・NECO type: CS channel: CS24 serviceId: 223 - name: ザ・シネマ type: CS channel: CS14 serviceId: 227 - name: ムービープラス type: CS channel: CS18 serviceId: 240 - name: スカイA type: CS channel: CS4 serviceId: 250 - name: GAORA type: CS channel: CS12 serviceId: 254 - name: 日テレG+ type: CS channel: CS24 serviceId: 257 - name: ゴルフネットワーク type: CS channel: CS18 serviceId: 262 - name: SKY STAGE type: CS channel: CS16 serviceId: 290 - name: 時代劇専門ch type: CS channel: CS4 serviceId: 292 - name: ファミリー劇場 type: CS channel: CS14 serviceId: 293 - name: ホームドラマch type: CS channel: CS6 serviceId: 294 - name: MONDO TV type: CS channel: CS24 serviceId: 295 - name: TBSチャンネル1 type: CS channel: CS2 serviceId: 296 - name: TBSチャンネル2 type: CS channel: CS22 serviceId: 297 - name: テレ朝チャンネル1 type: CS channel: CS2 serviceId: 298 - name: テレ朝チャンネル2 type: CS channel: CS2 serviceId: 299 - name: 日テレプラス type: CS channel: CS24 serviceId: 300 - name: エンタメ~テレ type: CS channel: CS4 serviceId: 301 - name: チャンネル銀河 type: CS channel: CS18 serviceId: 305 - name: フジテレビONE type: CS channel: CS20 serviceId: 307 - name: フジテレビTWO type: CS channel: CS20 serviceId: 308 - name: フジテレビNEXT type: CS channel: CS20 serviceId: 309 - name: スーパー!ドラマTV type: CS channel: CS14 serviceId: 310 - name: AXN海外ドラマ type: CS channel: CS16 serviceId: 311 - name: FOX type: CS channel: CS22 serviceId: 312 - name: 女性ch/LaLa type: CS channel: CS18 serviceId: 314 - name: AXNミステリー type: CS channel: CS16 serviceId: 316 - name: スペシャプラス type: CS channel: CS16 serviceId: 321 - name: スペースシャワーTV type: CS channel: CS20 serviceId: 322 - name: MTV type: CS channel: CS4 serviceId: 323 - name: ミュージック・エア type: CS channel: CS6 serviceId: 324 - name: エムオン! type: CS channel: CS12 serviceId: 325 - name: 歌謡ポップスch type: CS channel: CS6 serviceId: 329 - name: キッズステーション type: CS channel: CS12 serviceId: 330 - name: カートゥーン type: CS channel: CS6 serviceId: 331 - name: AT-X type: CS channel: CS16 serviceId: 333 - name: ディズニージュニア type: CS channel: CS2 serviceId: 339 - name: ディスカバリーチャンネル type: CS channel: CS6 serviceId: 340 - name: アニマルプラネット type: CS channel: CS6 serviceId: 341 - name: ヒストリーチャンネル type: CS channel: CS14 serviceId: 342 - name: ナショナルジオグラフィック type: CS channel: CS12 serviceId: 343 - name: 日テレNEWS24 type: CS channel: CS8 serviceId: 349 - name: TBS NEWS type: CS channel: CS22 serviceId: 351 - name: BBCワールドニュース type: CS channel: CS16 serviceId: 353 - name: CNNj type: CS channel: CS6 serviceId: 354 - name: 囲碁・将棋チャンネル type: CS channel: CS6 serviceId: 363 - name: スポーツライブ+ type: CS channel: CS10 serviceId: 800 - name: スカチャン1 type: CS channel: CS10 serviceId: 801
ログローテート
USBメモリーでシステムを稼働している都合極力ログ肥大化は避けたい。
pm2 install pm2-logrotate
sudo nano /etc/logrotate.d/mirakurun
/usr/local/var/log/mirakurun.stdout.log /usr/local/var/log/mirakurun.stderr.log /{ daily compress rotate 7 missingok notifempty }
以上で環境構築は完了。
あとはWindows側のBonDriver_MirakurunのiniでRaspberry PiのIPアドレスを指定してやったうえで、チャンネルスキャンを実施すればOK。