0x00 前言:
本文大部分内容借鉴自 https://blog.d2okkk.net/202101/kodi-setup/ 纠正其中几点小问题,添加一些新功能 最近因为网上找到的片源大部分都是 4k或h265的,之前一直在玩客云上跑的alexelec 只能播放1080 ,所以遇到前面 2 种片子只能在 nas上用 ffmpeg 进行转码,这样就得写脚本去判断一个个来转。
后来用用了一段时间 jellyfin,流媒体奈何 J1800 的 nas 扛不住,cpu 动不动就 100%,整个平台卡死。后来直接就换平台了,直接搞 HTPC。h110 平台 i5 6500 cpu 解码那叫一个流畅。这台机器双系统,windows 游戏用。
linux 就跑的最精简的 ubuntu server 装的最精简的 kodi。下面是具体的记录过程。当然我试过了 ubuntu 22.04 但是因为内核版本的原因,我的遥控器驱动没法编译,然后就退回到了 20.04。如果不用下面品牌的遥控器,22.04 操作步骤基本一样,可用。
0x00 安装过程
先对硬盘分区,先装 windows 再装 linux 这样最方便,grub 最后会自动 update 好,不用调试 2 遍。linux 安装时不要用 LVM,无他后续有问题好处理。懒。安装完以后,删除以下软件 - cloud-init 这是云相关用不上
echo 'datasource_list: [ None ]' | sudo -s tee /etc/cloud/cloud.cfg.d/90_dpkg.cfg
sudo apt-get purge cloud-init
sudo rm -rf /etc/cloud/; sudo rm -rf /var/lib/cloud/
- open-iscsi 远程scsi硬盘用不上
sudo apt remove open-iscsi
- snap 软件更用不上
sudo apt purge snapd
更新所有软件,安装驱动、x框架等kodi的依赖
sudo apt-get update
sudo apt-get install ssh software-properties-common xorg xserver-xorg-legacy \
alsa-utils mesa-utils git-core librtmp1 libmad0 lm-sensors libmpeg2-4 \
avahi-daemon avahi-discover libnss-mdns libnfs13 libva2 vainfo i965-va-driver linux-firmware dbus-x11 \
udisks2 pastebinit udisks2 xserver-xorg-video-intel
sudo systemctl enable --now avahi-daemon.service
# upnp dlna 投屏用的
sudo apt-get upgrade
配置允许”everyone” 启动Xserver
sudo dpkg-reconfigure xserver-xorg-legacy
新建kodi用户,并添加响应权限
sudo adduser kodi
sudo usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip,input kodi
vim /etc/X11/Xwrapper.config
# 添加下面这行,否则x无法随 kodi 启动,原作者没写
needs_root_rights=yes
我 kodi 能够需要关机 编辑/etc/polkit-1/localauthority/50-local.d/custom-actions.pkla
,添加以下内容使kodi可以重启和关机。
[Actions for kodi user]
Identity=unix-user:kodi
Action=org.freedesktop.login1.*;org.freedesktop.udisks2.*
ResultAny=yes
ResultInactive=yes
ResultActive=yes
[Untrusted Upgrade]
Identity=unix-user:kodi
Action=org.debian.apt.upgrade-packages;org.debian.apt.update-cache
ResultAny=yes
ResultInactive=yes
ResultActive=yes
添加kodi为服务,实现开机启动,这里直接是用kodi-standalone模式,这样只需要有X11就行了,可以省掉gnome、xface或者openbox之类的桌面环境。
编辑/etc/systemd/system/kodi.service
参考的链接的systemd,会有bug,kodi 的 upnp,作为客户端会不能发现。需要开机后在restart kodi才能解决。
故此解决的方法用下面这个system的 kodi.service` 地址在 https://raw.githubusercontent.com/graysky2/kodi-standalone-service/master/x86/init/kodi-x11.service 项目地址 https://github.com/graysky2/kodi-standalone-service
[Unit]
Description=Kodi standalone (X11)
After=remote-fs.target systemd-user-sessions.service network-online.target nss-lookup.target sound.target bluetooth.target polkit.service upower.service mysqld.service lircd.service
Wants=network-online.target polkit.service upower.service
Conflicts=getty@tty1.service
[Service]
User=kodi
Group=kodi
EnvironmentFile=-/etc/conf.d/kodi-standalone
PAMName=login
TTYPath=/dev/tty1
ExecStart=/usr/bin/xinit /usr/bin/kodi-standalone -- :0 -quiet -nolisten tcp vt1
ExecStop=/usr/bin/killall --user kodi --exact --wait kodi.bin
Restart=on-abort
StandardInput=tty
StandardOutput=journal
[Install]
Alias=display-manager.service
开机自动启动kodi
sudo systemctl daemon-reload
sudo systemctl enable kodi
安装kodi 准备了这么多,终于开始安装kodi了。安装kodi是很简单的,几条命令搞定。
sudo apt-add-repository ppa:team-xbmc/ppa
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install kodi kodi-x11 kodi-pvr-iptvsimple
sudo systemctl start kodi
关于遥控 遥控器是蓝宝石SAPPHIRE Theatrix的遥控器,比一般的HP之类的mce遥控便宜不少,这遥控器说实话,能不用还是不用了比较折腾。
网上有现成的驱动安装方法如下,最新版就是 7.4 ,作者没写支持5.x的内核,实测20.04 的5.4可用,22.04 的 5.14内核亲测无效。至于还会不会更新不好说了,这遥控器太老了。
另外,随着linux 内核的更新,每次小版本的update 都要跟着做一次make install,否则module里面因为没有驱动,遥控器会失效
sudo apt install build-essential
wget http://rtr.ca/sapphire_remote/sapphire-7.4.tar.gz
tar xvf sapphire-7.4.tar.gz
cd sapphire-7.4
sudo make
sudo make install
这个驱动是为MythTV制作的,要适配kodi的话还需要做一点点keymap的工作。
原作者的keymap https://blog.d2okkk.net/202101/kodi-setup/sapphire.keymap 我改的 /etc/sapphire.keymap
改一下这个keymap
SAPPHIRE_DVDMENU KEY_C NO_REPEAT ## Menu
改完后的效果
#
# Default keymap from sapphire.c v3.0.
#
# Edit this as you please, keeping in mind that spaces are NOT permitted
# within each column.
#
# Eg. this is INCORRECT: KEY_F15 | ALT
# whereas this is good: KEY_F15|ALT
#
# Use the provided sapphire_keymap.sh script to install these
# mappings at runtime in place of the driver's built-in mappings.
# Keep your own copy of this file separate from the driver source,
# so that subsequent changes in the driver mappings won't clobber
# your own definitions here.
#
# As in the example above, KeyCode values can be combined with
# any mix of these modifier keys: SHIFT, ALT, CTRL, and/or META.
#
# Eg. SAPPHIRE_PLAY KEY_P|CTRL NO_REPEAT ## Mythtv Play/Pause function
# Or: SAPPHIRE_PLAY KEY_P|CTRL|ALT NO_REPEAT ## something else
#
# The SpecialOptions field is used to indicate the desired auto-repeat rate
# for each button individually. The choices are:
#
# NO_REPEAT - the button will not auto-repeat when held down.
# SLOW_REPEAT - the button will repeat slowly.
# RAMP_REPEAT - the button will repeat slowly at first, but speed up if held down.
# LONGKEY - no auto-repeat: special behaviour described below.
#
# The special value LONGKEY can be used in SpecialOptions
# insted of an auto-repeat setting. This causes a button on the remote
# to have two separate functions, depending upon how quickly it is released.
#
# A short-press/release gets the regular KeyCode value, but if the button
# is held down for one second or longer, then an alternate value can be send instead.
# Just combine the desired alternate keycode with the LONGKEY tag.
#
# Eg. SAPPHIRE_MUTE KEY_F9 LONGKEY|KEY_F15 ## Mute (tap) or Audiosync (hold)
#
# ButtonName KeyCode SpecialOptions ## Comments
#
SAPPHIRE_UP KEY_UP RAMP_REPEAT ## up (CUSTOM)
SAPPHIRE_DOWN KEY_DOWN RAMP_REPEAT ## down (CUSTOM)
SAPPHIRE_RIGHT KEY_RIGHT RAMP_REPEAT ## right
SAPPHIRE_LEFT KEY_LEFT RAMP_REPEAT ## left
SAPPHIRE_ENTEROK KEY_ENTER LONGKEY|KEY_F15 ## Select (tap) or Audiosync (hold)
SAPPHIRE_BACK KEY_BACKSPACE SLOW_REPEAT ## Back
SAPPHIRE_PLAY KEY_P NO_REPEAT ## Play/Pause
SAPPHIRE_PAUSE KEY_SPACE NO_REPEAT ## Play/Pause
SAPPHIRE_VOLUP KEY_EQUAL FAST_REPEAT ## Volume Up
SAPPHIRE_VOLDOWN KEY_MINUS FAST_REPEAT ## Volume Down
SAPPHIRE_CHUP KEY_PAGEUP SLOW_REPEAT ## channel up (CUSTOM)
SAPPHIRE_CHDOWN KEY_PAGEDOWN SLOW_REPEAT ## channel down (CUSTOM)
SAPPHIRE_MUTE KEY_F8 SLOW_REPEAT ## Mute
SAPPHIRE_RECORD KEY_R NO_REPEAT ## Record/Delete (CUSTOM)
SAPPHIRE_FWD KEY_DOT RAMP_REPEAT ## FFwd
SAPPHIRE_REW KEY_COMMA RAMP_REPEAT ## Rewind
SAPPHIRE_ANGLE KEY_O NO_REPEAT ## Player process info
SAPPHIRE_SAP KEY_Z NO_REPEAT ## Display info
SAPPHIRE_DVDMENU KEY_C NO_REPEAT ## Menu
SAPPHIRE_INFOEPG KEY_I NO_REPEAT ## Info
SAPPHIRE_TAB KEY_END SLOW_REPEAT ## Commskip Fwd
SAPPHIRE_BACKTAB KEY_HOME SLOW_REPEAT ## Commskip Rev
SAPPHIRE_RADIO KEY_F7 NO_REPEAT ## Signal Monitor
SAPPHIRE_LASTCH KEY_0 NO_REPEAT ## previous chan
SAPPHIRE_LANGUAGE KEY_G SLOW_REPEAT ## Next Audio Track
SAPPHIRE_TELETEXTCC KEY_V SLOW_REPEAT ## Teletext
SAPPHIRE_SUBTITLE KEY_L SLOW_REPEAT ## Next subtitle
SAPPHIRE_HOMEHOUSE KEY_ESC NO_REPEAT ## jump to MainMenu
SAPPHIRE_BLUEVIDEOS KEY_F4 NO_REPEAT ## Video
SAPPHIRE_LIVETV KEY_F5 NO_REPEAT ## Play LiveTV
SAPPHIRE_REDDVDVCD KEY_F1 NO_REPEAT ## PlayDVD/DVDMenu
SAPPHIRE_YELLOWPICTURES KEY_F3 NO_REPEAT ## Picture
SAPPHIRE_1 KEY_1 SLOW_REPEAT ## 1
SAPPHIRE_2 KEY_2 SLOW_REPEAT ## 2
SAPPHIRE_3 KEY_3 SLOW_REPEAT ## 3
SAPPHIRE_4 KEY_4 SLOW_REPEAT ## 4
SAPPHIRE_5 KEY_5 SLOW_REPEAT ## 5
SAPPHIRE_6 KEY_6 SLOW_REPEAT ## 6
SAPPHIRE_7 KEY_7 SLOW_REPEAT ## 7
SAPPHIRE_8 KEY_8 SLOW_REPEAT ## 8
SAPPHIRE_9 KEY_9 SLOW_REPEAT ## 9
SAPPHIRE_0 KEY_0 SLOW_REPEAT ## 0
SAPPHIRE_STOP KEY_X NO_REPEAT ## Stop
SAPPHIRE_POWER KEY_S NO_REPEAT ## restart kodi
SAPPHIRE_CLEAR KEY_BACKSPACE SLOW_REPEAT ## Adjust audiosync by 90msecs (see below)
SAPPHIRE_GREENMUSIC KEY_F2 NO_REPEAT ## Music
#
# Now for the macro definitions: each macro sends a list of up to eight keycodes:
#
KEY_MACRO_0 KEY_F15 KEY_DOWN KEY_LEFT ## Adjust AudioSync by +90msecs
KEY_MACRO_1
KEY_MACRO_2
KEY_MACRO_2
KEY_MACRO_3
KEY_MACRO_4
KEY_MACRO_5
KEY_MACRO_6
KEY_MACRO_7
这样更好用 原作者的连接 https://blog.d2okkk.net/202101/kodi-setup/gen.xml 位置是 /home/kodi/.kodi/userdata/keymaps/gen.xml
实际内容
<keymap>
<global>
<keyboard>
<f5>playpvrtv</f5>
<f1>ActivateWindow(TVChannels)</f1>
<f4>ActivateWindow(Videos)</f4>
<f3>ActivateWindow(Pictures)</f3>
<g>AudioNextLanguage</g>
</keyboard>
</global>
</keymap>
这个不用动,后期有需求可以使用 kodi 的 keymap editor 来修改,这个文件是 kodi 内的 最后用这个 sapphire 的驱动覆盖系统自带的 topseed 驱动,开机自动加载 keymap 配置。
编辑文件/etc/systemd/system/sapphire.service
[Unit]
Description=Sapphire remote start script
Before=kodi.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/sapphire_startup.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable sapphire
sudo systemctl start sapphire
这样系统启动之后遥控器就直接可用了。 这个驱动会随着内核的更新儿丢失,丢失后需要重新make install
一下
0x02 与宝视来投影关联
因为我用的 boxlight 的投影带串口指令集就不放了,获取的渠道太多了,可以直接用串口控制。所以我在 systemd 里面添加了开启启动投影和关机时关闭投影的脚本 具体如下 开机启动,发出指令后因为是多显示接口,让 xrandr 确定一下主显,下面 30 秒内 1 秒执行一次。
kodi@kodi:~$ cat boxlightstart
#!/bin/bash
echo 00! >/dev/ttyS0
n=0
while (($n<30))
do
DISPLAY=:0 xrandr --output HDMI-1 --auto
n=$((n+1))
sleep 1
done
关机关闭
kodi@kodi:~$ cat boxlightstop
#!/bin/bash
echo 00\ >/dev/ttyS0
systemd 开机启动
kodi@kodi:/etc/systemd/system$ cat boxlightstart.service
[Unit]
Description = boxlight
#After = systemd-user-sessions.service
[Service]
ExecStart = /home/kodi/boxlightstart
[Install]
WantedBy = multi-user.target
systemd 关机时执行
kodi@kodi:/etc/systemd/system$ cat boxlightstop.service
[Unit]
Description=runs only upon shutdown
Conflicts=reboot.target
After=network.target
[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/bin/bash /home/kodi/boxlightstop
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
参考:
https://blog.d2okkk.net/202101/kodi-setup/
https://github.com/OnceUponALoop/mini-kodi
https://forum.kodi.tv/showthread.php?tid=231955 https://forum.kodi.tv/showthread.php?tid=231955&page=339 https://forum.kodi.tv/showthread.php?tid=333108&page=2 https://kodi.wiki/view/Keymap#Remotes https://github.com/xbmc/xbmc/blob/master/system/keymaps/remote.xml https://kodi.wiki/view/Using_an_MCE_remote https://kodi.wiki/view/Keyboard_controls#Customizing_buttons_through_the_GUI http://rtr.ca/sapphire_remote/index.html https://web.archive.org/web/20170714192652/http://kodi.wiki/view/Sapphire_Remote https://forum.libreelec.tv/thread/634-compile-sapphire-remote-driver/?pageNo=3