How to build a MythTV v33 system for a Raspberry Pi 4

For discussion of topics specific to MythTV on Raspberry Pi devices
User avatar
jfabernathy
Senior
Posts: 577
Joined: Wed Feb 18, 2015 2:37 pm
Location: Raleigh, NC
United States of America

How to build a MythTV v33 system for a Raspberry Pi 4

Post by jfabernathy »

This topic will give the instructions to build MythTV v33 for running on a 4GB Raspberry Pi 4 (RPI4) running the latest Bullseye 64 bit based on Debian 11 either as a Frontend only or a combination Frontend/Backend (FE/BE). The MythTV developer team and the Raspberry Pi OS team both have made huge improvments to video routines and drivers. So this doc will only concentrate on v33 and Bullseye 64 bit which means you must have a v33 backend or do the combination build so you will have one on the RPI4. The RPI4 has no issues being a backend. You can easily record 4 TV HD programs from the networked tuners at once while playing back a previously recorded program on the frontend section of the RPI4.

I created this document while building a combo FE/BE so the instructions should be as accurate as possible.

The first part is common to both, so we will start there. We are going to build from source so the latest will always be available for the version we want to work with.

We will be building 'mythtv-light' so the software will be packaged as a .deb file that can be easily installed and upgraded. Specifically, we will be building the latest released version v33 (fixes/33) for RPi OS 64 bit.

However, you may find the version of v33 that you want from the link https://dl.orangedox.com/pCBmBm page for mythtv-light and you can use that. The latest are at: https://dl.orangedox.com/pCBmBm/1bO1JOe ... gB0yPsaTHe

I'll try to keep the v33 Bullseye folders up to date.
However, the instructions below are for v33 Bullesys 64 bit only and may or may not work on anything else.

The hardware being used in this example is:
RPI4 4GB RAM
USB3 to SATA Adapter based on the ASMedia ASM1153E controller
1TB SATA SSD
USB keyboard
FHD HDMI monitor
SiliconDust HDHomeRun Quatro networked ATSC 1.0 tuner (4 tuners) (HDHR)
Ethernet connected to the same network as HDHR with Cat-5e, but WiFi can work if yours is a very good connection.

Using the Raspberry Pi Imager 1.7.1 or newer, select the Bullesys 64bit Lite version since we will not be running a Desktop Environment. Flash the image directly to the SATA SSD using the adapter. Use the setting of Imager to select to enable ssh and assign a password.

On first boot, log into the RPI4 using 'ssh' and run "sudo apt update && sudo apt upgrade -y" to upgrade to the latest OS software. We recommend using ssh from another PC because this will be easier if we can cut-and-paste some of the commands.

Next run "sudo raspi-config" and set the following:
System Options -> Hostname
System Options -> Boot / Auto Login -> Console Autologin
Localization, for this example, set for en_US.UTF-8, America/New_York
If using WiFi, setup the wifi SSID and password.

We need to setup the dependencies and clone the repositories. You can get the background by looking at some MythTV wiki pages, but I'll give the instructions to follow from those pages.
https://www.mythtv.org/wiki/Build_from_Source
https://github.com/MythTV/packaging/tre ... /deb-light
https://github.com/MythTV/ansible

Get the dependencies:

Code: Select all

sudo apt install git ansible
git clone https://github.com/MythTV/ansible
cd ansible
./mythtv.yml --limit=localhost
cd
Clone the MythTV repository:

Code: Select all

mkdir ~/build
cd build
git clone https://github.com/MythTV/mythtv.git mythtv
cd mythtv
git checkout fixes/33
Clone the MythTV packaging repository:

Code: Select all

cd ~/build
git clone https://github.com/MythTV/packaging.git
cd packaging
git checkout fixes/33

Code: Select all

cd ~/build/mythtv/mythtv
../../packaging/deb-light/build_package.sh
Press enter to first question about 'Please supply destination....

Go get a beer while it compiles. It could take a while (1 hour 56 minutes on RPI4 overclocked to 2.0Ghz), so maybe several beers.

Code: Select all

