Notes on setting up RPi4 + TV Hat + TVHeadend

This post is not a request for help, but some notes about how I got DVB on my OSMC. I cannot post to the HowTo section. So for the records, I’ll leave them here.

Introduction

Kodi (osmc) can work as a “TV client” (PVR), when configured against an appropriate provider by using digital video broadcasting (DVB) technologies. Next setup will use as a provider the TV terrestrial broadcasting system DVB-T/DVB-T2 which is spread among many contries. If you live in any of these countries, DVB-T/DVB-T2 waveforms may be likely available as a broadcast radio signal that would be generally feed your TV set via an antenna cable. By using the appropriate hardware (a TV Hat), this cable may be plugged into a Raspberry Pi which may tune, demultiplex and provide the digital video streams for Kodi to play.

In this post I will share some notes about how I did set up the whole stuff. However, I won’t get into details about how DVB or TVHeadend works. Think of this post as complementary documentation.

Requirements:

  1. A TV aerial cable with good signal quality. You can test the signal with any TV set that supports digital TV (DVB-T/DVB-T2).

  2. A Raspberry Pi 4. Not necessarily this model, but this is the one I worked with.

  3. A TV Hat. This device may be purchased online and should be connected on top of the the RPi via its pins (GPIO/SPI).

  4. To disable all radio protocols in RPi. This was really important. I disabled Wi-Fi (and Bluetooth) since the Wi-Fi radio signal was corrupting the DVB signal/receiver. At least I would just use a wired network connection for setting this up. You may try to reenable Wi-Fi later.

Install the TV Hat

Simple. Just unplug the RPi from the power source and plug the TV Hat in the pins. The TV hat has pin holes on both sides. Watch some pictures not to plug it the wrong way.

Once connected, just turn on the RPi and grep for dvb or cxd2880 via dmesg.

Install TVHeadend

Now you can proceed to install TVHeadend. In OSMC, you can install it from the app store in the My OSMC section of the kodi settings. This way I installed the version 4.2.8. In the post TVHeadend 4.3 (unstable) install commands - #3 by wbeard52 there is a deb I used to upgrade to version 4.3.

The TVHeadend service, when started, will take control of the DVB adapter (the TV hat) and any other dvb cli tool will not work. So that, it is better to stop and disable the service until we perform some testing.

Checking for signal, muxes and channels

This introduction to the Linux Digital TV API may be helpful to learn a bit about DVB adapters and API in Linux.

TVHeadend includes DVB-T muxes setup files for many areas. Muxes are just sets of TV channels that are bundled and streamed together in some radio frequency (simplified explanation). These files are required to set up the TV adapter to tune the muxes. These files are found in:

/usr/share/tvheadend/data/dvb-scan/dvb-t/

Those files may be outdated for your area (my case). However the required updated information may be found online. For instance, the muxes information for Spain is found in https://wiki2023.mundoplus.tv/tdt.

In my case I had to create a new file for my area. The file format is simple and I did not have to touch any technical property. Moreover, the DVB stream itself should include a Network Information Table (NIT) that provides a list of these channels and will be available once you get to tune one of the muxes. So that, the muxes file is not required to be perfect.

There are some frequency scanners for linux (e.g. w_scan) that could work to generate these muxes files. Nevertheless, I could not make them to work nicely, at least in osmc. Beware that some packages use the old Linux DVB API and may not work for your signal. Better install the dvb-tools package that uses the version 5 and will be used next.

Once we have the freqs and modulation parameters of the muxes, to scan for services (channels), use something like (use your own path):

dvbv5-scan /usr/share/tvheadend/data/dvb-scan/dvb-t/oz-North

This command will start tuning the frequencies in the muxes file and then to scan and print the channels found on these muxes. It will also output another file (dvb_channels.conf) with the list of channels.

If you cannot get here, then go back and recheck.

You can also record a transport stream (TS, the content of the mux) to a file:

dvbv5-zap -c dvb_channel.conf -P -t 60 "A-CHANNEL-NAME" -o raw.ts

and watch the saved stream with:

mpv raw.ts (will play the first channel)

or for channel 3:

mpv raw.ts --vid=3

If you watch nicely the expected video stream, the adapter and muxes file are working fine.

TVHeadEnd setup notes

Start the tvheadend service and connect to it using a browser via the web interface in the port 9981. Something like:

http://192.168.1.38:9981

TVHeadEnd config is stored in /home/osmc/.hts. If you have any trouble setting TVHeadend, you can start over by removing this directory. On the first login this directory will be created and a TVHeadend user/password pair (I think the default is osmc/osmc) will be setup.

The TVHeadend web interface has a lot of options, but they may be hidden since the web interface has three view levels: basic, advanced and expert. Every tab has these three view levels. However, beware that the whole interface has also these three levels. That is, some tabs will be hidden (e.g. EPG Grabber Modules) unless you enable advanced or expert view in the general config:

Configuration > General > Base > Web Interface Settings > Default View Level.

In case that you need to use your own muxes file (there is a dropdown selector for the ones already included), you will either have to copy it in the general muxes directory (see above) or you can also set your own path in:

Configuration > General > Base > Miscellaneous Settings > DVB scan files path.

The TVHeadend documentation also mentions an additional path in /usr/local to scan for muxes files, but this path is not set up in the osmc package (it uses /usr/data instead).

Sometimes you may also need to start over and run the start wizard again. It may be found also in:

Configuration > General > Base > [Start Wizard] (button on top).

You should create a less privileged user for kodi via the wizard or the users menu. This user will be used for kodi to work as a client for TVHeadEnd.

Networks, muxes, services, channels and EPG

These are DVB concepts I will not dive in. Follow next link for a brief introduction.. Anyway, I’ll provide some notes as well.

There is a long list of IPTV channels for Spain in the github project:

GitHub - LaQuay/TDTChannels: Listado de Canales de TV (TDT) en abierto, 100% legal, 100% gratuito // Spanish TV Channels, 100% legal, 100% free.

You may find more IPTV networks in the web and add them to TVHeadEnd, so you get an unified managament interface for terrestrial and web channels.

The electronic program guide (EPG) may also be downloaded from the internet. In my case I managed to add a custom grabber for the EPG data from the TDTChannels above by using the tv_grab_file remote grabber (search google for it). There are instructions on internet about how to add this file as a new EPG grabber module.

Once you have set up all your channels and EPG data, you can try to watch a TV channel. I have tried from the Live TV Player of the web interface (play button in the EPG tab) but it didn’t work. However, I can download the m3uext file from the web interface and just play it with mpv:

mpv ~/Downloads/2090702a66e47316239482069ab0b422

Kodi setup

In Kodi, we just need to enable the TVHeadend plugin via:

Settings > Add-on browser > My add-ons > PVR clients > Tvheadend HTSP client.

Add-on setup has a general setup for the add-on, and specific configs for different providers. Just make sure you are using just one provider config file for the TVHeadend service. Something like:

Edit add-on settings ← this is the general,
Edit “127.0.0.1” [Enabled] ← this one is for TVHeadend.

Point the configuration to your TVHeadend services and setup the previously configured kodi user for TVHeadend.

Enjoy!

1 Like