ゼロから始めるlinux録画鯖の書

Chinachu
スポンサーリンク

記念すべきブログ一発目のネタです。よろしくお願いします。
自分はLinuxのテキストエディタはnano派なのでテキストエディタのコマンドはnanoで書いています。
vimやviユーザーの方はお手数ですがnanoのところを打ち直してください。スイマセン
このページでは、2017年6月現在でのPT3でMirakurunとChinachu Gammmaでの録画サーバー構築方法を書いています。

それぞれのツールが更新されて挙動が変わるかもしれませんがあしからず。

この記事で紹介しているものは2017年のもので古いのでこれから録画サーバーを構築する場合は2019年版を参考にしてください。

参考にしたサイト

https://github.com/Chinachu/Chinachu/wiki/Gamma-Installation-V2
(Chinachu公式) https://github.com/Chinachu/Mirakurun
(Mirakurun公式) https://www.jifu-labo.net/2017/01/chinachu_gd
https://blog.sugtao4423.xyz/?p=700

 

どうしたの

最近身近でCorei5-4440のPCが余っていたので、今や生産終了したPT3を乗っけて録画鯖を建て直したので、そのメモです。
Chinachu開発者様や各種ツール製作者様のお陰で、簡単に録画サーバーができるようになっていて、製作者様方には本当に頭があがりません。

必要なもの

・PT3などのlinuxドライバのあるチューナー(今はPT3が生産終了で値上がりしているので新しく買う人はヤフオク等で)

PT3 Rev.A
アースソフト
¥63,800(2024/04/19 14:18時点)
アースソフト PT2
アースソフト
¥14,199(2024/04/20 01:21時点)
※地上波だけなら別のチューナーだけど4,000円くらいで買えます。↓
最近では、さんぱくんっていうPCチューナー(これもなかなか手に入りませんが、在庫があれば7,000円)なら有志のドライバとツールでBS/地上波が使えます(別記事で紹介)。

・カードリーダー(↓我が家はLinux系での稼働実績の高いこれです)

・B-CASカード(レコーダー等から流用でOK)

・そこそこ容量の大きいHDD(当方はOS用のHDDとは別に2TBのHDD使用)
※別のHDDを設定する方法は各自調べてください。

・Corei3以上の性能のあるCPUをもったPC(以前core2duoでやってて結構順調でしたが、突然安定しなくなったりするのでこのぐらいのCPUは必要かと)

Step1 OS導入

自分はUbuntuDesktopで比較的なれていたのでOSはServer版のUbuntuで挑戦してみました。
やり方は執筆時最新のUbuntu16.04のServerを公式サイトからダウンロードしてUSBかDVDに焼いてインストールするだけです。
他のサイト等でも紹介されているのでインストール方法は割愛します。(SSHを設定していると便利です)

Step2 必要パッケージのインストール

Chinachu+Mirakurun+他関連ツールならこのくらいで足りると思います。
もしエラーが出たら、それに対応してaptでインストールって感じで対応してください。

$ sudo apt -y install autoconf build-essential cmake curl git-core libssl-dev libtool libboost-all-dev pkg-config yasm

 

Step3 カードリーダー用ドライバをインストール

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

 

ここでJapanese Chijou Digital B-CAS Card (pay TV)と出ればOKです。
このコマンドは自動で終了しないのでCtrl+C で抜けます。

Step4 PT3ドライバ(チューナードライバ)をインストール

一応カーネル標準ドライバも試したのですが、何故かBSプレミアムが受信できないってのがあったので、PT3に関しては別途インストールした方が信頼性が高いと思います。

$ mkdir chinachu
$ cd chinachu
$ git clone https://github.com/m-tsudo/pt3.git
$ cd pt3 $make
$ sudo make install
$ sudo apt install dkms
$ sudo bash ./dkms.install 

 

カーネル標準ドライバと競合するので標準ドライバをブラックリストにする

$ sudo nano /etc/modprobe.d/blacklist.conf

 

一番下の行にblacklist earth-pt3と追記
最後に録画サーバを再起動して終了。

$ sudo reboot

 

再起動後、ドライバモジュールがロードされているかを確認。

$ lsmod | grep pt3

 

pt3_drvのような表示があればOK

