Raspberry PI4にMirakurun

 Raspberry pi4 とPX-W3U4でDVR Tuner Serverを稼働させる。
 色々いじっていて不具合が出た時に再インストールできるよう、あくまで自分なりの覚えなので詳細が抜けていたり間違いがあるかもしれません。

Raspberry pi4にはUbuntu Server 22.04.1 LTS(64-bit)をRaspberry Pi Imagerでインストール。

この時、詳細な設定で
・ホスト名にチェック、サーバー名を入力
・SSHを有効に
  ・パスワード認証を使う
・ユーザー名とパスワードを設定
・ロケールを設定
とそれぞれ設定した後保存し、書き込み

電源ONして、他機の端末からSSHで{サーバー名}.localに接続。
最初にアドレスを確認 DHCPで自動割当担っているが、固定にしたい。

/etc/netplan/50-cloud-init.yamlを以下のように変更

本当は90-mirakurun.yamlとかを作成したほうがいいらしい?

cat /etc/netplan/50-cloud-init.yaml

network:
    ethernets:
        eth0:
            dhcp4: no
            # optional: true
            addresses: [192.168.x.xxx/24]
            routes:
              - to: default
                via: 192.168.x.1
                metric: 100
            nameservers:
                addresses: [192.168.x.1]
            dhcp6: no
    version: 2

sudo netplan apply
ip a で確認
念の為 sudo reboot して再度端末からログインして設定したいアドレスになっているのを確認。

必要なソフトを前もってインストール

sudo apt install unzip gcc make build-essential git dkms cmake pcscd pcsc-tools libpcsclite-dev pkg-config g++ autoconf curl

PLEX PX-W3U4/W3PE4/Q3PE4 Unofficial Linux driverをインストール

cd
git clone https://github.com/nns779/px4_drv
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 ../

DKMSでドライバのインストール

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
sudo modprobe px4_drv

[ カーネルモジュールのロードの確認]
lsmod | grep -e ^px4_drv
     px4_drv 176128 0

PX-W3U4をUSBに接続
ls /dev/px4*
    /dev/px4video0 /dev/px4video1 /dev/px4video2 /dev/px4video3 となるのを確認

arib25ライブラリの設定

libpcscliteを都合でビルドし直した場合、wpa supplicantやKVMが使用できなくなる。
そこでlibpcscliteをlibpcsckaiに変更し、alib25にはlibpcsckaiを使用するようにする。

改変版ビルド後
sudo cp libpcsclite.so.1.0.0 /usr/lib/aarch64-linux-gnu/libpcsckai.so.1.0.0
( x86の場合は/usr/lib/x86_64-linux-gnu/libpcsckai.so.1.0.0 )
cd /usr/lib/aarch64-linux-gnu/
sudo cp libpcsckai.so.1.0.0 libpcsckai.so
sudo cp libpcsckai.so.1.0.0 libpcsckai.so.1

PCファイルを作成

cd /usr/lib/aarch64-linux-gnu/pkgconfig
sudo cp libpcsclite.pc libpcsckai.pc
sudo nano libpcsckai.pc

prefix=/usr
exec_prefix=${prefix}
libdir=${prefix}/lib/aarch64-linux-gnu
includedir=${prefix}/include/PCSC
usbdropdir=/usr/lib/pcsc/drivers
serialconfdir=/etc/reader.conf.d

Name: PCSC Lite
Description: PC/SC smart card interface
Version: 1.9.5
Libs: -L${libdir} -lpcsclite   --->  Libs: -L${libdir} -lpcsckai
Libs.private: -lpthread
Cflags: -I${includedir} -pthread

ここで、一度 sudo reboot

arib25の導入

cd
git clone https://github.com/stz2012/libarib25.git
cd libarib25

cmake関係の[ libpcsclite ] を [ libpcsckai ] に変更

nano CMakeLists.txt

set(PCSC_CFLAGS “pkg-config libpcsckai –cflags”)
set(PCSC_LIBS “pkg-config libpcsckai –libs”)
  の2行を先頭行「cmake_minimum_required(VERSION 2.8.5)」の後に追加

  set(WITH_PCSC_PACKAGE “libpcsclite” CACHE STRING “pkg-config package name for PC/SC”) の「libpcsclite」を「libpcsckai」とし、保存する。

さらに cmake/FindPCSC.cmakeに libpcsclite」があったので [ libpcsckai ] に修正。

cmake ./
make
sudo make install
sudo /sbin/ldconfig

ライブラリが適切にリンクされているか確認
sudo ldd libarib25.so
libpcsckai.soが出力されているのを確認。

recpt1のインストール

cd
git clone https://github.com/stz2012/recpt1.git
cd recpt1/recpt1
./autogen.sh
./configure
make
sudo make install

録画テスト

cd
recpt1 BS01_2 10 BS01_2.ts
recpt1 BS15_1 10 BS15_1.ts
recpt1 13 10 13.ts

b25 BS01_2.ts BS01.2x.ts というふうにデコードし、できているか確認

Node.jsのインストール

sudo apt-get install nodejs npm
sudo npm install -g n
sudo n 16
sudo apt purge nodejs

/usr/local/bin/node -v
v16.19.0 2022/12/16
/usr/local/bin/npm -v
8.19.3 2022/12/16

Mirakurunのインストール

sudo npm install pm2 -g
sudo npm install mirakurun -g -production
sudo mirakurun init # to install as service
sudo mirakurun restart # when updated

arib-b25-stream-testのインストール

