There are a few good tutorials on these forums explaining how to build TVHeadend on various platforms.
Creating a .deb installer using the TVHeadend Autobuild script...
Ubuntu 14.04LTS x86_64 by saen acro
https://tvheadend.org/d/4492-manual-building-deb-packages-on-clean-ubuntu-or-other-debian-distros
Ubuntu 22.04 x86_64 by Jonas Lang https://tvheadend.org/d/8133-tvheadend-build-and-install-on-ubuntu-22-04-64-bit-x86_64-platform-for-beginners
Manual compilation steps are listed here by Dave Pickles https://tvheadend.org/d/8133-tvheadend-build-and-install-on-ubuntu-22-04-64-bit-x86_64-platform-for-beginners?r=48009#message-48009
Recently I managed to build TVHeadend on a Pi 4 running Ubuntu 22.04.1 arm 64-bit.
My build has the same features and options as the pre-built packages Michael Marley makes available on his PPA
https://launchpad.net/~mamarley/+archive/ubuntu/tvheadend-git
Here are some instructions to explain what I did:
Instructions
Install fresh Ubuntu 22.04.1 and update /boot/firmware/config.txt
• I downloaded and set up a fresh install of Ubuntu Server 22.04.1 for Pi 4 64-bit
• Made sure it was up to date
# sudo apt update
# sudo apt upgrade
• Some changes needed to config.txt on the Pi.
# Added when building TVH on Pi 4 running Ubuntu Pi 22.04
# gpu_mem=128
gpu_mem=320
[pi4]
max_framebuffers=2
arm_boost=1
# Added when building TVH on Pi 4 running Ubuntu Pi 22.04
# dtoverlay=vc4-fkms-v3d,cma-128
dtoverlay=vc4-kms-v3d-pi4
This is my complete version now:
• # sudo nano /boot/firmware/config.txt
[all]
kernel=vmlinuz
cmdline=cmdline.txt
initramfs initrd.img followkernel
# Added when building TVH on Pi 4 running Ubuntu Pi 22.04
# gpu_mem=128
gpu_mem=320
[pi4]
max_framebuffers=2
arm_boost=1
# Added when building TVH on Pi 4 running Ubuntu Pi 22.04
# dtoverlay=vc4-fkms-v3d,cma-128
dtoverlay=vc4-kms-v3d-pi4
[all]
# Enable the audio output, I2C and SPI interfaces on the GPIO header. As these
# parameters related to the base device-tree they must appear *before* any
# other dtoverlay= specification
dtparam=audio=on
dtparam=i2c_arm=on
dtparam=spi=on
# Comment out the following line if the edges of the desktop appear outside
# the edges of your display
disable_overscan=1
# If you have issues with audio, you may try uncommenting the following line
# which forces the HDMI output into HDMI mode instead of DVI (which doesn't
# support audio output)
#hdmi_drive=2
# Enable the serial pins
enable_uart=1
# Autoload overlays for any recognized cameras or displays that are attached
# to the CSI/DSI ports. Please note this is for libcamera support, *not* for
# the legacy camera stack
camera_auto_detect=1
display_auto_detect=1
# Config settings specific to arm64
arm_64bit=1
dtoverlay=dwc2
[cm4]
# Enable the USB2 outputs on the IO board (assuming your CM4 is plugged into
# such a board)
dtoverlay=dwc2,dr_mode=host
[all]
# Turn off PWR LED
dtparam=pwr_led_trigger=none
dtparam=pwr_led_activelow=off
# Turn off ACT LED
dtparam=act_led_trigger=none
dtparam=act_led_activelow=off
# Turn off Ethernet ACT LED
dtparam=eth_led0=4
# Turn off Ethernet LNK LED
dtparam=eth_led1=4
Install RPI-Userland
• Rpi-userland is a bunch of support binaries and libraries needed for some of the TVH build options to work.
• However the problem is that these rpi-userland features are not actually currently (Dec 2022) supported AT ALL in 64-bit Pi OSs by the Raspberry Pi foundation. Google why.
• At the present time the only option is to cross compile the 32-bit rpi-userland and apparently some of the libraries work anyway in a 64-bit environment but not all (e.g: MMAL which is needed by TVH to offer a transcoding feature)
• Use this script → build_arm64_rpi_userland.sh
https://gist.github.com/satmandu/c462ab301cbe09bd6e7cf4db7f626727
• For that to work you need to install these packages...
# sudo apt install make cmake clang libgcc1-armhf-cross libc6-armhf-cross libstdc++6-armhf-cross
Decide what TVHeadend build options you want
• I modelled my build on MMarley so I went with these build options as per his build log output.
• Build Logs for the Michael Marley builds are also available from his launchpad.net for instance: https://launchpadlibrarian.net/627632817/buildlog_ubuntu-jammy-arm64.tvheadend_4.3.0~pre+202210071820-0~built202210071932~git81838dbb6~ubuntu22.04.1_BUILDING.txt.gz
--enable-hdhomerun_client --disable-hdhomerun_static --disable-dvbscan --enable-libav \
--disable-ffmpeg_static --enable-libx264 --disable-libx264_static --enable-libx265 --disable-libx265_static \
--enable-libvpx --disable-libvpx_static --enable-libtheora --disable-libtheora_static --enable-libvorbis \
--disable-libvorbis_static --enable-libfdkaac --disable-libfdkaac_static --enable-libopus --disable-libopus_static \
--enable-vaapi --enable-nvenc --enable-omx --enable-dvbcsa --enable-dvben50221 --enable-libsystemd_daemon \
--enable-pcre2 --enable-pngquant --enable-ddci --python=/usr/bin/python3
Install needed packages to build TVHeadend
• I found this to be the hardest part of the build process. Certain packages are needed on your system to build TVHeadend with the options and features specified in the specified build options.
• As explained in the linked tutorials above the best way to do this is by trial and error with repeated attempts to build TVHeadend, reading the error output and being guided about what packages need to be installed.
• In my case I started with the list of packages in the Russell Tobin build script to which I needed to remove some and add others.
• As of Dec 2022 this list of packages is needed to build the current TVHeadend in Ubuntu 22.04.1 (64-bit) on a Pi 4 with the above build options. Over time this list will likely change:
sudo apt install build-essential cmake pkg-config git bzip2 wget gettext debhelper python3 python3-dev python3-pip python3-rpi.gpio python2-minimal \
dvb-apps libraspberrypi-dev libraspberrypi-bin libraspberrypi0 libhdhomerun-dev libvpx-dev libx264-dev libx265-dev libopus-dev libssl-dev \
libavahi-client-dev libavcodec-dev libavcodec-extra libavfilter-dev libavfilter-extra libavformat-dev libavutil-dev libfdk-aac-dev libswscale-dev \
libdvbcsa-dev libswresample-dev libiconv-hook-dev libkqueue-dev liburiparser-dev libcurl4-gnutls-dev libpcre2-dev libpcre3-dev libva-dev libva-drm2 \
libva-x11-2 libsystemd-dev libomxil-bellagio-dev libprotobuf-dev libtcmalloc-minimal4 libgoogle-perftools-dev zlib1g-dev
The Autobuild script
• The build script is based on one by Russel Tobin
https://tvheadend.org/d/4492-manual-building-deb-packages-on-clean-ubuntu-or-other-debian-distros?r=44265#message-44265
#!/bin/bash
#
# Name: buildTVH.sh
#
# Description: Build script for tvheadend on Ubuntu 20.04.1 64bit on Raspberry 4
export LD_LIBRARY_PATH=/opt/vc/lib
BASE=$(dirname "$0")
(
if [ -d "$BASE/tvheadend" ]; then
cd "$BASE/tvheadend"
make distclean
git pull
else
# Ensure you have all needed TVH build packages as per MMarley
# Install rpi-userland libraries / binaries
# I used this script from Satadru Pramanik https://gist.github.com/satmandu/c462ab301cbe09bd6e7cf4db7f626727
cd "$BASE"
git clone -v https://github.com/tvheadend/tvheadend.git tvheadend
cd "$BASE/tvheadend"
fi
# If cross compiling on another system you would specify a target as a parameter to Autobuild.sh below,
# e.g: ./Autobuild.sh -j$(nproc) -t focal-arm64
echo "AUTOBUILD_CONFIGURE_EXTRA=\"\${AUTOBUILD_CONFIGURE_EXTRA:-} --arch=armhf\"" > Autobuild/focal-armhf.sh
echo "DEBDIST=focal" >> Autobuild/focal-armhf.sh
echo "source Autobuild/debian.sh" >> Autobuild/focal-armhf.sh
echo "AUTOBUILD_CONFIGURE_EXTRA=\"\${AUTOBUILD_CONFIGURE_EXTRA:-} --arch=arm64\"" > Autobuild/focal-arm64.sh
echo "DEBDIST=focal" >> Autobuild/focal-arm64.sh
echo "source Autobuild/debian.sh" >> Autobuild/focal-arm64.sh
time (
AUTOBUILD_CONFIGURE_EXTRA="--enable-hdhomerun_client --disable-hdhomerun_static --disable-dvbscan --enable-libav \
--disable-ffmpeg_static --enable-libx264 --disable-libx264_static --enable-libx265 --disable-libx265_static \
--enable-libvpx --disable-libvpx_static --enable-libtheora --disable-libtheora_static --enable-libvorbis \
--disable-libvorbis_static --enable-libfdkaac --disable-libfdkaac_static --enable-libopus --disable-libopus_static \
--enable-vaapi --enable-nvenc --enable-omx --enable-dvbcsa --enable-dvben50221 --enable-libsystemd_daemon \
--enable-pcre2 --enable-pngquant --enable-ddci --python=/usr/bin/python3" \
./Autobuild.sh -j$(nproc)
)
) 2>&1 | tee "$BASE/build.log"
Execute the script
• I saved that script in to: /home/ubuntu/buildir/buildTVH.sh on the Pi 4
• I made it executable:
• # sudo chmod +x /home/ubuntu/buildir/buildTVH.sh
• I ran it like this:
• # sudo /home/ubuntu/buildir/buildTVH.sh
Install TVHeadend from your freshly built .deb installer package
• I used gdebi to do the install
• # sudo apt-get update
• # sudo apt install gdebi
• Replace the .deb file name with which ever file name you have!
• # sudo gdebi /home/ubuntu/buildir/tvheadend_4.3-2049~g1a437c88e_arm64.deb
Optional tests to confirm what features your TVHeadend build has
• Take a look at the TVHeadend build log:
/home/ubuntu/buildir/build.log
• Check what rpi-userland files you got:
# dpkg -L rpiuserland > /home/ubuntu/rpi_userland_features.txt
• With TVHeadend running use this to check what encoders and decoders and registered in your TVHeadend build:
# cat /var/log/syslog | grep tvheadend
Notes
libavresample build errors
• With this build environment you will see hundreds of these warnings during the build output
Package libavresample was not found in the pkg-config search path.
Perhaps you should add the directory containing `libavresample.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libavresample' found
• It doesn't stop TVH from building successfully. Ubuntu 22.04.1 no longer supports libavresample or libavresample-dev instead it has libswresample and libswresample-dev
• I raised a (duplicate) bug request about this https://tvheadend.org/issues/6219 and also asked elsewhere on these forums why these errors appear https://tvheadend.org/d/8170-successful-tvheadend-build-has-many-errors-in-build-output-no-package-libavresample-found
Warning when installing the .deb file with gdebi
• When I ran the gdebi install command I got this error...
• /usr/bin/gdebi:113: FutureWarning: Possible nested set at position 1
• It didn't stop the TVH .deb file from installing correctly. This is a workaround for that warning:
# sudo cp /usr/share/gdebi/gdebi /usr/share/gdebi/gdebi_orig
# sudo sed -i 's|"\[\[.*\]"|"[\\[(](\\S+)/\\S+[\\])]"|' /usr/share/gdebi/gdebi
In Conclusion
• I hope this helps someone and saves them time.
• Comments, feedback or corrections very welcome!