Step5 暗号化解除用arib25ライブラリのインストール

$ cd ../
$ git clone https://github.com/stz2012/libarib25.git
$ cd libarib25
$ cmake .
$ make
$ sudo make install

 

Step6 録画コマンドソフトrecpt1のインストール

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

 

Step7 チューナー管理Mirakurunの前提ソフトであるnodeのインストール

Ubuntu等のOSのパッケージだとnodeやnpmのバージョンが古いのでnパッケージを入れて
そこから最新のnodeやnpmを入れていく形になります。最新になれば、古いパッケージは不要で混乱するため消す感じです。
ただ、nodeの奇数バージョンは不安定らしいので、最新が奇数バージョンの時は一つ前のバージョンを入れたほうがいいようです。ChinachuのWikiによると、通常環境における偶数バージョンの利用は Node.js 公式でも推奨されているようです。

$ sudo apt install npm
$ sudo npm cache clean
$ sudo npm install n -g
$ sudo n stable
$ sudo ln -sf /usr/local/bin/node /usr/bin/node
$ sudo apt purge -y nodejs npm

 

参考:http://qiita.com/seibe/items/36cef7df85fe2cefa3ea

バージョン確認は

$ node -v
v8.2.1
$ npm -v
5.3.0

 

という感じです。
因みにnpmが5.xや、nodeが7.x等(不安定版)がインストールされてバージョンを下げたい場合は

$ sudo npm i -g npm@4
$ sudo n 6.*

 

という感じです。
この場合npmは4.x、nodeは6.xになります。

Step8 Mirakurunの導入

MirakurunはChinachuのチューナー部分の管理ソフトです。
このソフトは録画が無い時に自動でEPGを取ってくれたりします。
他にもBonDriver_Mirakurunを使えばwindowsのDTVでは定番のTVtestでの視聴がローカルLan内で可能になったりする優れものです。

$ sudo npm install pm2 -g --no-optional
$ sudo npm install mirakurun -g --unsafe --production --no-optional
$ sudo npm install arib-b25-stream-test -g --unsafe --no-optional

 

設定

$ sudo EDITOR=nano mirakurun config {server|tuners|channels} 

 

server設定はデフォルトでいいと思いますが、tuners、channelsはチューナー、地域に合わせて変更する必要があります。
PT3の時は下記のような感じです。具体的にはPT3の設定は最初から書いてあるのでisDisabled: trueisDisabled: falseとすれば使うことができます。
※最初に紹介したさんぱくんの設定は別記事で紹介します。

$ sudo EDITOR=nano mirakurun config tuners
- name: PT3-S1
types:
- BS
- CS
command: recpt1 --device /dev/pt3video0 <channel> - -
decoder: arib-b25-stream-test
isDisabled: false

- name: PT3-S2
types:
- BS
- CS
command: recpt1 --device /dev/pt3video1 <channel> - -
decoder: arib-b25-stream-test
isDisabled: false

- name: PT3-T1
types:
- GR
command: recpt1 --device /dev/pt3video2 <channel> - -
decoder: arib-b25-stream-test
isDisabled: false

- name: PT3-T2
types:
- GR
command: recpt1 --device /dev/pt3video3 <channel> - -
decoder: arib-b25-stream-test
isDisabled: false

 

channelsの設定で地上波は

$ curl -X PUT "http://localhost:40772/api/config/channels/scan"

 

で自動登録できます。BS・CSのチャンネル設定は手動でしか出来ませんが全国均一なので一番下に書いておきます。
一通り設定が終わったら

$ sudo mirakurun restart

 

でmirakurunを再起動しましょう。

Step9 録画予約管理のChinachuの導入

ようやくメインとなるChinachuのインストールです。chinachuはインストーラーが非常によく出来ているのでインストールも対話的にできるので、かなり楽です。

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

 

初回は1“Auto (full)”を選択します。

コンフィグファイルやルールファイルの作成

$ cp config.sample.json config.json

 

空のルール設定ファイルを作成

$ echo [] > rules.json

 

動作確認

$ ./chinachu service wui execute

 

ここで、SSHや、プロンプトを開いたままブラウザでhttp://[サーバーIP]:20772でアクセス可能なことを確認してください。
問題なく起動できたらCtrl+\で終了
続いてEPG取得テスト