#libpcscliteをlibpcsckaiへと名称変更したときは、arib-b25-stream-testを対応させる
wget https://registry.npmjs.org/arib-b25-stream-test/-/arib-b25-stream-test-0.2.9.tgz
tar -xzvf arib-b25-stream-test-0.2.9.tgz
#libpcscliteをlibpcsckaiと名前を変更した場合
cd package/
nano src/Makefile
libpcsclite ==> libpcsckai
#名前を変えていない場合は上2行は適用しない
sudo npm install . -g -unsafe

Mirakurunの設定

/usr/local/etc/mirakurun フォルダ内のserver.yml , tuners.yml , channels.ym ファイルを修正

server.yml は変更不要

tuners.yml の修正

PX-W3U4の場合の設定です。

cat /usr/local/etc/mirakurun/tuners.yml

- name: PX4-S1
  types:
    - BS
    - CS
  command: recpt1 --device /dev/px4video0 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: false
- name: PX4-S2
  types:
    - BS
    - CS
  command: recpt1 --device /dev/px4video1 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: false
- name: PX4-T1
  types:
    - GR
  command: recpt1 --device /dev/px4video2 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: false
- name: PX4-T2
  types:
    - GR
  command: recpt1 --device /dev/px4video3 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: false
- name: PX4-S3
  types:
    - BS
    - CS
  command: recpt1 --device /dev/px4video4 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: true
- name: PX4-S4
  types:
    - BS
    - CS
  command: recpt1 --device /dev/px4video5 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: true
- name: PX4-T3
  types:
    - GR
  command: recpt1 --device /dev/px4video6 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: true
- name: PX4-T4
  types:
    - GR
  command: recpt1 --device /dev/px4video7 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: true
- name: mirakurun-S1
  types:
    - BS
    - CS
  remoteMirakurunHost: 192.168.1.104          # 他mirakurunサーバーのアドレス
  remoteMirakurunDecoder: false  
  decoder: arib-b25-stream-test
  isDisabled: true
- name: mirakurun-104-S2
  types:
    - BS
    - CS
  remoteMirakurunHost: 192.168.1.104          # 他mirakurunサーバーのアドレス
  remoteMirakurunDecoder: false
  decoder: arib-b25-stream-test
  isDisabled: true
- name: mirakurun-t1
  types:
    - GR
  remoteMirakurunHost: 192.168.1.104          # 他mirakurunサーバーのアドレス
  remoteMirakurunDecoder: false  
  decoder: arib-b25-stream-test
  isDisabled: true
- name: mirakurun-t2
  types:
    - GR
  remoteMirakurunHost: 192.168.1.104          # 他mirakurunサーバーのアドレス
  remoteMirakurunDecoder: false
  decoder: arib-b25-stream-test
  isDisabled: true

チャンネル設定

参考に大阪地方のチャンネルの内容です。見れない、見ることもないものが沢山あります。
適当に削除するなりしてください。

cat /usr/local/etc/mirakurun/channels.yml

 - name: NHKEテレ1大阪
  type: GR
  channel: '13'
- name: MBS毎日放送
  type: GR
  channel: '16'
- name: ABCテレビ1
  type: GR
  channel: '15'
- name: 関西テレビ1
  type: GR
  channel: '17'
- name: 読売テレビ1
  type: GR
  channel: '14'
- name: スカパー!ナビ1
  type: GR
  channel: '20'
- name: NHK総合1・大阪
  type: GR
  channel: '24'
- name: テレビ大阪1
  type: GR
  channel: '18'
- name: サンテレビ1
  type: GR
  channel: '26'
- 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_0
  serviceId: 231
- name: 放送大学 BS2
  type: BS
  channel: BS11_0
  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
  isDisabled: true
- 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_1
  serviceId: 251
- name: 日本映画専門チャンネル
  type: BS
  channel: BS21_1
  serviceId: 255
- name: ディズニー・チャンネル
  type: BS
  channel: BS23_0
  serviceId: 256
- name: ショップチャンネル
  type: CS
  channel: CS8
  serviceId: 55
- name: QVC
  type: CS
  channel: CS22
  serviceId: 161
- name: 東映チャンネル
  type: CS
  channel: CS8
  serviceId: 218
- name: 衛星劇場
  type: CS
  channel: CS10
  serviceId: 219
- name: 映画・chNECO
  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: 日テレジータス
  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: KBS World
  type: CS
  channel: CS10
  serviceId: 317
- name: Mnet
  type: CS
  channel: CS8
  serviceId: 318
- 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: 歌謡ポップス
  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
- name: WOWOWプラス
  type: BS
  channel: BS21_0
  isDisabled: false
  serviceId: 252
- name: BSテレ東2
  type: BS
  channel: BS01_2
  isDisabled: true
  serviceId: 172
- name: BS松竹東急
  type: BS
  channel: BS23_3
  isDisabled: false
  serviceId: 260
- name: BSJapanext
  type: BS
  channel: BS23_2
  isDisabled: false
  serviceId: 263
- name: BSよしもと
  type: BS
  channel: BS23_1
  isDisabled: false
  serviceId: 265


#設定後 Mirakurunをリスタートする。
sudo mirakurun restart

Mirakurunをアップデートする場合

sudo mirakurun stop
sudo npm update rivarun -g
sudo npm install mirakurun@latest -g --unsafe --product
sudo mirakurun start

Mirakurunログローテーション設定

sudo 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
} 

ログの抑制

/etc/rsyslog.d/50-default.conf の以下の箇所をコメントにします。

#cron.*                         /var/log/cron.log
#daemon.*                       -/var/log/daemon.log
#kern.*                         -/var/log/kern.log
#lpr.*                          -/var/log/lpr.log
#mail.*                         -/var/log/mail.log
#user.*                         -/var/log/user.log
#mail.info                      -/var/log/mail.info
#mail.warn                      -/var/log/mail.warn
#mail.err                       /var/log/mail.err

コメント