Ubuntu22.04とPX-MLT5PEとchinachuで録画サーバーを作る

環境

$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
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=jammy
$ uname -a
Linux rec07 5.15.0-48-generic #54-Ubuntu SMP Fri Aug 26 13:26:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

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

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

#タイムゾーンの設定
$ timedatectl
               Local time: Sun 2022-09-25 00:09:32 UTC
           Universal time: Sun 2022-09-25 00:09:32 UTC
                 RTC time: Sun 2022-09-25 00:09:32
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
$ timedatectl set-timezone Asia/Tokyo
$ timedatectl
               Local time: Sun 2022-09-25 09:10:15 JST
           Universal time: Sun 2022-09-25 00:10:15 UTC
                 RTC time: Sun 2022-09-25 00:10:15
                Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

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

$ sudo apt install -y unzip gcc make dkms
$ mkdir src
$ cd src/
$ 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
$ 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
$ lsmod | grep -e ^px4_drv
px4_drv               143360  0
$ reboot
$ ls -l /dev/pxmlt5video*
crw-rw-r-- 1 root video 234, 0 Sep 25 09:25 /dev/pxmlt5video0
crw-rw-r-- 1 root video 234, 1 Sep 25 09:25 /dev/pxmlt5video1
crw-rw-r-- 1 root video 234, 2 Sep 25 09:25 /dev/pxmlt5video2
crw-rw-r-- 1 root video 234, 3 Sep 25 09:25 /dev/pxmlt5video3
crw-rw-r-- 1 root video 234, 4 Sep 25 09:25 /dev/pxmlt5video4
crw-rw-r-- 1 root video 234, 5 Sep 25 09:25 /dev/pxmlt5video5
crw-rw-r-- 1 root video 234, 6 Sep 25 09:25 /dev/pxmlt5video6
crw-rw-r-- 1 root video 234, 7 Sep 25 09:25 /dev/pxmlt5video7
crw-rw-r-- 1 root video 234, 8 Sep 25 09:25 /dev/pxmlt5video8
crw-rw-r-- 1 root video 234, 9 Sep 25 09:25 /dev/pxmlt5video9

arib25ライブラリのインストール

$ sudo apt install -y cmake  build-essential libpcsclite-dev
$ cd ~/src/
$ git clone https://github.com/stz2012/libarib25.git
$ cd libarib25/
$ cmake .
$ make
$ sudo make install

recpt1のインストール
https://github.com/stz2012/recpt1 を参考に

$ sudo apt install -y autoconf automake
$ cd ~/src/
$ git clone https://github.com/stz2012/recpt1.git
$ cd recpt1/recpt1/
$ ./configure --enable-b25
$ make
$ sudo make install

autoconf automake が無いと下記の感じで怒られる

You must have autoconf installed to compile recpt1.
Get ftp://ftp.gnu.org/pub/gnu/autoconf/autoconf-2.62.tar.gz
(or a newer version if it is available)

You must have automake installed to compile recpt1.
Get ftp://ftp.gnu.org/pub/gnu/automake/automake-1.10.1.tar.gz
(or a newer version if it is available)

録画の確認
エラーが出たら上の手順をやり直す

$ recpt1 --device /dev/pxmlt5video1 --b25 --strip --sid hd 27 10 ~/test.ts
using device: /dev/pxmlt5video1
using B25...
enable B25 strip
pid = 3942
device = /dev/pxmlt5video1
C/N = 26.500628dB
Recording...
Available sid = 1024 1025 1408 65520 
Chosen sid    = 1024
Available PMT = 0x1f0 0x3f0 0x1fc8 0x1cf0 
Recorded 10sec

Mirakurunのインストール
この辺を見ながらインストール

$ curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
$ sudo apt-get install -y nodejs pkg-config

# 公式だとsudo /path/to/nave.sh usemain 16 って書いてあるけどよくわからない…
$ sudo npm install -g nave
$ nave usemain 16
$ sudo apt install build-essential
$ sudo npm install pm2 -g
$ sudo npm install mirakurun -g --unsafe-perm --foreground-scripts --production
$ sudo npm install arib-b25-stream-test -g --unsafe
$ sudo mirakurun config tuners # 下のテキストっぽく修正
$ sudo mirakurun restart

sudo mirakurun config tuners

- name: PX-MLT5PE0
  types:
    - GR
  command: /usr/local/bin/recpt1 --device /dev/pxmlt5video0 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: false
- name: PX-MLT5PE1
  types:
    - GR
  command: /usr/local/bin/recpt1 --device /dev/pxmlt5video1 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: false
- name: PX-MLT5PE2
  types:
    - GR
  command: /usr/local/bin/recpt1 --device /dev/pxmlt5video2 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: false
- name: PX-MLT5PE3
  types:
    - GR
  command: /usr/local/bin/recpt1 --device /dev/pxmlt5video3 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: false
- name: PX-MLT5PE4
  types:
    - GR
  command: /usr/local/bin/recpt1 --device /dev/pxmlt5video4 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: false
- name: PX-MLT5PE5
  types:
    - GR
  command: /usr/local/bin/recpt1 --device /dev/pxmlt5video5 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: false
- name: PX-MLT5PE6
  types:
    - GR
  command: /usr/local/bin/recpt1 --device /dev/pxmlt5video6 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: false
- name: PX-MLT5PE7
  types:
    - GR
  command: /usr/local/bin/recpt1 --device /dev/pxmlt5video7 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: false
- name: PX-MLT5PE8
  types:
    - GR
  command: /usr/local/bin/recpt1 --device /dev/pxmlt5video8 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: false
- name: PX-MLT5PE9
  types:
    - GR
  command: /usr/local/bin/recpt1 --device /dev/pxmlt5video9 <channel> - -
  decoder: arib-b25-stream-test
  isDisabled: false

チャンネルスキャン

sekki@rec07:~$ curl -X PUT "http://localhost:40772/api/config/channels/scan"
channel scanning... (type: "GR")

-> new 3 channels found.
-> existing 8 channels merged.
-> total 11/34 (GR/Any) channels configured.
(snip...)
channel scan has been completed and saved successfully.
**RESTART REQUIRED** to apply changes.

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

$ git clone https://github.com/Chinachu/Chinachu.git ~/chinachu
$ cd ~/chinachu/
$ ./chinachu installer
Chinachu Installer Menu:
[!] These are installed under all /home/rec/chinachu/...
[!] Recommend the Auto installation.
1) Auto (full)
2) submodule
3) Node.js Environment
4) Node.js Modules
5) ffmpeg
what do you install? > 1

$ 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

諸々終わったらchinachuにアクセスして確認
http://chinachu:20772/