$ ./chinachu update

 

ここでうまくいかない場合は恐らく Mirakurun に接続できていないようです。
うまくいかない場合はmirakurunのログシステムsudo mirakurun log server等でエラーを確認してください。

スクリプト(サービスとして)登録

自分はpm2でchinachuを管理するよりサービスで管理するほうが好きなので今回はサービス(というよりサービスでなれたから)として登録しますが、chinachuの公式wikiではpm2での自動起動を紹介しています。
ここでは混乱回避のためpm2での設定は書かないことにします(-_-)
※以前pm2とサービスの両方を設定して多重起動になって録画ファイルがおかしな事になってしまったので、気をつけましょう。(そんな変な人は自分くらい?)

$ ./chinachu service operator initscript > /tmp/chinachu-operator
$ ./chinachu service wui initscript > /tmp/chinachu-wui
$ sudo chown root:root /tmp/chinachu-operator /tmp/chinachu-wui
$ sudo chmod +x /tmp/chinachu-operator /tmp/chinachu-wui
$ sudo mv /tmp/chinachu-operator /tmp/chinachu-wui /etc/init.d/
$ sudo systemctl enable chinachu-operator
$ sudo systemctl enable chinachu-wui

 

ここまで設定すると起動時に自動でchinachuのwui、operatorを起動してくれます。
因みにサービスとして設定した場合の手動起動や手動再起動等は下記の通りです

#起動
$ sudo service chinachu-operator start
$ sudo service chinachu-wui start
#再起動
$ sudo service chinachu-operator restart
$ sudo service chinachu-wui restart
#終了
$ sudo service chinachu-operator stop
$ sudo service chinachu-wui stop

 

おまけ(設定ファイル)

起動が完了したらブラウザからChinachuトップの右上にある設定で設定をしましょう。JSONフォーマットのケツカンマは何度も悩みました。

このサイトで文法チェックをしてくれるようなので、文法チェックしながら設定しましょう。http://jsonlint.com/
ちなみに自分の設定は下記の通りです。

[wpex more=”クリックで展開” less=”▼ クリックで閉じる”]
 {
"uid": "[Ubuntuのユーザー名]",
"gid": "video",
"mirakurunPath": "http+unix://%2Fvar%2Frun%2Fmirakurun.sock/",
"recordedDir" : "./recorded/",
"vaapiEnabled": false,
"vaapiDevice": "/dev/dri/renderD128",

"wuiUsers": [
"chinachu:yoshikawa"
],
"wuiAllowCountries": ["JP"],
"wuiPort": null,
"wuiHost": "0.0.0.0",
"wuiTlsKeyPath": null,
"wuiTlsCertPath": null,
"wuiTlsRequestCert": false,
"wuiTlsRejectUnauthorized": true,
"wuiTlsCaPath": null,
"wuiOpenServer": true,
"wuiOpenPort": 20772,
"wuiXFF": false,
"wuiDLNAServerEnabled": false,
"wuiMdnsAdvertisement": true, "recordedFormat": "<date:yymmddHHMM>_<title>_<channel-name>.ts",
"storageLowSpaceThresholdMB": 3000,
"storageLowSpaceAction": "remove",
"storageLowSpaceNotifyTo": null,
"storageLowSpaceCommand": ""
}
[/wpex]

