created: 2022-08-05T01:57:33.437Z

2022年度版 RaspberryPi4で録画サーバ(Mirakurun/EPGStation)を動かす

参考にしたもの

録画サーバアプリの実装はここからセットアップさせてもらった。

ハードウェアのドライバとかを入れる手順はこの記事を参考にした。買っている機材も同じ。

このへんも拾い読みさせていただいた。

ありがとうございました。

チューナーのドライバの確認

これ用のドライバを入れて認識されるか確認しておく。

# [How can I permanently fix /dev/vchiq permission errors? - Raspberry Pi Stack Exchange](https://raspberrypi.stackexchange.com/questions/19436/how-can-i-permanently-fix-dev-vchiq-permission-errors)
echo 'SUBSYSTEM=="vchiq",GROUP="video",MODE="0666"' | sudo tee /etc/udev/rules.d/10-vchiq-permissions.rules
# v1.0.1が最新。2017年から更新されてない
wget http://plex-net.co.jp/plex/px-s1ud/PX-S1UD_driver_Ver.1.0.1.zip
unzip PX-S1UD_driver_Ver.1.0.1.zip
sudo cp PX-S1UD_driver_Ver.1.0.1/x64/amd64/isdbt_rio.inp /lib/firmware/
sudo reboot

認識されてるか確認

$ dmesg | grep PX-S1UD
[    2.584290] usb 1-1.3: Product: PX-S1UD Digital TV Tuner

カードリーダのドライバの確認

これ用のドライバを入れてちゃんと動くか確認する。

ちなみにデバイスファイルはコンテナの中から読みだすので、ここでパッケージ色々入れてもこのバイナリは本番では使わない。

$ sudo apt install -y pcscd libpcsclite-dev libccid pcsc-tools
$ sudo pcsc_scan

自分の場合はここでハマった。こんなメッセージが出る。

Card state: Card inserted, Unresponsive card,

原因は単純なやつでB-CASカードの差し込みが裏表逆だったから。表にして挿し直したらうまくいった。

認識されてるか確認

Japanese Chijou Digital B-CAS Card (pay TV)

と出ればいいらしい。

$ sudo pcsc_scan
Using reader plug'n play mechanism
Scanning present readers...

Thu Aug  4 19:45:09 2022
  Event number: 2
  Card state: Card inserted,

...(中略)...

Possibly identified card (using /usr/share/pcsc/smartcard_list.txt):
	Japanese Chijou Digital B-CAS Card (pay TV)

OK。ほっといたらずっとスキャンしてるので適当なところで止める。

Docker上でアプリを動かす準備

docker-compose.yml を拝借して録画管理アプリ(EPGStation)を動かそうとしているので、Docker環境を用意する。

$ curl -sSL https://get.docker.com/ | CHANNEL=stable sh

docker compose も入れないとと思ってたらすでに入っていた。今はそうらしい。

$ sudo apt-get install docker-compose-plugin
...
docker-compose-plugin is already the newest version (2.6.0~raspbian-bullseye).

アプリのセットアップ

ここで公開されている setup.sh と docker-compose.yml を使う。

docker compose run でもセットアップ用とアプリ実行用で切り替わるようになっていて、先に前者を叩いている。 setup.sh が docker-compose コマンドに依存しててコケるので、最後のコマンドだけやりなおし。

$ curl -sf "https://raw.githubusercontent.com/l3tnun/docker-mirakurun-epgstation/v2/setup.sh" | sh -s
$ cd docker-mirakurun-epgstation
$ sudo docker compose run --rm -e SETUP=true mirakurun

/app-data/programs.json is not exists とか出てオオッてなるが setup is done と出るのでなんとなくうまくいってそう。 あとから見たら、programs.json は起動後に用意する番組表情報のデータだった。番組表はもちろん動的なデータなのでなくても問題ない。

2022-08-05T09:55:26.740+09:00 info: setup is done.

セットアップ用の docker compose の出力はこんな感じ。

$ sudo docker compose run --rm -e SETUP=true mirakurun
[+] Running 2/1Network docker-mirakurun-epgstation_default    Created                                                        0.2s
 ⠿ Volume "docker-mirakurun-epgstation_mysql-db"  Created                                                        0.0s
[+] Running 9/9
 ⠿ mirakurun Pulled                                                                                             76.7s
   ⠿ 1acfd43b1a25 Pull complete                                                                                 14.1s
   ⠿ a6fcfc4ea2c3 Pull complete                                                                                 14.5s
   ⠿ efb930494c57 Pull complete                                                                                 25.1s
   ⠿ 429b139202a5 Pull complete                                                                                 25.6s
   ⠿ 106f052342c2 Pull complete                                                                                 25.9s
   ⠿ ee3c67a22b21 Pull complete                                                                                 26.1s
   ⠿ 5b9e3a3df52f Pull complete                                                                                 44.5s
   ⠿ 9c6a43c7c507 Pull complete                                                                                 71.9s
