Skip to content

Instantly share code, notes, and snippets.

@kuniiskywalker
Last active December 11, 2023 17:45
Show Gist options
  • Save kuniiskywalker/57ae57c49b04e17995187fd1333c8309 to your computer and use it in GitHub Desktop.
Save kuniiskywalker/57ae57c49b04e17995187fd1333c8309 to your computer and use it in GitHub Desktop.
Raspberry Pi 4 Model BにmirakurunをインストールしてVNCで視聴

Raspberry Pi 4 Model BにmirakurunをインストールしてVNCで視聴

前提

  • Raspberry Pi 4 Model B
  • PLEX PX-Q1UD
  • B-CAS Card
  • B-CAS CARD Reader
  • micro SD
  • Geekworm Raspberry Pi(冷却用アーマーケース)

OS

Raspberry Pi OS Lite(32-bit)

Install

wifi使わないから無効

sudo iwconfig wlan0 txpower off

IP固定

編集

pi@raspberrypi:~ $ sudo vi /etc/dhcpcd.conf

環境に合わせて設定

interface eth0
static ip_address=192.168.0.37/24
static routers=192.168.0.1
static domain_name_servers=8.8.8.8

再起動

sudo reboot

SSH有効化

pi@raspberrypi:~ $ touch /boot/ssh

以降はssh接続で

ソフトウェア更新

pi@raspberrypi:~ $ sudo timedatectl set-timezone 'Asia/Tokyo'
pi@raspberrypi:~ $ sudo apt update && sudo apt upgrade -y && sudo apt install locales-all
pi@raspberrypi:~ $ sudo localectl set-locale 'LANG=ja_JP.UTF-8'
pi@raspberrypi:~ $ export LC_ALL=en_US.UTF-8

スワップの無効化

pi@raspberrypi:~ $ sudo swapoff --all
pi@raspberrypi:~ $ sudo systemctl stop dphys-swapfile.service
pi@raspberrypi:~ $ sudo systemctl disable dphys-swapfile.service
pi@raspberrypi:~ $ systemctl status dphys-swapfile.service

チューナーの準備

PLEX PX-Q1UDのドライバーインストール

pi@raspberrypi:~ $ wget http://plex-net.co.jp/plex/px-s1ud/PX-S1UD_driver_Ver.1.0.1.zip
pi@raspberrypi:~ $ unzip PX-S1UD_driver_Ver.1.0.1.zip
pi@raspberrypi:~ $ sudo cp PX-S1UD_driver_Ver.1.0.1/x64/amd64/isdbt_rio.inp /lib/firmware

再起動して dmesg を実行すると PX-S1UD Digital TV Tuner が 4 つ見える

pi@raspberrypi:~ $ sudo reboot
pi@raspberrypi:~ $ dmesg | grep PX-S1UD
[    3.016040] usb 1-1.4.1: Product: PX-S1UD Digital TV Tuner
[    3.246042] usb 1-1.4.2: Product: PX-S1UD Digital TV Tuner
[    3.476047] usb 1-1.4.3: Product: PX-S1UD Digital TV Tuner
[    3.715967] usb 1-1.4.4: Product: PX-S1UD Digital TV Tuner

カードリーダーの準備

pi@raspberrypi:~ $ sudo apt install build-essential pcscd libpcsclite-dev libccid pcsc-tools

B-CAS カードを読み取れているかを確認する.

pi@raspberrypi:~ $ sudo pcsc_scan

Japanese Chijou Digital B-CAS Card (pay TV) みたいなのが出てれば OK.

録画用コマンドをインストール

pi@raspberrypi:~ $ sudo apt install dvb-tools

pi@raspberrypi:~ $ cd /usr/local
pi@raspberrypi:~ $ sudo mkdir conf
pi@raspberrypi:~ $ cd conf
pi@raspberrypi:~ $ sudo curl -O https://raw.githubusercontent.com/Chinachu/dvbconf-for-isdb/master/conf/dvbv5_channels_isdbt.conf

Install mirakurun

pi@raspberrypi:~ $ sudo apt-get install -y nodejs npm && \
  npm install npm n -g && \
  n stable
