Ubuntu24.04とPX-Q3PE4とchinachuで録画サーバーを作る

環境

$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
$ uname -a
Linux tiny-rec01 6.8.0-41-generic #41-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug  2 20:41:06 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

ユーザーの追加とタイムゾーンの設定

# 必要に応じてデフォルトのエディタを変更
$ sudo update-alternatives --config editor

# 必要に応じてadduserでユーザーを作っておきsudoできるようにしておく
$ sudo adduser rec
$ sudo visudo

#タイムゾーンの設定
$ timedatectl
               Local time: Wed 2024-07-17 13:03:12 UTC
           Universal time: Wed 2024-07-17 13:03:12 UTC
                 RTC time: Wed 2024-07-17 13:03:13
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
$ sudo timedatectl set-timezone Asia/Tokyo
$ timedatectl
               Local time: Wed 2024-07-17 22:03:44 JST
           Universal time: Wed 2024-07-17 13:03:44 UTC
                 RTC time: Wed 2024-07-17 13:03:45
                Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

PX-Q3PE4ドライバーのインストール
https://github.com/kazuki0824/recisdb-rs を見ながら粛々と入れる

$ wget https://github.com/tsukumijima/px4_drv/releases/download/v0.4.5/px4-drv-dkms_0.4.5_all.deb
$ sudo apt install -y ./px4-drv-dkms_0.4.5_all.deb

# インストール後に下記エラーが出るがよくわからない
N: Download is performed unsandboxed as root as file '/home/rec/px4-drv-dkms_0.4.5_all.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)

# 確認
$ lsmod | grep -e ^px4_drv
px4_drv               237568  0

$ ls /dev/px4video*
/dev/px4video0  /dev/px4video1  /dev/px4video2  /dev/px4video3  /dev/px4video4  /dev/px4video5  /dev/px4video6  /dev/px4video7
# なんかエラーが出るが動いてるっぽいので無視
[  530.875453] ------------[ cut here ]------------
[  530.875456] UBSAN: array-index-out-of-bounds in /var/lib/dkms/px4_drv/0.4.5/build/driver/ptx_chrdev.c:78:25
[  530.875485] index 2 is out of range for type 'ptx_chrdev [1]'
[  530.875499] CPU: 2 PID: 1255 Comm: recisdb Tainted: G           OE      6.8.0-41-generic #41-Ubuntu
[  530.875502] Hardware name: LENOVO 10RRS3B900/3136, BIOS M1UKT28A 02/18/2019
[  530.875503] Call Trace:

B25デコーダーのインストール
https://github.com/kazuki0824/recisdb-rs を見ながら粛々と入れる

$ wget https://github.com/kazuki0824/recisdb-rs/releases/download/1.2.2/recisdb_1.2.2-1_amd64.deb
$ sudo apt install ./recisdb_1.2.2-1_amd64.deb

# インストール後に下記エラーが出るがよくわからない
N: Download is performed unsandboxed as root as file '/home/rec/recisdb_1.2.2-1_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)

#うまくいくとこんな感じの表記になる
$ recisdb checksignal --device /dev/px4video2 --channel T27
[2024/09/01 16:32:10] INFO:     recisdb version 1.2.2
[2024/09/01 16:32:10] INFO:     Tuner: /dev/px4video2
[2024/09/01 16:32:10] INFO:     Channel: T27 / Terrestrial: 27
41.04dB

$ recisdb tune --device /dev/px4video2 --channel T27 --time 10 test.m2ts
[2024/09/01 16:36:59] INFO:     recisdb version 1.2.2
[2024/09/01 16:36:59] INFO:     Tuner: /dev/px4video2
[2024/09/01 16:36:59] INFO:     Channel: T27 / Terrestrial: 27
[2024/09/01 16:36:59] INFO:     Recording duration: 10 seconds
[2024/09/01 16:37:00] INFO:     Decode: Enabled
[2024/09/01 16:37:00] INFO:     Recording...
[2024/09/01 16:37:10] INFO:     Decoder: 21479424B received, and 18858656B converted.

うまくいかない場合はこんなエラーが出る

# チャンネルがなかったりするとこんな感じ
$ recisdb checksignal --device /dev/px4video2 --channel T18
[2024/09/01 16:31:52] INFO:     recisdb version 1.2.2
[2024/09/01 16:31:52] INFO:     Tuner: /dev/px4video2
[2024/09/01 16:31:52] INFO:     Channel: T18 / Terrestrial: 18
[2024/09/01 16:31:58] ERROR:    Channel selection failed. The channel may not be received.

# BCASカードが認識できなかった時
$ recisdb tune --device /dev/px4video2 --channel T27 --time 10 test.m2ts
[2024/09/01 16:34:37] INFO:     recisdb version 1.2.2
[2024/09/01 16:34:37] INFO:     Tuner: /dev/px4video2
[2024/09/01 16:34:37] INFO:     Channel: T27 / Terrestrial: 27
[2024/09/01 16:34:37] INFO:     Recording duration: 10 seconds
[2024/09/01 16:34:38] INFO:     Decode: Enabled
[2024/09/01 16:34:38] ERROR:    Failed to initialize the decoder. (BCAS_CARD_ERROR_NO_SMART_CARD_READER)
[2024/09/01 16:34:38] INFO:     Disabling decoding and continue...
[2024/09/01 16:34:38] INFO:     Recording...

Mirakurun の設定とインストール
https://github.com/Chinachu/Mirakurun

# nodejsのインストールとmirakurunのインストール
$ curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
$ sudo apt-get install -y nodejs
$ sudo apt install build-essential
$ sudo npm install pm2 -g
$ sudo npm install mirakurun -g --unsafe-perm --foreground-scripts --production
$ curl http://127.0.0.1:40772/api/version
$ sudo mirakurun stop

# ISDBScanner でチャンネルスキャン
$ sudo wget https://github.com/tsukumijima/ISDBScanner/releases/download/v1.1.6/isdb-scanner -O /usr/local/bin/isdb-scanner
$ sudo chmod +x /usr/local/bin/isdb-scanner
$ isdb-scanner --exclude-pay-tv ./scanned/

# ISDBScanner でチャンネルスキャンしたデータをmirakurunにコピー
$ sudo cp -a scanned/Mirakurun/channels.yml /usr/local/etc/mirakurun/channels.yml
$ sudo cp -a scanned/Mirakurun/tuners.yml /usr/local/etc/mirakurun/tuners.yml
$ sudo chown -R root /usr/local/etc/mirakurun/
$ sudo mirakurun start

chinachu のインストール
https://github.com/Chinachu/Chinachu/wiki/Gamma-Installation-V2 この辺を見ながら

$ git clone https://github.com/Chinachu/Chinachu.git ~/chinachu
$ cd ~/chinachu/
$ ./chinachu installer


# pythonの古い文法が使われててエラーが出るので修正
$ vim ~/chinachu/.nave/installed/14.18.3/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py
# 234行目の Ur を r に変更する
234       build_file_contents = open(build_file_path, 'Ur').read()
# 変更後
234       build_file_contents = open(build_file_path, 'r').read()


$ cp config.sample.json config.json
$ vim config.json
$ echo [] > rules.json
$ ./chinachu service wui execute
$ ./chinachu update
$ sudo pm2 start processes.json
$ sudo pm2 save
$ sudo pm2 startup