そしてMirakurunのBS・CSのチャンネル設定
[wpex more=”クリックで展開” less=”▼ クリックで閉じる”]

 {

- name: NHK BS1
type: BS
channel: BS15_0
serviceId: 101

- name: NHK BS1 (サブ)
type: BS
channel: BS15_0
serviceId: 102

- name: NHK BSプレミアム
type: BS
channel: BS15_1
serviceId: 103

- name: NHK BSプレミアム (サブ)
type: BS
channel: BS15_1
serviceId: 104

- name: BS日テレ
type: BS
channel: BS13_0
serviceId: 141

- name: BS日テレ (サブ)
type: BS
channel: BS13_0
serviceId: 142

- name: BS朝日
type: BS
channel: BS01_0
serviceId: 151

- name: BS朝日 (サブ)
type: BS
channel: BS01_0
serviceId: 152

- name: BS-TBS
type: BS
channel: BS01_1
serviceId: 161

- name: BSジャパン
type: BS
channel: BS03_1
serviceId: 171

- name: BSフジ
type: BS
channel: BS13_1
serviceId: 181

- name: WOWOWプライム
type: BS
channel: BS03_0
serviceId: 191
isDisabled: flse

- name: WOWOWライブ
type: BS
channel: BS05_0
serviceId: 192
isDisabled: flse

- name: WOWOWシネマ
type: BS
channel: BS05_1
serviceId: 193
isDisabled: flse

- name: スター・チャンネル1
type: BS
channel: BS09_1
serviceId: 200
isDisabled: flse

- name: スター・チャンネル2
type: BS
channel: BS07_0
serviceId: 201
isDisabled: flse

- name: スター・チャンネル3
type: BS
channel: BS07_0
serviceId: 202
isDisabled: flse

- name: BS11
type: BS
channel: BS09_0
serviceId: 211

- name: TwellV
type: BS
channel: BS09_2
serviceId: 222

- name: 放送大学BS1
type: BS
channel: BS11_2
serviceId: 231

- name: 放送大学BS2
type: BS
channel: BS11_2
serviceId: 232

- name: 放送大学BS3
type: BS
channel: BS11_2
serviceId: 233

- name: グリーンチャンネル
type: BS
channel: BS19_0
serviceId: 234
isDisabled: flse

- name: BSアニマックス
type: BS
channel: BS07_1
serviceId: 236
isDisabled: flse

- name: FOXスポーツ&エンターテイメント
type: BS
channel: BS11_0
serviceId: 238
isDisabled: flse

- name: BSスカパー!
type: BS
channel: BS11_1
serviceId: 241
isDisabled: flse

- name: J SPORTS 1
type: BS
channel: BS19_1
serviceId: 242
isDisabled: flse

- name: J SPORTS 2
type: BS
channel: BS19_2
serviceId: 243
isDisabled: flse

- name: J SPORTS 3
type: BS
channel: BS21_1
serviceId: 244
isDisabled: flse

- name: J SPORTS 4
type: BS
channel: BS21_2
serviceId: 245
isDisabled: flse

- name: BS釣りビジョン
type: BS
channel: BS23_0
serviceId: 251
isDisabled: flse

- name: イマジカBS・映画
type: BS
channel: BS21_0
serviceId: 252
isDisabled: flse

- name: 日本映画専門チャンネル
type: BS
channel: BS23_1
serviceId: 255
isDisabled: flse

- name: ディズニー・チャンネル
type: BS
channel: BS07_2
serviceId: 256
isDisabled: flse

- name: D-Life
type: BS
channel: BS23_2
serviceId: 258
isDisabled: flse

- name: ショップチャンネル
type: CS
channel: CS8
serviceId: 55

- name: スカパー!プロモ
type: CS
channel: CS4
serviceId: 100

- name: QVC
type: CS
channel: CS2
serviceId: 161

- name: 東映チャンネル
type: CS
channel: CS8
serviceId: 218
isDisabled: flse

- name: 衛星劇場
type: CS
channel: CS8
serviceId: 219
isDisabled: flse

- name: チャンネルNECO
type: CS
channel: CS4
serviceId: 223
isDisabled: flse

- name: ザ・シネマ
type: CS
channel: CS4
serviceId: 227
isDisabled: flse

- name: FOXムービー
type: CS
channel: CS24
serviceId: 229
isDisabled: flse

- name: ムービープラスHD
type: CS
channel: CS18
serviceId: 240
isDisabled: flse

- name: sky・Aスポーツ+
type: CS
channel: CS4
serviceId: 250
isDisabled: flse

- name: GAORA
type: CS
channel: CS12
serviceId: 254
isDisabled: flse

- name: 日テレG+ HD
type: CS
channel: CS24
serviceId: 257
isDisabled: flse

- name: ゴルフネットHD
type: CS
channel: CS18
serviceId: 262
isDisabled: flse

- name: SKY STAGE
type: CS
channel: CS16
serviceId: 290
isDisabled: flse

- name: 時代劇専門chHD
type: CS
channel: CS14
serviceId: 292
isDisabled: flse

- name: ファミリー劇場HD
type: CS
channel: CS14
serviceId: 293
isDisabled: flse

- name: ホームドラマCH
type: CS
channel: CS6
serviceId: 294
isDisabled: flse

- name: TBSチャンネル1
type: CS
channel: CS2
serviceId: 296
isDisabled: flse

- name: TBSチャンネル2
type: CS
channel: CS22
serviceId: 297
isDisabled: flse

- name: テレ朝チャンネル1
type: CS
channel: CS2
serviceId: 298
isDisabled: flse

- name: テレ朝チャンネル2
type: CS
channel: CS2
serviceId: 299
isDisabled: flse

- name: 日テレプラス
type: CS
channel: CS24
serviceId: 300
isDisabled: flse

- name: チャンネル銀河
type: CS
channel: CS16
serviceId: 305
isDisabled: flse

- name: フジテレビONE
type: CS
channel: CS20
serviceId: 307
isDisabled: flse

- name: フジテレビTWO
type: CS
channel: CS20
serviceId: 308
isDisabled: flse

- name: フジテレビNEXT
type: CS
channel: CS20
serviceId: 309
isDisabled: flse

- name: スーパー!ドラマHD
type: CS
channel: CS14
serviceId: 310
isDisabled: flse

- name: AXN
type: CS
channel: CS16
serviceId: 311
isDisabled: flse

- name: FOX
type: CS
channel: CS22
serviceId: 312
isDisabled: flse

- name: 女性ch/LaLa
type: CS
channel: CS18
serviceId: 314
isDisabled: flse

- name: スペシャプラス
type: CS
channel: CS24
serviceId: 321
isDisabled: flse

- name: スペースシャワーTV
type: CS
channel: CS22
serviceId: 322
isDisabled: flse

- name: MTV HD
type: CS
channel: CS6
serviceId: 323
isDisabled: flse

- name: エムオン!HD
type: CS
channel: CS12
serviceId: 325
isDisabled: flse

- name: ミュージック・エア
type: CS
channel: CS8
serviceId: 326
isDisabled: flse

- name: 歌謡ポップス
type: CS
channel: CS6
serviceId: 329
isDisabled: flse

- name: キッズステーション
type: CS
channel: CS12
serviceId: 330
isDisabled: flse

- name: カートゥーン
type: CS
channel: CS22
serviceId: 331
isDisabled: flse

- name: AT-X
type: CS
channel: CS16
serviceId: 333
isDisabled: flse

- name: ディズニージュニア
type: CS
channel: CS8
serviceId: 339
isDisabled: flse

- name: ディスカバリー
type: CS
channel: CS6
serviceId: 340
isDisabled: flse

- name: アニマルプラネット
type: CS
channel: CS6
serviceId: 341
isDisabled: flse

- name: ヒストリーチャンネル
type: CS
channel: CS4
serviceId: 342
isDisabled: flse

- name: ナショジオチャンネル
type: CS
channel: CS16
serviceId: 343
isDisabled: flse

- name: 日テレNEWS24
type: CS
channel: CS8
serviceId: 349
isDisabled: flse

- name: TBSニュースバード
type: CS
channel: CS22
serviceId: 351
isDisabled: flse

- name: BBCワールド
type: CS
channel: CS16
serviceId: 353
isDisabled: flse

- name: CNNj
type: CS
channel: CS6
serviceId: 354
isDisabled: flse

- name: 旅チャンネル
type: CS
channel: CS24
serviceId: 362
isDisabled: flse

- name: 囲碁・将棋チャンネル
type: CS
channel: CS4
serviceId: 363
isDisabled: flse

- name: スカチャン0
type: CS
channel: CS10
serviceId: 800
isDisabled: flse

- name: スカチャン1
type: CS
channel: CS10
serviceId: 801
isDisabled: flse

- name: スカチャン2
type: CS
channel: CS10
serviceId: 802
isDisabled: flse

- name: スカチャン3
type: CS
channel: CS10
serviceId: 805
isDisabled: flse

 

[/wpex]

あとがき

頻繁に更新されるChinachuは日に日に便利になって、次期大型アップデートChinachuAirが楽しみです。
ではまた。

Amazon検索
Chinachu
シェアする
Till0196をフォローする

コメント