^[[Bmkdir: created directory '/opt/bin'

added 1 package, and audited 2 packages in 6s

found 0 vulnerabilities
npm notice
npm notice New minor version of npm available! 8.3.1 -> 8.16.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.16.0
npm notice Run npm install -g npm@8.16.0 to update!
npm notice
'/opt/bin/arib-b25-stream-test' -> '/opt/node_modules/arib-b25-stream-test/bin/b25'
starting pcscd...
Using reader plug'n play mechanism
Scanning present readers...

Fri Aug  5 09:55:22 2022
  Event number: 0
  Card state: Card inserted,

+ TS = 3B --> Direct Convention
+ T0 = F0, Y(1): 1111, K: 0 (historical bytes)
  TA(1) = 12 --> Fi=372, Di=2, 186 cycles/ETU
    21505 bits/s at 4 MHz, fMax for Fi = 5 MHz => 26881 bits/s
  TB(1) = 00 --> VPP is not electrically connected
  TC(1) = FF --> Extra guard time: 255 (special value)
  TD(1) = 91 --> Y(i+1) = 1001, Protocol T = 1
-----
  TA(2) = 81 --> Protocol to be used in spec mode: T=1 - Unable to change - defined by interface bytes
  TD(2) = B1 --> Y(i+1) = 1011, Protocol T = 1
-----
  TA(3) = 7C --> IFSC: 124
  TB(3) = 45 --> Block Waiting Integer: 4 - Character Waiting Integer: 5
  TD(3) = 1F --> Y(i+1) = 0001, Protocol T = 15 - Global interface bytes following
-----
  TA(4) = 03 --> Clock stop: not supported - Class accepted by the card: (3G) A 5V B 3V
+ Historical bytes:
+ TCK = 99 (correct checksum)

Possibly identified card (using /usr/share/pcsc/smartcard_list.txt):
	Japanese Chijou Digital B-CAS Card (pay TV)

 -
2022-08-05T09:55:25.571+09:00 info: missing server config `/app-config/server.yml`
2022-08-05T09:55:25.575+09:00 info: copying default server config to `/app-config/server.yml`
2022-08-05T09:55:25.577+09:00 info: load server config `/app-config/server.yml`
2022-08-05T09:55:25.579+09:00 info: load server config (merged w/ env): {"logLevel":2,"path":"/var/run/mirakurun.sock","port":40772,"allowIPv4CidrRanges":["10.0.0.0/8","127.0.0.0/8","172.16.0.0/12","192.168.0.0/16"],"allowIPv6CidrRanges":["fc00::/7"],"disableIPv6":true,"hostname":"fc6c28d31e26"}
2022-08-05T09:55:25.602+09:00 info: missing channels config `/app-config/channels.yml`
2022-08-05T09:55:25.603+09:00 info: copying default channels config to `/app-config/channels.yml`
2022-08-05T09:55:25.604+09:00 info: load channels config `/app-config/channels.yml`
2022-08-05T09:55:25.614+09:00 info: missing tuners config `/app-config/tuners.yml`
2022-08-05T09:55:25.615+09:00 info: trying to detect tuners...
2022-08-05T09:55:25.629+09:00 info: detected DVB device: adapter0
2022-08-05T09:55:26.691+09:00 info: added tuner config (generated): {"name":"adapter0","types":["GR"],"dvbDevicePath":"/dev/dvb/adapter0/dvr0","decoder":"arib-b25-stream-test","command":"dvbv5-zap -a 0 -c ./config/dvbconf-for-isdb/conf/dvbv5_channels_isdbt.conf -r -P <channel>"}
2022-08-05T09:55:26.692+09:00 info: detected 1 tuners!
2022-08-05T09:55:26.695+09:00 info: writing auto generated tuners config to `/app-config/tuners.yml`
2022-08-05T09:55:26.718+09:00 info: load tuners config `/app-config/tuners.yml`
2022-08-05T09:55:26.731+09:00 info: 1 of 1 tuners loaded
2022-08-05T09:55:26.738+09:00 info: load db `/app-data/services.json` w/ integrity (gPvjlTkut3OyJvE6sR+fN2QIFhs/Co1eSddkngzYj4g=)
2022-08-05T09:55:26.738+09:00 info: db `/app-data/services.json` is not exists
2022-08-05T09:55:26.739+09:00 info: load db `/app-data/programs.json` w/ integrity (gPvjlTkut3OyJvE6sR+fN2QIFhs/Co1eSddkngzYj4g=)
2022-08-05T09:55:26.739+09:00 info: db `/app-data/programs.json` is not exists
2022-08-05T09:55:26.740+09:00 info: setup is done.
stopping...
already killed.
exit.

チャンネルの設定

READMEにチャンネル設定をせよと書いてあるが、関東在住の場合はそのままでよさそうだった。

vim mirakurun/conf/channels.yml

mysqlのイメージ

arm用のmariadbがないので、つかうimageを切り替える。

$ sudo docker compose up -d
[+] Running 0/1
 ⠼ mysql Pulling                                                                                                 3.5s
no matching manifest for linux/arm/v7 in the manifest list entries

このリポジトリで Raspberry Pi 4 Model B (4GB)で利用できるようにした という差分が公開されているので拝借する。

yobasystems/alpine-mariadb:10.4.17-arm32v7 というイメージを使うように切り替える。

10:43:35-pi@raspberrypi:~/docker-mirakurun-epgstation git diff
diff --git a/docker-compose-sample.yml b/docker-compose-sample.yml
index 09767d4..fd2d7a5 100644
--- a/docker-compose-sample.yml
+++ b/docker-compose-sample.yml
@@ -24,7 +24,7 @@ services:
                 max-size: 10m

     mysql:
-        image: mariadb:10.5
+        image: yobasystems/alpine-mariadb:10.4.17-arm32v7
         # image: mysql:8.0 # 囲み文字を使用する場合
         volumes:
             - mysql-db:/var/lib/mysql

コメントされていた docker-compose.yml の変更はこんな感じにしておいた。

#コメントアウトされている restart や user の設定を適宜変更する

diff --git a/docker-compose-sample.yml b/docker-compose-sample.yml
index 09767d4..3479d87 100644
--- a/docker-compose-sample.yml
+++ b/docker-compose-sample.yml
@@ -60,9 +60,9 @@ services:
         ports:
             - "8888:8888"
             - "8889:8889"
-#         user: "1000:1000"
-#         devices:
-#             - /dev/dri:/dev/dri
+        user: "1000:1000"
+        devices:
+            - /dev/dri:/dev/dri
         restart: always

アプリ起動

docker-compose.yml とかが修正できたらアプリを立ち上げ。

$ sudo docker compose up -d

依存のインストールでけっこう時間がかかる(20分ほど)

終わったら動作しているか確認。

$ curl -I localhost:8888
HTTP/1.1 200 OK
X-Powered-By: Express
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Mon, 10 Jan 2022 10:14:34 GMT
ETag: W/"3a1-17e437b7f10"
Content-Type: text/html; charset=UTF-8
Content-Length: 929
Date: Fri, 05 Aug 2022 01:53:01 GMT
Connection: keep-alive
Keep-Alive: timeout=5
$ curl localhost:8888
<!DOCTYPE html><html lang="ja"><head><meta charset="utf-8"><link rel="manifest" href="./manifest.json" crossorigin="use-credentials"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="mobile-web-app-capable" content="yes"><meta name="theme-color" content="#3f51b5"><link rel="icon" href="./icon/favicon.png"><link rel="apple-touch-icon-precomposed" href="./icon/ios.png" sizes="180x180"><link rel="icon" href="./icon/android.png"><title>epgstation</title><link href="css/chunk-vendors.cc90f7b7.css" rel="stylesheet"><link href="css/app.d63fa559.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but clinet doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.f3cd2cb6.js"></script><script src="js/app.280916ae.js"></script></body></html>

OK

チャンネルのスキャン

Mirakurun にチャンネルをスキャンしてもらっておく必要があるらしい。

$ curl -X PUT "http://raspberrypi.local:40772/api/config/channels/scan"

その他

ハードウェアエンコーダが認識されてるかを確認

10:10:41-pi@raspberrypi:~/docker-mirakurun-epgstation ffmpeg -encoders 2>&1 | grep h264_omx
 V..... h264_omx             OpenMAX IL H.264 video encoder (codec h264)

設定のマニュアルが

ものすごい丁寧に書かれていて素晴らしい。

docker-compose コマンド

参考にしている docker-compose.yml が docker-compose コマンドに依存しているので自分で入れたい場合は入れる。

お金のむこうに人がいる 元ゴールドマン・サックス金利トレーダーが書いた 予備知識のいらない経済新入門
[ad] お金のむこうに人がいる 元ゴールドマン・サックス金利トレーダーが書いた 予備知識のいらない経済新入門
田内学 (単行本(ソフトカバー))