Project

General

Profile

TVHeadend build and install on Lubuntu 20.04 64bit with iGPU 8+ (for gpu transcoding)

Added by Alin Gherghescu almost 2 years ago

This tutorial is intended for beginners interested in compiling tvheadend with HW GPU transcoding (using iGPU form Intel gen 8+).
It is a little messy how Intel is combining CPU generations with GPU generations so before you buy a platform I strongly recommend you to check www.cpu-monkey.com and www.cpu-world.com to confirm your GPU is hardware capable decoding/encoding, Gen 9+ is recommended to 'low power encoders'.
I tested this methodology on following platforms:
- atomicpi (Atom x5-Z8350) iGPU gen 8 Atom x5-Z8350 downloading lubuntu 20.04 from: http://ehxz.tk/atomicpi
Note: this CPU doesn't have the H264 Low Power Mode encoder
- gk41 celeron J4125 Amazon iGPU 9.5 celeron J4125
- NUC8 Compute Element with Pentium Gold 5405U Compute Element iGPU 9.5 Pentium Gold 5405U
- NUC11 Compute Element with Celeron 6305

Date:
Jan 4, 2023.

HW:
NUC element with Pentium Gold 5405u

download ISO LUBUNTU 20.04:
https://www.cdimage.ubuntu.com/lubuntu/releases/20.04/release/
lubuntu-20.04.5-desktop-amd64.iso

flash ISO to USB 32G using rufus-3.21
Note: make sure you plug the USB stick in USB2.0 socket (black).

Install Lubuntu to PC with default settings; connect also to internet.
At boot you will see some i915 error about DRM ... don't worry.

Update some settings:
Preference / LXQt setting / Power Management: Idle --> uncheck Enable Idleness Watcher : Close
Preference / LXQt setting / Monitor Settings: 1280 x 720 : Save : Yes
Preference / LXQt setting / LXQt Configuration Center : Openbox Settings --> Desktops : Number of desktops : 1
Preference / Screen Saver : Mode : Disable screen saver

Install SSH:
System Tools / QTerminal

sudo apt update
sudo apt install ssh

check status:

systemctl status sshd.service

You should see is Active.

if is not working:

sudo systemctl enable sshd

and:
sudo systemctl start sshd

I prefer to connect over SSH to continue, but you can remain in terminal (on desktop):

Update to latest kernel version:

sudo apt update
sudo apt upgrade
sudo reboot

sudo apt autoremove --purge

uname -a

alin@alin-cm8pcb4r:~$ uname -a
Linux alin-cm8pcb4r 5.15.0-56-generic #62~20.04.1-Ubuntu SMP Tue Nov 22 21:24:20 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

install Media SDK:
https://docs.unified-streaming.com/documentation/transcode/media-sdk.html#ubuntu-20-04-intel-media-sdk-2020

sudo apt-get -q -y update
sudo apt-get -q -y install intel-media-va-driver-non-free libmfx1 libva-drm2 vainfo

sudo vainfo