cd ../..
The mythtv-light_33.1-12-gc4b7e4c433-0_arm64_bullseye.deb in that directory may be a different version but the name should be similar.

Code: Select all

sudo apt install ./mythtv-light_33.1-12-gc4b7e4c433-0_arm64_bullseye.deb
At this point the MythTV software is installed and if you only want a frontend then you are done. You can create and run the run_mythfrontend.sh script that is documented later and use the search function to find the remote backend, assuming you setup the backend to support remote frontends.

If you want a combo FE/BE, then we have to setup the backend now.

There is a utility to make this easier so clone the following repository:

Code: Select all

cd
git clone https://github.com/MikeB2013/pi-utils.git
cd pi-utils
edit pi-mythbackend-helper.sh

Make the following changes:

Code: Select all

mythtv_git_branch=fixes/33
php_version="7.4"
Now run the script (do not use sudo as that is included in commands in the script that need sudo):

Code: Select all

./pi-mythbackend-helper.sh
reboot
The Electronic Program Guides (EPG) received over-the-air (OTA) are not ideal and we will not be using them here. We will be using SchedulesDirect (SD) EPG. XMLTV will be used to gather the EPG from SD. In this case, it will be for OTA ATSC 1.0 TV. We will use the XMLTV grabber called 'tv_grab_zz_sdjson_sqlite' and follow the instructions at:https://www.mythtv.org/wiki/XMLTV.

This must be run as user 'mythtv'

Code: Select all

sudo su mythtv
cd
tv_grab_zz_sdjson_sqlite --manage-lineups --config-file $HOME/.mythtv/SD.xmltv
You can at this point add a lineup to your account or use your existing lineup.

Then select the "Initialize/update the local database"
Take the defaults on the next several questions until it exits.

Code: Select all

tv_grab_zz_sdjson_sqlite --configure --config-file $HOME/.mythtv/SD.xmltv
Take the default on database name/location.

Select the Lineup. If you only have one it will be listed and you can reply yes.

Take the defaults until the command exits.

Code: Select all

tv_grab_zz_sdjson_sqlite --days 0 --config-file $HOME/.mythtv/SD.xmltv
tv_grab_zz_sdjson_sqlite --manage-lineups --config-file $HOME/.mythtv/SD.xmltv
Select 'Manage database lineup channel selection'
Confirm your lineup.
Choose which channels are selected. Walk thru the channels and select yes or no.

When you're done with the list of channels, just exit.
Exit back to user 'pi' with 'exit'

At this point we are done with ssh and now will run from the RPI4 console.

Now setup the backend with:

Code: Select all

pi-utils/run_mythsetup.sh
Under 1. General -> Host Address Backend Setup set Security PIN to 0000 and Primary IP Address/DNS Name to the IP address of the RPI4 which you can find out by hitting enter and just select it.

Under Job Queue (Backend-Specific) I uncheck 'Allow Transcoding Jobs' and 'Allow Commerical Detection Jobs'. The RPI4 is not good at transcoding and Commerical detection also affects performance. Your mileage may vary.

You can make other changes if you want.

Under 2. Capture cards, select New Capture Card 4 times since we have a 4 tuner HDHomerun. The first select of New Capture Card takes some time comparied to the next 3, so wait.

At each New Capture Card entry select HDHomeRun Networked Tuner then press the right arrow and check the tuner you want to use and then right arrow on Recording Options and uncheck Use HDHomeRun for active EIT scan since we are using SchedulesDirect for EPG.

Repeat for the other tuner entries.

Under 4. Video Sources, select New Video Source. It will take a few seconds.Then select the new entry for New Video Source and then select Video Source Name and enter 'SD' which is what we used in our XMLTV setup. Note upper-case 'SD'