pi@raspberrypi:~ $ sudo reboot
pi@raspberrypi:~ $ sudo npm install pm2 -g
pi@raspberrypi:~ $ sudo npm install mirakurun -g --unsafe-perm --production
pi@raspberrypi:~ $ sudo npm install arib-b25-stream-test -g --unsafe
pi@raspberrypi:~ $ sudo mirakurun init

Settings

  pi@raspberrypi:~ $ sudo mirakurun config tuners  

末尾に以下を追加

 - name: PX-S1UD
  types:
    - GR
  command: /usr/bin/dvbv5-zap -a 0 -c /usr/local/conf/dvbv5_channels_isdbt.conf -r -P <channel>
  dvbDevicePath: /dev/dvb/adapter0/dvr0
  decoder: arib-b25-stream-test
  isDisabled: false

再起動

pi@raspberrypi:~ $ sudo mirakurun restart

チャンネルスキャン

pi@raspberrypi:~ $ curl -X PUT "http://localhost:40772/api/config/channels/scan"

VNCで視聴

チャンネル取得

pi@raspberrypi:~ $ curl http://localhost:40772/api/channels

接続URL例

地上波 - NHK総合
http://mirakurun:40772/api/channels/GR/27/services/1024/stream/
地上波 - NHK Eテレ
http://mirakurun:40772/api/channels/GR/26/services/1032/stream/
地上波 - 日本テレビ
http://mirakurun:40772/api/channels/GR/25/services/1040/stream/
地上波 - テレビ朝日
http://mirakurun:40772/api/channels/GR/24/services/1064/stream/
地上波 - TBS
http://mirakurun:40772/api/channels/GR/22/services/1048/stream/
地上波 - テレビ東京
http://mirakurun:40772/api/channels/GR/23/services/1072/stream/
地上波 - フジテレビ
http://mirakurun:40772/api/channels/GR/21/services/1056/stream/

.m3uファイル

VLCでプレイリスト表示出来る

#EXTM3U

#EXTINF:-1, 地上波 - NHK総合
http://mirakurun:40772/api/channels/GR/27/services/1024/stream/

#EXTINF:-1, 地上波 - NHK Eテレ
http://mirakurun:40772/api/channels/GR/26/services/1033/stream/

#EXTINF:-1, 地上波 - 日本テレビ
http://mirakurun:40772/api/channels/GR/25/services/1041/stream/

#EXTINF:-1, 地上波 - テレビ朝日
http://mirakurun:40772/api/channels/GR/24/services/1064/stream/

#EXTINF:-1, 地上波 - TBS
http://mirakurun:40772/api/channels/GR/22/services/1048/stream/

#EXTINF:-1, 地上波 - テレビ東京
http://mirakurun:40772/api/channels/GR/23/services/1072/stream/

#EXTINF:-1, 地上波 - フジテレビ
http://mirakurun:40772/api/channels/GR/21/services/1056/stream/

外付けHDD(SSD)

前提

  • パーティションテーブルはGPT
    • partedコマンドでフォーマットできる(MBRもいける)
  • ファイルシステムはext4

RasberrypiにUSB接続

差し込んだHDDのパスを確認

pi@raspberrypi:~ $ sudo fdisk -l
Disk /dev/sda: 119.24 GiB, 128035676160 bytes, 250069680 sectors
Disk model: PX-128M3P       

パーティションテーブル設定

pi@raspberrypi:~ $ sudo parted /dev/sda   

注意点: /dev/sdaはパーティションテーブル /dev/sda1,/dev/sda2はパーティション

パーティションテーブルをgptに変更

(parted) mklabel gpt

パーティション確認

(parted) p
Model: PLEXTOR PX-128M3P (scsi)
Disk /dev/sda: 128GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name     Flags
 1      1049kB  128GB  128GB  ext4         primary

パーティションが作成済の場合は削除

(parted) rm 1
(parted) quit

パーティション作成

pi@raspberrypi:~ $ sudo parted -a optimal /dev/sda mkpart primary ext4 0% 100%