alin@alin-cm8pcb4r:~$ sudo vainfo
error: XDG_RUNTIME_DIR not set in the environment.
error: can't connect to X server!
libva info: VA-API version 1.7.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_7
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.7 (libva 2.6.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 20.1.1 ()
vainfo: Supported profile and entrypoints
VAProfileNone : VAEntrypointVideoProc
VAProfileNone : VAEntrypointStats
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Simple : VAEntrypointEncSlice
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointEncSlice
VAProfileH264Main : VAEntrypointVLD
VAProfileH264Main : VAEntrypointEncSlice
VAProfileH264Main : VAEntrypointFEI
VAProfileH264Main : VAEntrypointEncSliceLP
VAProfileH264High : VAEntrypointVLD
VAProfileH264High : VAEntrypointEncSlice
VAProfileH264High : VAEntrypointFEI
VAProfileH264High : VAEntrypointEncSliceLP
VAProfileVC1Simple : VAEntrypointVLD
VAProfileVC1Main : VAEntrypointVLD
VAProfileVC1Advanced : VAEntrypointVLD
VAProfileJPEGBaseline : VAEntrypointVLD
VAProfileJPEGBaseline : VAEntrypointEncPicture
VAProfileH264ConstrainedBaseline: VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
VAProfileH264ConstrainedBaseline: VAEntrypointFEI
VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP
VAProfileVP8Version0_3 : VAEntrypointVLD
VAProfileVP8Version0_3 : VAEntrypointEncSlice
VAProfileHEVCMain : VAEntrypointVLD
VAProfileHEVCMain : VAEntrypointEncSlice
VAProfileHEVCMain : VAEntrypointFEI
VAProfileHEVCMain10 : VAEntrypointVLD
VAProfileHEVCMain10 : VAEntrypointEncSlice
VAProfileVP9Profile0 : VAEntrypointVLD
VAProfileVP9Profile2 : VAEntrypointVLD

the data format is:
CODEC/profile : Encoder/Decoder
VAProfileH264High : VAEntrypointVLD
VAProfileH264High : VAEntrypointEncSlice
VAProfileH264High : VAEntrypointFEI
VAProfileH264High : VAEntrypointEncSliceLP

This is: H264, Profile high with decoder (VAEntrypointVLD) , Encoder (VAEntrypointEncSlice) and LowPower encoder (VAEntrypointEncSliceLP)
Is importand to identify if your GPU has this low power (LP) codecs available.
In my case I have low power for: H264 profiles Main, High and Constrained

OPTION 1: Gen8 / Gen9 / Gen9.5
Install required development packages:
https://www.linuxfordevices.com/tutorials/ubuntu/install-intel-graphic-drivers

Note:
- some packages are already installed ... but is no harm to install them again.

check:

sudo lspci -nn | grep -e VGA

alin@alin-cm8pcb4r:~$ sudo lspci -nn | grep -e VGA
00:02.0 VGA compatible controller [0300]: Intel Corporation Device [8086:3ea1] (rev 02)

you can go on: https://dgpu-docs.intel.com/devices/hardware-table.html
and search for: "3ea1" (check after [8086:****]).
and see is: Intel® UHD Graphics 610 --> Gen 9 --> Coffee Lake

sudo apt install mesa-utils

sudo apt autoremove

Now, enter the following command to get the driver details. It will also give you other GPU details along with driver details.
in Desktop (not SSH):

glxinfo -B

How to install Intel graphic drivers on Ubuntu?

sudo apt install -y gpg-agent wget

wget -qO - https://repositories.intel.com/graphics/intel-graphics.key | sudo apt-key add -

sudo apt-add-repository \
  'deb [arch=amd64] https://repositories.intel.com/graphics/ubuntu focal main'

Install run-time packages:

sudo apt-get update

sudo apt install \
  intel-opencl-icd \
  intel-level-zero-gpu level-zero \
  intel-media-va-driver-non-free libmfx1

Install developer packages:

sudo apt install \
  libigc-dev \
  intel-igc-cm \
  libigdfcl-dev \
  libigfxcmrt-dev \
  level-zero-dev

END OPTION 1

OPTION 2: Gen11+
https://dgpu-docs.intel.com/installation-guides/ubuntu/ubuntu-focal-legacy.html

Note:
- some packages are already installed ... but is no harm to install them again.

check:

sudo lspci -nn | grep -e VGA

alin@alin-cm8pcb4r:~$ sudo lspci -nn | grep -e VGA
00:02.0 VGA compatible controller [0300]: Intel Corporation Device [8086:9a78] (rev 01)

you can go on: https://dgpu-docs.intel.com/devices/hardware-table.html
and search for: "9a78" (check after [8086:****]).
and see is: Intel® UHD Graphics --> Gen Xe --> Tiger Lake

Step 1 Add package repository:

sudo apt-get install -y gpg-agent wget

wget -qO - https://repositories.intel.com/graphics/intel-graphics.key |
  sudo gpg --dearmor --output /usr/share/keyrings/intel-graphics.gpg

echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/graphics/ubuntu focal-legacy main' | \
  sudo tee  /etc/apt/sources.list.d/intel.gpu.focal.list

Step 2 Install run-time packages:

sudo apt-get update

sudo apt-get install \
  intel-opencl-icd \
  intel-level-zero-gpu level-zero \
  intel-media-va-driver-non-free libmfx1 libmfxgen1 libvpl2

Install developer packages:

sudo apt-get install \
  libigc-dev \
  intel-igc-cm \
  libigdfcl-dev \
  libigfxcmrt-dev \
  level-zero-dev

END OPTION 2

Configuring permissions:
To access GPU capabilities, a user needs to have the correct permissions. The following will list the group assigned ownership of the render nodes, and list the groups the active user is a member of:

stat -c "%G" /dev/dri/render*

alin@alin-cm8pcb4r:~$ stat -c "%G" /dev/dri/render*
render

My expectation is that you receive 'render' ... but you might receive also other names (like video). In that case you have to replace in commands below the 'render' with 'video' (or what ever you receive).

Now we check if user is part of that group:

groups ${USER}

alin@alin-cm8pcb4r:~$ groups ${USER}
alin : alin adm cdrom sudo dip plugdev lpadmin sambashare
--> as expected is not.

we add user to group 'render' (or video if you received video above):

sudo gpasswd -a ${USER} render

newgrp render

Now we have to verify that actual user is part of render (or video):

groups ${USER}

alin@alin-cm8pcb4r:~$ groups ${USER}
alin : alin adm cdrom sudo dip plugdev render lpadmin sambashare

Note we have render in the list.

Update to latest:

sudo apt update
sudo apt upgrade

Install gpu tools (required to check the work load on GPU):

sudo apt install intel-gpu-tools

Enable GUC firmware (this is a must for encoding with low power codec):

we need to generate a file:

sudo vi /etc/modprobe.d/i915.conf

with the text (only one line) --> press key 'I':

OPTION 1: Gen8 / Gen9 / Gen9.5

options i915 enable_guc=2

END OPTION 1

OPTION 2: Gen11+

options i915 enable_guc=3

END OPTION 2

--> press key : and w
--> press key : and q

sudo update-initramfs -k all -u
sudo update-grub

sudo reboot

Verify GuC was enabled:

dmesg | grep guc

OPTION 1: Gen8 / Gen9 / Gen9.5
alin@alin-cm8pcb4r:~$ dmesg | grep guc
[ 1.460690] Setting dangerous option enable_guc - tainting kernel
[ 2.610368] i915 0000:00:02.0: [drm] GuC firmware i915/kbl_guc_62.0.0.bin version 62.0 submission:disabled
END OPTION 1

OPTION 2: Gen11+
alin@alin-6305:~$ dmesg | grep guc
[ 1.685204] Setting dangerous option enable_guc - tainting kernel
[ 2.391513] i915 0000:00:02.0: [drm] GuC firmware i915/tgl_guc_62.0.0.bin version 62.0 submission:enabled
END OPTION 2

-> it sounds scary 'dangerous option' ... but is fine.

check vainfo:

vainfo

OPTION 1: Gen8 / Gen9 / Gen9.5
alin@alin-cm8pcb4r:~$ vainfo
error: can't connect to X server!
libva info: VA-API version 1.15.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_15
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.15 (libva 2.15.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 22.5.0 (7e9cc59)
vainfo: Supported profile and entrypoints
VAProfileNone : VAEntrypointVideoProc
VAProfileNone : VAEntrypointStats
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Simple : VAEntrypointEncSlice
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointEncSlice
VAProfileH264Main : VAEntrypointVLD
VAProfileH264Main : VAEntrypointEncSlice
VAProfileH264Main : VAEntrypointFEI
VAProfileH264Main : VAEntrypointEncSliceLP
VAProfileH264High : VAEntrypointVLD
VAProfileH264High : VAEntrypointEncSlice
VAProfileH264High : VAEntrypointFEI
VAProfileH264High : VAEntrypointEncSliceLP
VAProfileVC1Simple : VAEntrypointVLD
VAProfileVC1Main : VAEntrypointVLD
VAProfileVC1Advanced : VAEntrypointVLD
VAProfileJPEGBaseline : VAEntrypointVLD
VAProfileJPEGBaseline : VAEntrypointEncPicture
VAProfileH264ConstrainedBaseline: VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
VAProfileH264ConstrainedBaseline: VAEntrypointFEI
VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP
VAProfileVP8Version0_3 : VAEntrypointVLD
VAProfileVP8Version0_3 : VAEntrypointEncSlice
VAProfileHEVCMain : VAEntrypointVLD
VAProfileHEVCMain : VAEntrypointEncSlice
VAProfileHEVCMain : VAEntrypointFEI
VAProfileHEVCMain10 : VAEntrypointVLD
VAProfileHEVCMain10 : VAEntrypointEncSlice
VAProfileVP9Profile0 : VAEntrypointVLD
VAProfileVP9Profile2 : VAEntrypointVLD

You should see that "VA-API version: 1.15 (libva 2.15.0)" updated from previous "VA-API version: 1.7 (libva 2.6.0)"
END OPTION 1

OPTION 2: Gen11+
alin@alin-6305:~$ vainfo
Trying display: wayland
Trying display: x11
error: can't connect to X server!
Trying display: drm
libva info: VA-API version 1.16.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_16
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.16 (libva 2.16.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 22.6.4 (aca8ee0)
vainfo: Supported profile and entrypoints
VAProfileNone : VAEntrypointVideoProc
VAProfileNone : VAEntrypointStats
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Simple : VAEntrypointEncSlice
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointEncSlice
VAProfileH264Main : VAEntrypointVLD
VAProfileH264Main : VAEntrypointEncSlice
VAProfileH264Main : VAEntrypointFEI
VAProfileH264Main : VAEntrypointEncSliceLP
VAProfileH264High : VAEntrypointVLD
VAProfileH264High : VAEntrypointEncSlice
VAProfileH264High : VAEntrypointFEI
VAProfileH264High : VAEntrypointEncSliceLP
VAProfileVC1Simple : VAEntrypointVLD
VAProfileVC1Main : VAEntrypointVLD
VAProfileVC1Advanced : VAEntrypointVLD
VAProfileJPEGBaseline : VAEntrypointVLD
VAProfileJPEGBaseline : VAEntrypointEncPicture
VAProfileH264ConstrainedBaseline: VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
VAProfileH264ConstrainedBaseline: VAEntrypointFEI
VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP
VAProfileVP8Version0_3 : VAEntrypointVLD
VAProfileHEVCMain : VAEntrypointVLD
VAProfileHEVCMain : VAEntrypointEncSlice
VAProfileHEVCMain : VAEntrypointFEI
VAProfileHEVCMain : VAEntrypointEncSliceLP
VAProfileHEVCMain10 : VAEntrypointVLD
VAProfileHEVCMain10 : VAEntrypointEncSlice
VAProfileHEVCMain10 : VAEntrypointEncSliceLP
VAProfileVP9Profile0 : VAEntrypointVLD
VAProfileVP9Profile0 : VAEntrypointEncSliceLP
VAProfileVP9Profile1 : VAEntrypointVLD
VAProfileVP9Profile1 : VAEntrypointEncSliceLP
VAProfileVP9Profile2 : VAEntrypointVLD
VAProfileVP9Profile2 : VAEntrypointEncSliceLP
VAProfileVP9Profile3 : VAEntrypointVLD
VAProfileVP9Profile3 : VAEntrypointEncSliceLP
VAProfileHEVCMain12 : VAEntrypointVLD
VAProfileHEVCMain12 : VAEntrypointEncSlice
VAProfileHEVCMain422_10 : VAEntrypointVLD
VAProfileHEVCMain422_10 : VAEntrypointEncSlice
VAProfileHEVCMain422_12 : VAEntrypointVLD
VAProfileHEVCMain422_12 : VAEntrypointEncSlice
VAProfileHEVCMain444 : VAEntrypointVLD
VAProfileHEVCMain444 : VAEntrypointEncSliceLP
VAProfileHEVCMain444_10 : VAEntrypointVLD
VAProfileHEVCMain444_10 : VAEntrypointEncSliceLP
VAProfileHEVCMain444_12 : VAEntrypointVLD
VAProfileHEVCSccMain : VAEntrypointVLD
VAProfileHEVCSccMain : VAEntrypointEncSliceLP
VAProfileHEVCSccMain10 : VAEntrypointVLD
VAProfileHEVCSccMain10 : VAEntrypointEncSliceLP
VAProfileHEVCSccMain444 : VAEntrypointVLD
VAProfileHEVCSccMain444 : VAEntrypointEncSliceLP
VAProfileAV1Profile0 : VAEntrypointVLD
VAProfileHEVCSccMain444_10 : VAEntrypointVLD
VAProfileHEVCSccMain444_10 : VAEntrypointEncSliceLP
END OPTION 2

This is required to scan channels later on:

sudo apt update
sudo apt install w-scan

clean up:

sudo apt autoremove

Compile tvheadend:

cd ~
git clone https://github.com/tvheadend/tvheadend.git

sudo apt update
sudo apt install gettext libssl-dev cmake libpcre2-dev libdvbcsa-dev libva-dev liburiparser-dev libavahi-client-dev debhelper zlib1g-dev python
sudo apt install pip

cd tvheadend

./configure

$################### log output ####################
alin@alin-cm8pcb4r:~/tvheadend$ ./configure
Checking support/features
checking for cc execinfo.h ... ok
checking for cc -mmmx ... ok
checking for cc -msse2 ... ok
checking for cc -Wunused-result ... ok
checking for cc -fstack-protector ... ok
checking for cc -fstack-protector-strong ... ok
checking for cc -fstack-check ... ok
checking for cc -fPIE ... ok
checking for cc strlcat ... fail
checking for cc strlcpy ... fail
checking for cc fdatasync ... ok
checking for cc getloadavg ... ok
checking for cc atomic32 ... ok
checking for cc atomic64 ... ok
checking for cc atomic_time_t ... ok
checking for cc atomic_ptr ... ok
checking for cc bitops64 ... ok
checking for cc lockowner ... ok
checking for cc qsort_r ... ok
checking for cc stime ... fail
checking for cc gmtoff ... ok
checking for cc recvmmsg ... ok
checking for cc sendmmsg ... ok
checking for cc libiconv ... fail
^ using build-in glibc iconv routines
checking for cc ifnames ... ok
checking for cc cclang_threadsan ... fail
checking for py module gzip ... ok
checking for pkg-config ... ok
checking for xgettext ... ok
checking for msgmerge ... ok
checking for gzip ... ok
checking for bzip2 ... ok
checking for pkg openssl ... ok (detected 1.1.1f)
checking for cc linux/dvb/version.h ... ok
checking for pkg zlib ... ok (detected 1.2.11)
checking for pkg libpcre2-8 ... ok (detected 10.34)
checking for pkg liburiparser ... ok (detected 0.9.3)
checking for pkg avahi-client ... ok (detected 0.7)
checking for cmake ... ok
checking for cc -lstdc++ ... ok
checking for pkg libva >=0.38.0 ... ok (detected 1.15.0)
checking for pkg libva-drm >=0.38.0 ... ok (detected 1.15.0)
checking for cc sys/inotify.h ... ok
checking for cc inotify_init1 ... ok
checking for cc dvbcsa/dvbcsa.h ... ok
checking for cc -ldvbcsa ... ok
fetching dvb-scan files ... ok
checking for cc epoll_create1 ... ok
checking for pkg dbus-1 ... ok (detected 1.12.16)

Compiler:
Using C compiler: cc
Using LD flags: -ldvbcsa
Build for arch: x86_64

Binaries:
Using PYTHON: python
Using GZIP: gzip
Using BZIP2: bzip2

Options:
pie yes
ccdebug no
cardclient yes
cwc yes
cccam yes
capmt yes
constcw yes
linuxdvb yes
satip_server yes
satip_client yes
hdhomerun_client yes
hdhomerun_static yes
iptv yes
tsfile yes
dvbscan yes
timeshift yes
trace yes
avahi yes
zlib yes
libav yes
ffmpeg_static yes
libx264 yes
libx264_static yes
libx265 yes
libx265_static yes
libvpx yes
libvpx_static yes
libtheora yes
libtheora_static yes
libvorbis yes
libvorbis_static yes
libfdkaac no
libfdkaac_static no
libopus yes
libopus_static yes
nvenc no
vaapi yes
mmal no
omx no
inotify yes
epoll yes
pcre no
pcre2 yes
uriparser yes
ccache no
tvhcsa yes
bundle no
pngquant no
kqueue no
dbus_1 yes
android no
gtimer_check no
slow_memoryinfo no
libsystemd_daemon no
pcloud_cache yes
ddci yes
cclang_threadsan no
gperftools no
execinfo yes
mmx yes
sse2 yes
W_unused_result yes
f_stack_protector yes
f_stack_protector_strong yes
f_stack_check yes
f_PIE yes
fdatasync yes
getloadavg yes
atomic32 yes
atomic64 yes
atomic_time_t yes
atomic_ptr yes
bitops64 yes
lockowner yes
qsort_r yes
gmtoff yes
recvmmsg yes
sendmmsg yes
ifnames yes
py_gzip yes
bin_pkg_config yes
bin_xgettext yes
bin_msgmerge yes
bin_gzip yes
bin_bzip2 yes
ssl yes
linuxdvbapi yes
linuxdvb_ca yes
upnp yes
bin_cmake yes
stdcpp yes
libogg_static yes
hwaccels yes
inotify_h yes
inotify_init1 yes
dvbcsa yes
epoll_create1 yes
mpegts yes
mpegts_dvb yes

Packages:
openssl 1.1.1f
zlib 1.2.11
libpcre2-8 10.34
liburiparser 0.9.3
avahi-client 0.7
libva 1.15.0
libva-drm 1.15.0
dbus-1 1.12.16

Installation paths:
Prefix: /usr/local
Binaries: ${prefix}/bin
Libraries: ${prefix}/lib
Data files: ${prefix}/share
Man pages: ${datadir}/man

Final Binary:
/home/alin/tvheadend/build.linux/tvheadend

Tvheadend Data Directory:
/usr/local/share/tvheadend
$################### log output end ####################

Build tvheadend:

./Autobuild.sh

This step will take sometime ... you will see a lot of workings. Is OK as long as the long will end with something like:
$################### log output ####################
dpkg-deb: building package 'tvheadend-dbg' in '../tvheadend-dbg_4.3-2063~gd88549603~focal_amd64.deb'.
dpkg-deb: building package 'tvheadend' in '../ tvheadend_4.3-2063~gd88549603~focal_amd64.deb '.
make1: Leaving directory '/home/alin/tvheadend'
dpkg-genbuildinfo --build=binary
dpkg-genchanges --build=binary >../tvheadend_4.3-2063~gd88549603~focal_amd64.changes
dpkg-genchanges: info: binary-only upload (no source code included)
dpkg-source --after-build .
dpkg-buildpackage: info: binary-only upload (no source included)
doozer-versioned-artifact:/home/alin/tvheadend/../tvheadend_4.3-2063~gd88549603~focal_amd64.deb:deb:application/x-deb:tvheadend_4.3-2063~gd88549603~focal_amd64.deb
doozer-versioned-artifact:/home/alin/tvheadend/../tvheadend-dbg_4.3-2063~gd88549603~focal_amd64.deb:deb:application/x-deb:tvheadend-dbg_4.3-2063~gd88549603~focal_amd64.deb
doozer-versioned-artifact:/home/alin/tvheadend/../tvheadend_4.3-2063~gd88549603~focal_amd64.changes:changes:text/plain:tvheadend_4.3-2063~gd88549603~focal_amd64.changes
$################### log output end ####################

From this last log you need to copy the file name bolded (in your case will have a different number after '4.3-')
In my case is: tvheadend_4.3-2063~gd88549603~focal_amd64.deb

cd ..

Install tvheadend:
sudo dpkg -i tvheadend_4.3-2063~gd88549603~focal_amd64.deb

Intel GPU:
sudo apt install i965-va-driver-shaders

We have to add also user hts to render (or your group that has access to GPU):
sudo gpasswd -a hts render

newgrp render

verify:
groups hts

alin@alin-cm8pcb4r:~$ groups hts
hts : hts render

Now we see user is part of render.

start tvheadend:

sudo systemctl start tvheadend.service

in browser:
http://[IP_NUMBER]:9981

From this point you need to perfom the tvheadend setup (not in the scope of this tutorial).

Setup GPU transcoding:
--> make sure you have 'Expert' settings enabled
[browser menus]:
Configuration / Stream / Codec Profiles --> Add
Codec: h264_vaapi
Name: h264_vaapi
Description: ....
Deniterlace: checked (very important)
Height: 0
Hardware acceleration: checked (very important)
Device name: i915 v.1.6.0 (/dev/dri/renderD128) (very important)
Bitrate: 0
Buffer factor: 3
Rate control: 1 (CQP)
Constant QP: 27
Ignore B-Frames: 0
Quality: 1

Press Create button.

[browser menus]:
Configuration / Stream / Stream Profiles --> Add
Type: Transcode/av-lib
Profile name: h264
Enabled: checked
Default: checked
Comment: ...
Data timeout: 5
Default priority: Normal
Force priority: 0
Restart on error: checked
Continue if descrambling fails: checked
Descrembling timeout: 2000
Switch to another service: checked
Prefered services vide type: None
Container: Matroska
Video codec profile: h264_vaapi (very important)
Source video codec: EMPTY
Audio codec profile: web-aac
Source audio codec: EMPTY
Subtitle codec profile: Copy
Source subtitle codec: EMPTY

Press Create button.

Note:
all 'very important' are required.

Now you are ready to test: open one stream with tvh server and check the Tvheadend log:
2022-12-09 10:53:37.821 transcode: 0001: 01:MPEG2VIDEO: > Using profile h264_vaapi
2022-12-09 10:53:37.822 transcode: 0001: 02:AC3: > Using profile webtv-aac

To confirm you are using GPU for trancoding you need to send:

sudo intel_gpu_top

When you don't have any streams open you will see all numbers: 0; after you open streams you should see values non-zero in: Render/3D , Video and VideoEnhance.

Next we enable 'low power' encoding.
For that we need to use ffmpeg + spwan (because tvheadend is not supporting this feature natively). This will come with some limitation (like you have to use http instead of htsp for transport, Kodi client will require this feature to be enabled by hand).

Install ffmpeg:

sudo apt install ffmpeg

We check the location of ffmpeg:
which ffmpeg

alin@alin-cm8pcb4r:~$ which ffmpeg
/usr/bin/ffmpeg

We have to create a spawn profile:
[browser menus]:
Configuration / Stream / Stream Profiles --> Add
Type: MPEG-TS Spawn/built-in
Profile name: fh264
Enabled: checked
Default: checked
Comment: ...
Data timeout: 5
Default priority: Normal
Force priority: 0
Restart on error: checked
Continue if descrambling fails: checked
Descrembling timeout: 2000
Switch to another service: checked
Prefered services vide type: None
Command line:

/usr/bin/ffmpeg -hide_banner -err_detect ignore_err -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i pipe:0 -map 0:v -vf 'deinterlace_vaapi' -low_power 1 -c:v h264_vaapi -profile:v high -qp:v 28 -map 0:a? -c:a aac -b:a 64k -map 0:s? -c:s copy -fflags +nobuffer+discardcorrupt+genpts+flush_packets -avoid_negative_ts disabled -f mpegts pipe:1

Mime type: video/mp2t
Kill signal (pipe): SIGTERM
Kill timeout: 15
Rewrite Service ID: 0
Rewrite PMT: uncheck
Rewrite PAT: uncheck
Rewrite SDT: uncheck
Rewrite NIT: uncheck
Rewrite EIT: uncheck

Press Create button.

To confirm you are using GPU for trancoding you need to send:

sudo intel_gpu_top

When you don't have any streams open you will see all numbers: 0; after you open streams you should see values zero for Render/3D and non-zero in: Video and VideoEnhance.
Also you shuld see a power consumption differece (CLK freq difference) on first row.
In my particular tests (720p60 mpeg2-->h264):
- without low power (native tvh): 360 --> 410 MHz with average 0.8W
- with low power (ffmpeg): 290 -- 370 MHz with average 0.4W

After we manage to implement low power natively in tvh I will update this tutorial.


Replies (13)

RE: TVHeadend build and install on Lubuntu 20.04 64bit with iGPU 9+ (for gpu transcoding) - Added by saen acro almost 2 years ago

https://www.cpu-monkey.com/en/
replace with
https://www.cpu-world.com

Why you need desktop OS when, can use server OS with Kodi GUI?
less services more free memory.

RE: TVHeadend build and install on Lubuntu 20.04 64bit with iGPU 9+ (for gpu transcoding) - Added by Alin Gherghescu almost 2 years ago

Thank you for providing your feedback.

saen acro wrote:

https://www.cpu-monkey.com/en/
replace with
https://www.cpu-world.com

This is a very good source of info ... there is only one info that I could not find: iGPU encoders/decoders available. cpu-monkey has a "Hardware Codec support' section very useful to select a CPU (when you have a target encoding scheme in mind, before you have the HW).

Why you need desktop OS when, can use server OS with Kodi GUI?
less services more free memory.

Frankly I don't know this combination "server OS with Kodi GUI" ... I consider my self a beginner and Lubuntu selection was with 'low resources' in mind. I think this comes down to personal preferences (in the end), and how comfortable each user is with GUI versus CLI. I think is obvious that Server is the most fit option (if you know what to select during install process). The tutorial is less focused on 'Os install + most fit install' and more towards 'If you are a beginner what CPU to select to achieve HW encoding with iGPU'.
For example: how you know (before you buy the CPU) how many streams you will be able to transcode (for a particular combination: as example 1080p h264 --> 1080p h264 30p) in real time? I don't have this answer ... I see (on reports over internet) an increase of the number of streams with increase in 'Shader', 'Execution units' and max GPU CLK. Probably we should start a separate thread in order to report the results (with various CPU) and build a 'database' that can be accessed by users before ordering some particular HW.
I can't continue the tutorial because there seems to be a problem with Intel repository ( I can't install vainfo). Hopefully will be fixed soon.

RE: TVHeadend build and install on Lubuntu 20.04 64bit with iGPU 9+ (for gpu transcoding) - Added by saen acro almost 2 years ago

For NVIDIA there is a big list from PLEX community click
There is a simple way to do GPU benchmark with FFMPEG
/FFMpeg need Intel library's ONEApi /
Run multiple time simultaneous trascoding until frame rate is ~25% more fps then source.

RE: TVHeadend build and install on Lubuntu 20.04 64bit with iGPU 9+ (for gpu transcoding) - Added by Alin Gherghescu almost 2 years ago

saen acro wrote:

/FFMpeg need need Intel library's ONEApi /

This is only for Gen11+; for Gen9+ (up to 11) I was planing to use ffmpeg + libmfx for QSV. VAAPI should work without problems even with 'stock ffmpeg'.

RE: TVHeadend build and install on Lubuntu 20.04 64bit with iGPU 9+ (for gpu transcoding) - Added by Alin Gherghescu almost 2 years ago

saen acro wrote:

https://github.com/Syllo/nvtop
to monitor performance/ load of GPU

unfortunately requires kernel 5.19 ... the app is very interesting.

RE: TVHeadend build and install on Lubuntu 20.04 64bit with iGPU 8+ (for gpu transcoding) - Added by denis joshua about 1 year ago

Alin, thanks a lot for your post about decoding (mersi mult :-)
I just want to ask if it's possible to use it when I have TVH installed in docker please...
It is possible ?
I use a Nuc with a i7 CPU and Iris Plus Graphics 650 (rev 06) GPU,
and Astrometa DVB-T2 Tuner.

Thanks in advance
Denis

RE: TVHeadend build and install on Lubuntu 20.04 64bit with iGPU 8+ (for gpu transcoding) - Added by Alin Gherghescu 11 months ago

Sorry, I am not using dockers ... I don't have experience with dockers.

RE: TVHeadend build and install on Lubuntu 20.04 64bit with iGPU 8+ (for gpu transcoding) - Added by denis joshua 11 months ago

Thanks a lot... I'll try on Ubuntu that I have installed on that NUC
I so that the Media SDK is deprecated,
do you know if will this work also using Intel® ?
https://www.intel.com/content/www/us/en/docs/onevpl/upgrade-from-msdk/2023-1/overview.html

Thanks again
Denis

RE: TVHeadend build and install on Lubuntu 20.04 64bit with iGPU 8+ (for gpu transcoding) - Added by Alin Gherghescu 11 months ago

Can you tell me the CPU model name (use 'lscpu').
Example output:
Model name: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz

What Ubuntu is installed?
I assume you are trying to transcode: what input resolution/codec into what resolution/codec? How many simultaneous streams?

RE: TVHeadend build and install on Lubuntu 20.04 64bit with iGPU 8+ (for gpu transcoding) - Added by denis joshua 11 months ago

When I snd lscpu command there is a lot of thinks:

Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         39 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  4
  On-line CPU(s) list:   0-3
Vendor ID:               GenuineIntel
  Model name:            Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
    CPU family:          6
    Model:               142
    Thread(s) per core:  2
    Core(s) per socket:  2
    Socket(s):           1
    Stepping:            9
    CPU max MHz:         4000.0000
    CPU min MHz:         400.0000
    BogoMIPS:            6999.82
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds                         _cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_a                         djust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities
Virtualization features: 
  Virtualization:        VT-x
Caches (sum of all):     
  L1d:                   64 KiB (2 instances)
  L1i:                   64 KiB (2 instances)
  L2:                    512 KiB (2 instances)
  L3:                    4 MiB (1 instance)
NUMA:                    
  NUMA node(s):          1
  NUMA node0 CPU(s):     0-3
Vulnerabilities:         
  Gather data sampling:  Mitigation; Microcode
  Itlb multihit:         KVM: Mitigation: VMX disabled
  L1tf:                  Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
  Mds:                   Mitigation; Clear CPU buffers; SMT vulnerable
  Meltdown:              Mitigation; PTI
  Mmio stale data:       Mitigation; Clear CPU buffers; SMT vulnerable
  Retbleed:              Mitigation; IBRS
  Spec rstack overflow:  Not affected
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl and seccomp
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; IBRS, IBPB conditional, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected
  Srbds:                 Mitigation; Microcode
  Tsx async abort:       Not affected

I use Ubuntu 22.04 on that NUC.
And a tuner "Astrometa DVB-T2 Tuner." via USB.
I need only one streaming of romanian DIGI channel.
At my home in Romania I have a fiber modem of DIGI and I take the DVB-C from that one.

I don't need a 4K or high quality streaming... I just need a clean HD image without interruptions (like now).
Now I have TVH in a docker, but I will install it on the primary OS in some days,
but I don't know witch step by step guide to use.
Is better if I compile it for my OS or I can use a .deb please ?

Thanks a lot for the help
Denis

RE: TVHeadend build and install on Lubuntu 20.04 64bit with iGPU 8+ (for gpu transcoding) - Added by Alin Gherghescu 11 months ago

I installed latest tvheadend to Lubuntu 22.04, I can share my notes.
I can share with you the deb generated ... but is not wise to install deb-s that are shared by users on forums :) .
deb was compiled with:

alin@alin-nuc11pahi5:~$ uname -a
Linux alin-nuc11pahi5 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Anyway that will only save you few commands ... so my advise is to follow commands from my notes (in that order).

If you want to stay with containers (for some reason), You should know that there is another option: Jellyfin.
https://jellyfin.org/docs/general/installation/container
https://hub.docker.com/r/linuxserver/jellyfin
make sure you install/read:
https://jellyfin.org/docs/general/administration/hardware-acceleration/
https://jellyfin.org/docs/general/administration/hardware-acceleration/intel
you will need to connect Jellyfin to tvheadend using:
https://jellyfin.org/docs/general/server/plugins/tvheadend/
In this case Jellyfin will trancode and tvheadend will deliver the video/audio with 'pass' (without any transformation/change).
Personally I didn't liked the clients for Jellyfin ... but you might have a different opinion.

lubuntu_22.04_master-ver3 -web.txt (22 KB) lubuntu_22.04_master-ver3 -web.txt instructions to install tvheadend to Lubuntu 22.04
tvheadend_4.3-2186~g4825b8414~jammy_amd64.deb (15.7 MB) tvheadend_4.3-2186~g4825b8414~jammy_amd64.deb tvheadend_4.3-2186_compiled_with_5.15.0-76-generic #83

RE: TVHeadend build and install on Lubuntu 20.04 64bit with iGPU 8+ (for gpu transcoding) - Added by denis joshua 11 months ago

Thanks a lot for your help,
as soon as I'll have some time (after christmas days :-),
I'll try to make some updates.

I think I'll try the codec first, and if will work, I'll try the TVH,

Thanks again
Denis

    (1-13/13)