For Listings Grabber select Multinational (Schedules Direct JSON Web Service with SQLite D...
Then ESC and save and exit.

Under 5. Input connections select 'MPEG2TS' under Input Name and select 'SD' under Video Source.
Then only on the first Input Connections go to Scan for Channels and go to the bottom and select Scan.
Insert All

ESC and save. Then set the other Input conections up the same, but don't scan for them.

The rest of the default settings of Input connections should work and also allow multi-channel recording for subchannels like 5.1 and 5.2 on the same tuner.

Use 6. Channel Editor if you have some channels you don't want displayed.

Under 7. Storage Group you should fill out at least Default but can do more to suit your needs. Walk the folders for Default to /srv/mythtv/recordings. All of our storage directories in this case are under /srv/mythtv/.

reboot

Now we need to put in some delay mechanism to make sure the HDHomerun tuners are on the network before mythtv-backend.service starts up. There are many ways to do this but the easiest to setup on the RPI4 is setting up a service that waits for a ping of a networking device like the HDHR tuner and have the mythtv-backend.service wait for that service. There is a discussion with the full instructions to implement this service athttps://lists.archive.carbon60.com/myth ... 986#625984
The instructions are cut down to what we will use. First become root user:

Code: Select all

sudo su
Run these commands as root:

Code: Select all

cd /usr/local/bin
wget http://www.jsw.gen.nz/mythtv/wait-until-pingable.py
chmod u=rwx,g=r,o=r wait-until-pingable.py
cd /etc/systemd/system
mkdir mythtv-backend.service.d
chmod u=rwx,g=rx,o=rx mythtv-backend.service.d
cd mythtv-backend.service.d
wget http://www.jsw.gen.nz/mythtv/mythtv-backend-wait-until-pingable.conf
chmod u=rw,g=r,o=r mythtv-backend-wait-until-pingable.conf
cd ..
wget http://www.jsw.gen.nz/mythtv/local-network-pingable.service
chmod u=rw,g=r,o=r local-network-pingable.service
Here you will need to change the text in local-network-pingable.service where it says "switch.jsw.gen.nz" and replace that with the IP address or DNS name of your first network tuner (if the tuner is pingable), or otherwise something on your network such as your switch or router that is normally pingable when your MythTV box is booting.

Use nano or your favorite editor:
nano local-network-pingable.service
Then save the changes and exit from nano or your editor and do these commands:

Code: Select all

systemctl enable local-network-pingable.service
systemctl start local-network-pingable.service
systemctl status local-network-pingable.service
The systemctl status command should show that the local-network-pingable.service has started and the ping worked. If not, fix that before proceeding. Then do these commands:

Code: Select all

systemctl daemon-reload
exit
After that, on boot mythbackend will wait for either the ping to work, or the 30 second timeout specified in the local-network-pingable.service file. If you want to change that timeout, it is the "30" after the ping address.

Now we need to create a command to start the frontend.

Create "~/run_mythfrontend.sh" containing the ONE line below:

Code: Select all

QT_QPA_EGLFS_ALWAYS_SET_MODE="1" QT_QPA_PLATFORM=eglfs QT_QPA_EGLFS_KMS_CONFIG=./pi_mythfrontend.json mythfrontend --noupnp --logpath /tmp
Then create "~/pi_mythfrontend.json" containing:

Code: Select all

{
    "device": "/dev/dri/by-path/platform-gpu-card",
    "outputs": [
        { "name": "HDMI1", "mode": "1920x1080@60" }
    ]
}
Before you execute "./run_mythfrontend.sh" you need to make it executable with "chmod +x run_mythfrontend.sh"

Now we can execute "./run_mythfrontend.sh" and setup and Audio and Video as below:

In Setup -> Audio -> Audio Output Device select "ALSA:hdmi:CARD=vc4hdmi0,DEV=0"
Setup Digital Audio and speakers base on your audio system.

In Setup -> Video -> Playback change what you want but the critical ones are:
Advanced Playback Settings -> Audio Read Ahead (ms) to your needs. Start by using 400.
Change the Current Video Playback Profile to OpenGL Normal and drill down to change Max CPUs to 4 and Deinterlacer Quality (single rate) to Low quality. Do the same for Deinterlacer quality (double rate).

Performance settings.

The RPI4 standard settings are all you need for a good picture. However, you can improve the FPS jitter statistics by overclocking. I have found that the RPI4 can be overclocked and still be reliable. Most all RPI4s can overclock to 2.0 Ghz. The unit in this case is the newest RPI4 stepping and by default on Bullseye runs at 1.85Ghz. More RPI4 overclocking information at https://magpi.raspberrypi.com/articles/ ... erry-pi-4

I overclocked it as follows:

edit /boot/config.txt
add these lines to the file:

Code: Select all

arm_freq=2147
over_voltage=6
gpu_freq=750
Setup fstrim for the SSD

Since we are using a SSD we need to setup automatic trim once a week. The service that controls this is fstrim.service/timer.

Use 'lsusb' to find the vendor and product IDs for your USB3-SATA adapter. Mine is an ASMedia ASM1153E controller (Eluteng adapters) and "lsusb" shows:

Code: Select all

Bus 002 Device 002: ID 174c:55aa ASMedia Technology Inc. ASM1051E SATA 6Gb/s bridge, ASM1053E SATA 6Gb/s bridge...
So I need to create a file in /etc/udev/rules.d/ called 01-asmedia-trim.rules containing:

Code: Select all

# ASMedia ASM1153E controller (Eluteng adapters)
ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="55aa", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"
Enable and start fstrim:

Code: Select all

sudo systemctl enable --now fstrim.timer
Last edited by jfabernathy on Sun Apr 30, 2023 2:08 pm, edited 22 times in total.
User avatar
jfabernathy
Senior
Posts: 577
Joined: Wed Feb 18, 2015 2:37 pm
Location: Raleigh, NC
United States of America

Re: How to build a MythTV v32 system for a Raspberry Pi 4

Post by jfabernathy »

If you see any mistakes or issue with the above post, let me know and I can fix them. I'd like to keep this post current so it can be referenced to others who need some guidance to building MythTV on a RPI4
keef256
Junior
Posts: 39
Joined: Fri Apr 22, 2022 3:38 pm
Great Britain

Re: How to build a MythTV v32 system for a Raspberry Pi 4

Post by keef256 »

I am following these instructions and get to the part about

Code: Select all

cd ~/build/mythtv/mythtv
../../packaging/deb-light/build_package

and all I get is

>


Any help please
mythpi
Junior
Posts: 18
Joined: Thu Jan 13, 2022 3:38 pm
United States of America

Re: How to build a MythTV v32 system for a Raspberry Pi 4

Post by mythpi »

That particular line in this otherwise excellent guide has a typo - it has a trailing single quote which shouldn't be there, and will cause the behavior you describe if you used copy/paste.

The code should read:

Code: Select all

cd ~/build/mythtv/mythtv
../../packaging/deb-light/build_package
Hope this helps.
User avatar
jfabernathy
Senior
Posts: 577
Joined: Wed Feb 18, 2015 2:37 pm
Location: Raleigh, NC
United States of America

Re: How to build a MythTV v32 system for a Raspberry Pi 4

Post by jfabernathy »

mythpi wrote:
Fri Apr 22, 2022 9:09 pm
That particular line in this otherwise excellent guide has a typo - it has a trailing single quote which shouldn't be there, and will cause the behavior you describe if you used copy/paste.

The code should read:

Code: Select all

cd ~/build/mythtv/mythtv
../../packaging/deb-light/build_package
Hope this helps.
Thanks for pointing out the typo. I've edited the OP.
keef256
Junior
Posts: 39
Joined: Fri Apr 22, 2022 3:38 pm
Great Britain

Re: How to build a MythTV v32 system for a Raspberry Pi 4

Post by keef256 »

Thanks
zaphod
Junior
Posts: 17
Joined: Thu Jun 18, 2020 2:31 am
United States of America

Re: How to build a MythTV v32 system for a Raspberry Pi 4

Post by zaphod »

Very nice jfabernathy!

Unfortunately, after taking the prescribed beers, falling asleep, and waking up the next morning - I just get some critical errors that I don't understand. I did try to build v31. So, maybe I will try 32.
Last edited by zaphod on Fri May 13, 2022 4:48 pm, edited 1 time in total.
User avatar
jfabernathy
Senior
Posts: 577
Joined: Wed Feb 18, 2015 2:37 pm
Location: Raleigh, NC
United States of America

Re: How to build a MythTV v32 system for a Raspberry Pi 4

Post by jfabernathy »

These instructions will only work for V32 or non-Bullseye 64 OS's
zaphod
Junior
Posts: 17
Joined: Thu Jun 18, 2020 2:31 am
United States of America

Re: How to build a MythTV v32 system for a Raspberry Pi 4

Post by zaphod »

jfabernathy wrote:
Fri May 13, 2022 1:35 pm
These instructions will only work for V32 or non-Bullseye 64 OS's
I have now tried that too. The first attempt locked up my Pi. It would not respond to ping or keyboard input. The second attempt might have done that for a while too - but if it did, it recovered, and eventually the compile failed. I ran the compile in "screen". So, I only have the tail end of the output, and what's in config_mythtv.out doesn't look complete. I also tried cross compiling from Ubuntu on WSL2 - but that failed too (and it still took over 2 hours). It couldn't find libQt5Gui.so.5, even though libqt5gui5 was installed, and when I installed libqt5gui5-gles, it complained:

Vulkan is not supported with this version of Qt
Error! QtScript headers not found

Jfabernathy, could you possibly make your compiled packages available? You provided a link on some other post - but the link is dead.
zaphod
Junior
Posts: 17
Joined: Thu Jun 18, 2020 2:31 am
United States of America

Re: How to build a MythTV v32 system for a Raspberry Pi 4

Post by zaphod »

Maybe I was missing libraspberrypi-dev...?

It's called out as a dependency here: https://www.mythtv.org/wiki/Build_from_Source

And I'm installing these too: debhelper quilt dh-python

Ansible didn't catch those dependencies.
User avatar
jfabernathy
Senior
Posts: 577
Joined: Wed Feb 18, 2015 2:37 pm
Location: Raleigh, NC
United States of America

Re: How to build a MythTV v32 system for a Raspberry Pi 4

Post by jfabernathy »

I just built on a clean RPI4 4GB following my instructions above to the letter, no deviations and it worked as expected.Remember the .buildrc file
User avatar
monkeypet
Junior
Posts: 49
Joined: Tue Feb 11, 2014 7:18 pm
United States of America

Re: How to build a MythTV v32 system for a Raspberry Pi 4

Post by monkeypet »

How is the mythtvfrontend mpeg2 playback performance on the Raspberry Pi 4 especially for MPEG2? Better/Worse or the same as the prior version?
User avatar
jfabernathy
Senior
Posts: 577
Joined: Wed Feb 18, 2015 2:37 pm
Location: Raleigh, NC
United States of America

Re: How to build a MythTV v32 system for a Raspberry Pi 4

Post by jfabernathy »

monkeypet wrote:
Sat May 21, 2022 9:10 pm
How is the mythtvfrontend mpeg2 playback performance on the Raspberry Pi 4 especially for MPEG2? Better/Worse or the same as the prior version?
I think it's pretty good. I use it in my RV and don't think about it.
mythpi
Junior
Posts: 18
Joined: Thu Jan 13, 2022 3:38 pm
United States of America

Re: How to build a MythTV v32 system for a Raspberry Pi 4

Post by mythpi »

I have been using a pre-v32 version since February on a 64-bit bullseye OS. In all that time, once I had a case where playback was bad - stuttering significantly every few seconds. I rebooted the frontend, which fixed the problem (presumably something else was running amuck on the system, but I didn't have the opportunity to identify it at the time).

Otherwise, I find the playback quite acceptable on a 4GB Pi4.
User avatar
jfabernathy
Senior
Posts: 577
Joined: Wed Feb 18, 2015 2:37 pm
Location: Raleigh, NC
United States of America

Re: How to build a MythTV v32 system for a Raspberry Pi 4

Post by jfabernathy »

If you use FPS jitter as a metric. V32 is significantly better than v31 on RPI4 Bullseye 64 bit
Post Reply