パーティションが作成されたことを確認

pi@raspberrypi:~ $ sudo fdisk -l

パーティションフォーマット

pi@raspberrypi:~ $ sudo mkfs -t ext4 -L DATA-ext4 /dev/sda1

パーティションマウント

pi@raspberrypi:~ $ sudo mkdir /mnt/data
pi@raspberrypi:~ $ sudo mount /dev/sda1 /mnt/data

OS起動時にマウントする設定

/dev/sda1のUUID確認
pi@raspberrypi:~ $ sudo blkid
/dev/sda1: LABEL="DATA-ext4" UUID="01a4cd5d-618b-4dc4-a645-1e4aa12cca5b" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="primary" PARTUUID="37096080-0e06-4a7a-b1c8-54012cdab042"
起動時にマウントする設定
pi@raspberrypi:~ $ sudo vi /etc/fstab
以下を追記
UUID="r50e4-e715-4de2-b5c9-371b50" /mnt/data ext4    defaults,nofail 0 0
再起動
pi@raspberrypi:~ $ sudo reboot

EPGstation

ffmpegインストール

pi@raspberrypi:~ $ sudo apt -y install ffmpeg

ffmpegテスト実行(ハードウェアエンコード)

ffmpeg -y \
-hide_banner \
-fflags +discardcorrupt \
-i "test.m2ts" \
-sn \
-c:v h264_v4l2m2m \
-b:v 4M \
-num_capture_buffers 64 \
-vf yadif=0:-1:1,scale=-1:720 \
-vsync 1 -qmin 10 -qmax 51 -qdiff 8 -i_qfactor 1.40 -qcomp 0.6 \
-c:a copy \
-bsf:a aac_adtstoasc \
-f mp4 \

EPGstationインストール

https://github.com/l3tnun/EPGStation/blob/master/doc/linux-setup.md

ソースダウンロード&ビルド

pi@raspberrypi:~ $ git clone https://github.com/l3tnun/EPGStation.git
pi@raspberrypi:~ $ cd EPGStation
pi@raspberrypi:~ $ npm run all-install
pi@raspberrypi:~ $ sudo npm run build

設定ファイルコピー

pi@raspberrypi:~ $ cp config/config.yml.template config/config.yml
pi@raspberrypi:~ $ cp config/operatorLogConfig.sample.yml config/operatorLogConfig.yml
pi@raspberrypi:~ $ cp config/epgUpdaterLogConfig.sample.yml config/epgUpdaterLogConfig.yml
pi@raspberrypi:~ $ cp config/serviceLogConfig.sample.yml config/serviceLogConfig.yml
pi@raspberrypi:~ $ cp config/enc.js.template config/enc.js

設定変更

pi@raspberrypi:~ $ vi config/config.yml
recorded:
    - name: recorded
      path: '/mnt/data/recorded'
~~
ffmpeg: /usr/bin/ffmpeg

libx264 が指定されているところを h264_v4l2m2m(ハードウェアエンコード) に置換する

config.ymlの設定

libx264 を h264_v4l2m2m に置換

pi@raspberrypi:~ $ config/config.yml

enc.jsの設定

libx264 を h264_v4l2m2m に置換と追加

pi@raspberrypi:~ $ vi config/enc.js
// コーデックを変更
//const codec = 'libx264';
const codec = 'h264_v4l2m2m';

// その他設定
Array.prototype.push.apply(args,[
    '-preset', preset,
    '-aspect', '16:9',
    '-c:v', codec,
    '-crf', crf,
    '-b:v', '3M', // ビットレートの指定が必要らしいので追加。
    '-f', 'mp4',
    '-c:a', 'aac',
    '-ar', '48000',
    '-ab', audioBitrate,
    '-ac', '2',
    output
]);

自動起動設定

sudo pm2 startup -u pi --hp ~pi
pm2 start dist/server/index.js --name "epgstation"
pm2 save

自動起動設定確認

pi@raspberrypi:~ $ pm2 status
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0  │ epgstation         │ fork     │ 0    │ online    │ 0%       │ 84.8mb   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment