Linux Crumbs
Simbiotic - A Cyberpunk Thriller Novel

Build a PVR using Raspberry Pi 4, MythTV, & HDHomeRun

Summary

This article is both a tutorial and a proof of concept. The tutorial describes the hardware required and steps involved to set up a MythTV Personal Video Recorder (PVR) as a combined display frontend and recording backend using a Raspberry Pi 4.

Areas covered include:

  • Mythbackend to record Over-The-Air (OTA) broadcast TV shows
  • Mythfrontend to playback recordings
  • Kodi to playback recordings
  • MCE rc6 remote control with ir-keytable
  • Episode guide using OTA Event-Information-Table (EIT)
  • Episode guide using Schedules Direct (subscription based)

The tutorial uses a Raspberry Pi 4 model B computer with 4GB RAM using MythTV v31, a Silicon Dust HDHomeRun Connect dual network tuner, and a Seagate USB3 2TB hard drive. The RPi4 functions as both a frontend to display TV shows and as mythbackend to record TV shows.

At completion of the steps you will be able to concurrently record two TV shows and watch a prior recording.

TL;DR (Too Long; Didn't Read): The RPi4 can work as a MythTV backend for recording Over-The-Air TV broadcasts with some frontend display compromises for watching recordings.

This article was written in January 2021.

Update 2023-03-21: Rebuild PVR with another USB 2TB HDD. Add Appendix B: Enable Closed Captions for MPEG4.

Update 2023-03-12: The USB 2TB HDD failed. This resulted in the loss of all recordings and the OS which were stored on the HDD. The HDD lasted just over 2 years.

In retrospect with SATA HDDs I can check on the drive's health (S.M.A.R.T - Self-Monitoring, Analysis, and Reporting Technology) with a command like sudo /usr/sbin/smartctl -A /dev/sda. Unfortunately I never discovered a way to get similar information from the USB 2TB HDD. This makes it is difficult to know when a USB HDD is starting to fail.

Update 2023-03-08: Change remote key bindings to work better with Kodi: Rectangle slot key == "C"ontext menu, Pause == PlayPause.

Update 2021-05-06: Add draft steps to work around dl.bintray.com package download site being decommissioned.

Update 2021-01-30: Add Completed PVR section and update menu options for MythTV PVR.

Contents

Completed PVR

Following is a picture of the completed RPi4 MythTV PVR in operation.

RPi4 MythTV PVR

Background

First, a word of thanks. MythTV is made possible by volunteers who develop, maintain, and provide assistance with MythTV software, scripts, and packages which make the installation process easier. Thanks goes to all the MythTV developers and users who make using MythTV possible. A special thank you goes out to Peter Bennett for work on the Raspberry Pi and the MythTV-Light packages, Mike Bibbings for the pi-utils scripts, and Jim Abernathy for his MythTV v31 install on RPi4 instructions. Great work everyone!

For quite some time I have been anticipating the ability to run MythTV on less expensive hardware than x86-64 based computers. With the release of the RPi4 with 4 GB of RAM it appears that this capability may have arrived.

Why MythTV?

In 2011 my spouse and I cut the cord on cable TV and have been running MythTV as our primary PVR. I also support three similar PVRs for family members. These PVRs continue to function well.

In 2017 I started running Tvheadend on LibreELEC with Kodi on a RPi3 as a backup PVR. This has enabled me to compare the operation of these two PVR solutions. Following are three differences:

  • MythTV reliably parses MPEG2 recordings and displays Closed Captions (many times CC does not parse and display with Tvheadend/Kodi/LibreELEC)

  • MythTV skip ahead and skip back is instantaneous (skipping not as fast with Tvheadend/Kodi/LibreELEC)

  • MythTV has a separate list of upcoming TV shows and movies that are new premieres for easy perusal and recording rule creation (I did not find this feature with Tvheadend/Kodi/LibreELEC)

These three differences make using MythTV a much more pleasurable experience.

An overview of the steps in this tutorial are:

  1. Install software on SD card (Raspberry Pi OS, MythTV, etc.)
  2. Copy SD card root file system, not boot, to hard drive (HDD/SSD)
  3. Configure software
  4. Enjoy recording and watching TV shows

Hardware Component List

Following is a list of components and their costs in January 2021.

Category Component Cost
RPi4 Kit RPi4 4GB, microSD card, aluminum case, HDMI cables, power supply 180
Keyboard Wireless Mini Keyboard 20
Hard Drive Seagate Backup Plus Slim 2TB External Hard Drive Portable HDD USB 3.0 90
TV Tuner Silicon Dust HDHomeRun Connect network dual tuner 160
Ethernet Cable 10 ft Cat 6 patch cable 10
Grand Total   $460

Note that cheaper RPi4 kits are available that include a case with a fan. I chose a kit with an aluminum case that provides passive cooling (no fan) to eliminate fan noise.

Raspberry Pi 4 MythTV Set Up Steps

A. Download OS and Install on microSD Card

Because this RPi4 will be dedicated to MythtTV we only need the Lite version of the Raspberry Pi OS.

B. Assemble Hardware

Connect all the components keeping in mind:

  • USB hard drive connects to blue USB 3 port ONLY when power is off

  • Micro HDMI cable connects to RPi HDMI 0 port near power port

  • Do not power up RPi at this time

Note if your TV does not have a TV signal strength meter to help with placing an aerial, then you might use an Android device with the HDHomeRun Signal Meter app to experiment and find a good aerial location for receiving Over-The-Air broadcasts.

C. Configure Raspberry Pi OS

  1. Insert microSD card into RPi and power up (connect power cable).

    On first boot the root file system is resized (grown) to use the entire card and then reboots. This option is also available in raspi-config at 6 Advanced Options A1 Expand Filesystem.

  2. Login at raspberrypi login: prompt with username pi and password raspberry.

  3. Run raspi-config tool to configure RPi.

     sudo raspi-config

    Use arrows, space bar, tab, and enter keys to change the following settings:

     1 System Options
        s2 Audio
            0 HDMI 0               # Leave at HDMI 0 or choose Headphones for 3.5mm jack
        S3 Password
            yourpwd                # Set new password for pvr
        S4 Hostname
            rpipvr                 # Use a hostname you prefer
        S5 Boot / Auto Login
            B2 Console Autologin
        S6 Network at Boot
    
     3 Interface Options
        P2 SSH                     # enable SSH server
    
     5 Localisation Options
        L1 Locale
            en_CA.UTF-8            # Use your locale and set as default
        L2 Timezone
            America - Edmonton     # Use your timezone
        L3 Keyboard
            Generic 105-key (Intl) PC     # Use your keyboard
              Other
                English (US)              # To fix tilde ~ key
                  Right Alt (AltGr)
                    No compose key

    Choose Finish and reboot.

  4. Run alsamixer to boost volume for 3.5mm audio

     alsamixer

    Use F3 for View: [Playback] for Item: Headphone and use Up arrow to increase volume to 100

    Use ESC key to exit

    Optionally test volume with:

     speaker-test -c2 -twav

    Use Ctrl+C to stop.

D. Assign Static IP address

To enable this RPi to provide MythTV services to other computers, we set up a static IP address for the RPi.

This also helps us avoid connection issues that can arise between the MythTV frontend(s), backend(s), and database when a dynamically assigned DHCP IP address changes.

For this tutorial we use static IP address: 192.168.1.60

Either use the following steps to set a static IP address on the RPi, or consider using a Router IP Address Reservation.

  1. Create a backup of the /etc/dhcpd.conf file.

     sudo cp -p /etc/dhcpcd.conf /etc/dhcpcd.conf.backup
  2. Edit /etc/dhcpd.conf file.

     sudo nano /etc/dhcpcd.conf
  3. Copy and paste to the end of the file the following lines:

    ----- begin lines -----

    interace eth0
    static ip_address=192.168.1.60/24
    static routers=192.168.1.1
    static domain_name_servers=192.168.1.1
    static domain_search=
    noipv6
    

    ----- end lines -----

    Note: Make any necessary adjustments to the configuration (i.e., change IP address, change router/gateway address, change DNS servers) depending on your desired network configuration.

  4. Save file and exit editor with Ctrl+X, Y, and Enter key presses.

  5. Reboot RPi for IP address change to take effect.

     sudo reboot

    This reboot sets the static IP address. You can use an SSH connection from your main computer to the RPi to make it easier to perform some of the steps while you reference a web browser page.

    An SSH connection from a terminal window can be established as follows:

    ssh pi@192.168.1.60

E. Install MythTV Software

  1. Install git.

     sudo apt update        # refresh package list
     sudo apt install git
  2. Clone the pi utility scripts.

     git clone https://github.com/MikeB2013/pi-utils.git
  3. Install mythtv-light frontend and backend mythTV version 31.

    Use steps after greyed out strike-through text.

    2021-05-06: dl.bintray.com decommissioned so greyed out steps no longer valid.

    Old Install mythtv-light frontend and backend mythTV version 31.

    ~/pi-utils/pi-setup_mythtv_31.sh

    • At initial MythTV Setup for Raspberry Pi screen choose No so we can manually choose options.

    • At Install mythplugins prompt choose No.

    • At Auto start mythfrontend prompt choose No.

    • At Install mythbackend scripts prompt choose Yes.

    • At Enable SSH prompt choose Yes.

    Installation can take a while so you might wish to grab a beverage while you wait.

    At time of writing the MythTV light package was version 31.0-54-g445cf1fe6b-0.

    No need to reboot yet as we've more software to install. We'll reboot later.

    New Install mythtv-light frontend and backend mythTV version 31.

    • Download mythtv-light_31*.deb package for Raspberry Pi from:

      Orangedox   MythTV-Light -> raspberry-pi -> v31

    • Install package with:

         sudo dpkg -i ~/Downloads/mythtv-light_31*.deb

      If errors encountered then install dependencies and re-install with:

         sudo apt install -f
         sudo dpkg -i ~/Downloads/mythtv-light_31*.deb
  4. Install mythbackend, mythweb , database, xmltv, and related software.

     ./pi-mythbackend-helper.sh

    For reference only the tail portion of the console output follows:

    ----- begin console output -----

     xmltv has been installed and updated to latest version
    
     mythtv log rotation has been setup
    
     daily backup of mythconverg database has been setup
    
     **************************************************
    
     If running headless on Pi4, no monitor connected on hdmi port
      put 'hdmi_ignore_cec=1' in '/boot/config.txt' and reboot
    
     Storage Group directories have been created in '/srv/mythtv/'
     Directories 'banners coverart fanart recordings streaming videos bare-client db_backups  livetv  screenshots  trailers music musicart'
     Use mythtv-setup Storage Directories to setup those required
    
     For mythtv prior to fixes/31, use systemctl commands to stop or start mythtv-backend
       To stop  'sudo systemctl stop mythtv-backend'
       To start 'sudo systemctl start mythtv-backend'
       Sometimes mythtv-backend maybe 'failed' by systemd, to re-enable use
        'sudo systemctl daemon-reload' followed by
        'sudo systemctl start mythtv-backend'
    
     For mythtv from fixes/31, use script 'run_mythsetup.sh'
      which automatically stops mythbackend, starts mythtv-setup and restarts mythbackend
    
     xmltv installed and updated to latest version
     When using xmltv e.g. tv_grab_zz_sdjson
     mythfilldatabase arguments should use '--no-allatonce'
    
     mythconverg database password 'mythtv'
     Latest version of this script is available from:
     https://github.com/MikeB2013/pi-utils
    
     References:
       https://www.mythtv.org/wiki/MythTV_Light
       https://www.mythtv.org/wiki/Database_Setup
       https://www.mythtv.org/wiki/Build_from_Source
       https://www.mythtv.org/wiki/Systemd_mythbackend_Configuration
       https://www.mythtv.org/wiki/Setup_Storage_Directories
       https://www.mythtv.org/wiki/Mythfilldatabase
    
     Finished setting up for mythtv-backend - Please reboot

    ----- end console output -----

  5. Before rebooting, this is a good point to change some boot parameters.

    Edit /boot/config.txt file.

     sudo nano /boot/config.txt

    If you do not use CEC (TV remote controls RPi) then change or add the following lines to the file.

     # Disable CEC.  Also good for running RPi headless
     hdmi_ignore_cec=1

    Save file and exit editor with Ctrl+X, Y, and Enter key presses.

  6. Set storage group directory preference.

    I prefer using /data/mythtv/ instead of /srv/mythtv/ so I renamed the directory.

     sudo mv /srv /data
  7. Reboot.

     sudo reboot

At this point all the MythTV software is installed but not configured. We will configure MythTV in a later step.

F. Install Kodi and Other Software

  1. Install kodi.

     sudo apt install kodi kodi-pvr-mythtv kodi-inputstream-adaptive
  2. Enable support for mounting common portable media file systems.

     sudo apt install exfat-fuse exfat-utils

    NTFS and FAT file system support is installed by default.

G. Configure MCE Remote Control support

There are at least two different ways to handle infrared remote controls: lirc, and ir-keytable. The two main differences are:

  • lirc permits custom key mapping for each application
  • ir-keytable works like a keyboard and has a single key mapping for all apps

For this setup I chose to use ir-keytable because it has the added benefit that I can use the MCE remote control to recall commands in the console with the up arrow, and execute with the OK or Enter keys.

The ir-keyable method works well with the menu we will create later and has been confirmed to work with the following three MCE RC6 remote controls:

  • Mediagate MG-IR02BK MCE rc6 remote control
  • Rosewill RRC-126 MCE rc6 remote control
  • Philips 5100 Vista MCE rc6 remote control

The MCE RC6 remote control keys are be bound to the following MythTV PVR functions as shown in the following diagram:

PVR Remote Schematic

  1. Install ir-keytable package.

     sudo apt install ir-keytable
  2. Confirm the USB remote receiver is recognized.

     ir-keytable

    Output from my remote control follows:

    Found /sys/class/rc/rc0/ (/dev/input/event4) with:
            Name: Media Center Ed. eHome Infrared Remote Transceiver (147a:e03e)
            Driver: mceusb, table: rc-rc6-mce
            LIRC device: /dev/lirc0
            Attached BPF protocols:
            Supported kernel protocols: other lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 sharp xmp imon
            Enabled kernel protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 sharp xmp imon
            bus: 3, vendor/product: 147a:e03e, version: 0x1201
            Repeat delay = 500 ms, repeat period = 125 ms
  3. Fix UDEV rule.

    Edit /lib/udev/rules.d/60-ir-keytable.rules file.

     sudo nano /lib/udev/rules.d/60-ir-keytable.rules

    Comment out the existing ACTION line with a # hash mark.

    #ACTION=="add", SUBSYSTEM=="rc", RUN+="/usr/bin/ir-keytable -a /etc/rc_maps.cfg -s $name"

    Copy and paste the following line after the above commented out line.

    ACTION=="add", SUBSYSTEM=="input", SUBSYSTEMS=="rc", KERNEL=="event*", ENV{.rc_sysdev}="$id", RUN+="/usr/bin/ir-keytable -a /etc/rc_maps.cfg -s $env{.rc_sysdev}"

    Save file and exit editor with Ctrl+X, Y, and Enter key presses.

  4. Create /etc/rc_keymaps/rc6_mce.toml file.

    For reference I started with the original source in the /lib/udev/rc_keymaps/rc6_mce.toml file and made modifications to map the keys to MythTV functions.

     sudo nano /etc/rc_keymaps/rc6_mce.toml

    Copy and paste the following lines:

    ----- begin rc6_mce.toml file -----

    [[protocols]]
    name = "rc6_mce"
    protocol = "rc6"
    variant = "rc6_mce"
    [protocols.scancodes]
    0x800f0400 = "KEY_0"        # was "KEY_NUMERIC_0"
    0x800f0401 = "KEY_1"        # was "KEY_NUMERIC_1"
    0x800f0402 = "KEY_2"        # was "KEY_NUMERIC_2"
    0x800f0403 = "KEY_3"        # was "KEY_NUMERIC_3"
    0x800f0404 = "KEY_4"        # was "KEY_NUMERIC_4"
    0x800f0405 = "KEY_5"        # was "KEY_NUMERIC_5"
    0x800f0406 = "KEY_6"        # was "KEY_NUMERIC_6"
    0x800f0407 = "KEY_7"        # was "KEY_NUMERIC_7"
    0x800f0408 = "KEY_8"        # was "KEY_NUMERIC_8"
    0x800f0409 = "KEY_9"        # was "KEY_NUMERIC_9"
    0x800f040a = "KEY_DELETE"
    0x800f040b = "KEY_ENTER"
    0x800f040c = "KEY_SLEEP"
    0x800f040d = "KEY_M"        # was "KEY_MEDIA"
    0x800f040e = "KEY_F9"       # was "KEY_MUTE"
    0x800f040f = "KEY_I"        # was "KEY_INFO"
    0x800f0410 = "KEY_F11"      # was "KEY_VOLUMEUP"
    0x800f0411 = "KEY_F10"      # was "KEY_VOLUMEDOWN"
    0x800f0412 = "KEY_CHANNELUP"
    0x800f0413 = "KEY_CHANNELDOWN"
    0x800f0414 = "KEY_DOT"      # was "KEY_FASTFORWARD"
    0x800f0415 = "KEY_COMMA"    # was "KEY_REWIND"
    0x800f0416 = "KEY_P"        # was "KEY_PLAY"
    0x800f0417 = "KEY_R"        # was "KEY_RECORD"
    0x800f0418 = "KEY_PLAYPAUSE"    # was "KEY_PAUSE"
    0x800f0419 = "KEY_STOP"   # Use "KEY_STOP" for kodi, "KEY_ESC" for mythfrontend
    0x800f041a = "KEY_Z"        # was "KEY_NEXT"
    0x800f041b = "KEY_Q"        # was "KEY_PREVIOUS"
    0x800f041c = "KEY_D"        # was "KEY_NUMERIC_POUND"
    0x800f041d = "KEY_NUMERIC_STAR"
    0x800f041e = "KEY_UP"
    0x800f041f = "KEY_DOWN"
    0x800f0420 = "KEY_LEFT"
    0x800f0421 = "KEY_RIGHT"
    0x800f0422 = "KEY_ENTER"    # was "KEY_OK"
    0x800f0423 = "KEY_ESC"      # was "KEY_EXIT"
    0x800f0424 = "KEY_C"        # was "KEY_DVD"
    0x800f0425 = "KEY_TUNER"
    0x800f0426 = "KEY_S"        # was "KEY_EPG"
    0x800f0427 = "KEY_W"        # was "KEY_ZOOM"
    0x800f0432 = "KEY_MODE"
    0x800f0433 = "KEY_PRESENTATION"
    0x800f0434 = "KEY_EJECTCD"
    0x800f043a = "KEY_BRIGHTNESSUP"
    0x800f0446 = "KEY_TV"
    0x800f0447 = "KEY_PAGEDOWN" # was "KEY_AUDIO"
    0x800f0448 = "KEY_PVR"
    0x800f0449 = "KEY_PAGEUP"   # was "KEY_CAMERA"
    0x800f044a = "KEY_END"      # was "KEY_VIDEO"
    0x800f044c = "KEY_LANGUAGE"
    0x800f044d = "KEY_T"        # was "KEY_TITLE"
    0x800f044e = "KEY_PRINT"
    0x800f0450 = "KEY_HOME"     # was "KEY_RADIO"
    0x800f045a = "KEY_T"        # was "KEY_SUBTITLE"
    0x800f045b = "KEY_W"        # was "KEY_RED"
    0x800f045c = "KEY_GREEN"
    0x800f045d = "KEY_YELLOW"
    0x800f045e = "KEY_T"        # was "KEY_BLUE"
    0x800f0465 = "KEY_POWER2"
    0x800f0469 = "KEY_MESSENGER"
    0x800f046e = "KEY_PLAYPAUSE"
    0x800f046f = "KEY_PLAYER"
    0x800f0480 = "KEY_BRIGHTNESSDOWN"
    0x800f0481 = "KEY_PLAYPAUSE"

    ----- end rc6_mce.toml file -----

    Save file and exit editor with Ctrl+X, Y, and Enter key presses.

  5. Reboot to activate remote control key mappings.

     sudo reboot
  6. Test keypresses are recognized (Use Ctrl+C to abort).

     ir-keytable -t

    If all is working properly then you should see the remote keypresses being recognized and printed to the screen.

    Use Ctrl+C to exit.

For those who might be setting up additional MythTV instances, now is a good time to perform an image backup. This will help to maintain consistency in software versions. To shutdown immediately use the sudo shutdown -h now command.

H. Migrate root "/" file system from microSD to USB HDD

The purpose of this step is to copy all of our work from the microSD card root "/" file system to a USB hard drive (HDD/SSD).

USB hard drives are much faster with read and write operations than the microSD cards. Moreover this additional speed is an absolute requirement for being able to record and watch North American OTA ATSC MPEG2 1080i/720p content which can be up to 9 GB of data per hour.

This step will overwrite the hard drive attached to the RPi.

Proceed only if you are okay with losing access to all data on the hard drive.

    sudo ./pi-SDtoHD-helper.sh -d /dev/sda

Agree with all prompts regarding erasure and copying from microSD to hard drive.

For reference the tail portion of the console output follows:

----- begin console output -----

total size is 2,783,307,814  speedup is 1.00
Configuring boot from /dev/sda1
Commenting out old root partition in /etc/fstab, adding new one
Your new root drive is currently accessible under /mnt.
You may wish to check:
  /mnt/etc/fstab
  /boot/cmdline.txt
Target partition PARTUUID (/boot/cmdline.txt): 1f6d240b-4bc9-42df-845c-ca530bfa340e
Target partition UUID (/mnt/fstab): b2466ba0-f892-4887-8661-5e7ffc64934a
Please reboot to use the new SSD/HD, type sudo reboot

----- end console output -----

To further reduce wear and tear on the hard drive I add the -nodiratime parameter to the root "/" file system mount entry in the fstab file.

  1. Edit fstab file.

     sudo nano /mnt/etc/fstab
  2. Locate the line similar to:

    /dev/disk/by-uuid/b2466ba0-f892-4887-8661-5e7ffc64934a / ext4 defaults,noatime 0 1

  3. Append the following parameter immediately after defaults,noatime

     ,nodiratime

    It should now look similar to:

    /dev/disk/by-uuid/b2466ba0-f892-4887-8661-5e7ffc64934a / ext4 defaults,noatime,nodiratime 0 1

  4. Save file and exit editor with Ctrl+X, Y, and Enter key presses.

  5. Reboot to use the new SSD/HDD.

     sudo reboot

I. MythTV-Setup for HDHR tuners with OTA EIT EPG

Here we set up the mythbackend PVR with HDHomeRun network tuners for an OTA Event-Information-Table (EIT) episode guide.

Note that the EIT guide information where I live is incomplete and often for less than 24 hours so in a subsequent section I will describe how to use set up a Schedules Direct EPG.

  1. Run Myth setup. (This is a GUI so run on RPi console)

     ~/run_mythsetup.sh

    Configure MythTV Backend

  2. When backend GUI starts configure the following:

    Note that navigation is via the arrow keys, tab, shift+tab and escape keys. Enter key or Space bar often pops up list or toggles setting.

    
    # ####################
    # Set security PIN and disable transcoding jobs
    #
    1. General
         Host Address Backend Setup
           Security PIN (required):                     0000
           Primary IP Address/DNS Name:                 192.168.1.60
         .
         Miscellaneous Settings
           File Management Settings
             Delete Files Slowly:                       Enable
         .
         Job Queue (Backend-Specific)
           Maximum simultaneous jobs on this backend:   1         # default is 1
           Allow commercial-detection jobs:             Enable    # disable to lighten computer load
           Allow Transcoding jobs:                      Disable
         .
         Program Schedule Downloading Options
           Automatically update program listings:       Enable    # default is enabled
       # Use ESC key to **Save and Exit**
    .
    # ####################
    # Create 2 capture cards for a dual tuner HDHomeRun
    #
    # Create 1st capture card
    2. Capture cards
         (New Capture Card)                                      # Choose once - **slowly** creates "New Capture Card" entry
         New Capture Card                                        # Choose this new entry and arrow right
           Card Type:                HDHomeRun Networked Tuner   # Space bar for drop-down list
             HDHomeRun Networked Tuner                           # Arrow right
               Use HDHomeRun 104F3D29 (...):           Enable    # Note that 104F3D29 varies with HDHomeRun device
               Recording Options:                                # Arrow right
                 Use HD HomeRun for Active EIT Scan:   Enable    # Only enable one
       # Use ESC key to **Save and Exit**
    .
    # Create 2nd capture card
    2. Capture cards
         (New Capture Card)                                      # Choose once - **slowly** creates "New Capture Card" entry
         New Capture Card                                        # Choose this new entry and arrow right
           Card Type:                HDHomeRun Networked Tuner   # Space bar for drop-down list
             HDHomeRun Networked Tuner                           # Arrow right
               Use HDHomeRun 104F3D29 (...):           Enable    # Note that 104F3D29 varies with HDHomeRun device
               Recording Options:                                # Arrow right
                 Use HD HomeRun for Active EIT Scan:   Disable   # Only enable one
       # Use ESC key to **Save and Exit**
    .
    # ####################
    # Create entry for OTA EIT episode guide
    #
    4. Video Sources
         (New Video Source)              # Choose once - **after a long wait** creates "New Video Source" entry
         New Video Source                # Choose this new entry
           Video Source Name:         EIT EPG
           Listings Grabber:          Transmitted Guide Only (EIT)
           Channel Frequency Table:   us-bcast
       # Use ESC key to **Save and Exit**
    .
    # ####################
    # Associate each capture card with a video source
    #
    # Associate 1st capture card
    5. Input Connections
         [HDHOMERUN: 104F3D29](None)->(None)
           Input Name:                   MPEG2TS
           Display Name:                 HDHR1     # 1st HDHomeRun tuner
           Video Source:                 EIT EPG
           Interactions between inputs       # Arrow right
             Max recordings:             2   # default is 1
             Schedule order:             1   # Ascending order, increment by capture card max recordings
             Live TV order:              3   # Descending order, to avoid conflicts with scheduled recordings
                                             # Arrow left to go back one level
           .
           Scan for Channels                 # Choose this **after** above.
             Scan                            # Scroll down and choose Scan.
                                             #   Wait while scan proceeds.
                                             # When scan complete at "Found X channels" choose "Insert All".
                                             # Choose "OK"
                                             # Choose "Exit"
       # Use ESC key to **Save and Exit**
    .
    # Associate 2nd capture card
    5. Input Connections
         [HDHOMERUN: 104F3D29](None)->(None)
           Input Name:                   MPEG2TS
           Display Name:                 HDHR2     # 2nd HDHomeRun tuner
           Video Source:                 EIT EPG
           Interactions between inputs       # Arrow right
             Max recordings:             2   # default is 1
             Schedule order:             3   # Ascending order, increment by capture card max recordings
             Live TV order:              1   # Descending order, to avoid conflicts with scheduled recordings
                                             # Arrow left to go back one level
           .
           Scan for Channels             # Skip.  Only one scan needed.
       # Use ESC key to **Save and Exit**
    .
    # ####################
    # [OPTIONAL] Can enable/disable channels.
    #   I skipped this section.
    6. Channel Editor
    .
    # ####################
    # Set default storage directory.
    #
    7. Storage Directories
         Default
           (Add New Directory)
              #   default         /data/mythtv/recordings
       # Use ESC key to **Save and Exit**
    .
    # ####################
    # Create the following storage group-name groups.
    #
    7. Storage Directories
         (Create group-name Group)
           (Add New Directory)
              #   LiveTV        /data/mythtv/livetv
              #   DB Backups    /data/mythtv/db_backups
              #   Videos        /data/mythtv/videos
              #   Trailers      /data/mythtv/trailers
              #   Coverart      /data/mythtv/coverart
              #   Fanart        /data/mythtv/fanart
              #   Screenshots   /data/mythtv/screenshots
              #   Banners       /data/mythtv/banners
       # Use ESC key to **Save and Exit** after each group
    

    Use ESC key to back out and exit.

    Note when I exited the GUI it crashed.

    I checked if the recording backend was running and it was.

     $ ps -fu mythtv
    
     UID        PID  PPID  C STIME TTY          TIME CMD
     mythtv    1830     1  2 13:20 ?        00:00:01 /usr/bin/mythbackend --quiet --syslog local7

    Configure MythTV Frontend

  3. Configure MythTV Frontend. (This is a GUI so run on RPi console)

     ./run_mythfrontend.sh
  4. When frontend GUI starts configure the following:

     Setup
       # ####################
       General
         # Database Configuration            # Shows user and password
    
         Shutdown/Reboot Settings
           Customize exit menu options:      # Can change - I left as default
    
       # ####################
       Theme Chooser
           # I chose Mythbuntu 30.1.  Default is MythCenter.
    
       # ####################
       Audio
         Audio Output Device:   ALSA:hw:CARD=b1,DEV=0              # HDMI sound
                                #ALSA:hw:CARD=Headphones,DEV=0     # For 3.5mm analog audio
         # Use ESC key to **Save then Exit**
    
       # ####################
       Video
         General
           General(Auto-Expire)
             Time to retain deleted recordings (days)   7       # Window of ability to restore
    
         Program Guide
           Guide starts at channel:                     #9      # Value changes initial EPG grid positioning
           # Use ESC key to **Save then Exit**
    
         Playback
           General Playback
             Automatically mark a recording as watched:   Disable   # default is disable
    
           Current Video Playback Profile:        MMAL      # Arrow right
             -> Standard & OpenGL YV12                      # Arrow right (this entry will change name after we change settings)
                 Decoder:                         MMAL acceleration (decode only)
                 Max CPUs:                        4
                 Deblocking filter:               Enable
                 Video Renderer:                  OpenGL YV12
                 Deinterlacer Quality (SR):       Medium quality
                   Prefer OpenGL deinterlacers:   Disable
                   Prefer driver Deinterlacer:    Disable
                 Deinterlacer Quality (DR):       Medium quality
                   Prefer OpenGL Deinterlacer:    Disable
                   Prefer driver Deinterlacer:    Disable
             # Use ESC key to **Save then Exit**
    
         Playback
           View Recordings
             Episode sort orderings:   Sort all sub-titles/multi-titles Descending
    
         Playback
           Commercial Skip
             Commercial skip automatic rewind amount (secs):   1
           # Use ESC key to **Save then Exit**
    
         Playback Groups
           Default Group
             Skip ahead (seconds)               30       # default is 30
             Skip back (seconds)                 5       # default is  5
           # Use ESC key to **Save then Exit**
    
       # ####################
       Edit Keys
         TV Playback        # Context.  Arrow right
           ToggleBookmark   # Actions.  Arrow right and press "Enter"
                            # At Waiting for a keypress, press "Enter"
                            # At Add key 'Return'? choose "OK"
                            # at This key binding conflicts with SELECT in the Global context.  Do you want to bind it anyway?  Choose "OK"
         # Use ESC key to prompt **Save changes?** and choose "OK"

    Use ESC key to back out of setup and mythfrontend.

J. Change to Schedules Direct EPG via XMLTV

This change is optional and requires a paid ($25 USD/year) subscription to Schedules Direct which provides over 2 weeks of guide data. Personally I find the OTA EIT EPG not very useful as in my area it contains less than 24 hours of guide data.

  1. Switch to login as user mythtv.

     sudo su --login mythtv

    These next steps are based on the guide: https://www.mythtv.org/wiki/XMLTV#Setup_with_tv_grab_zz_sdjson_sqlite

  2. Initialize the Schedules Direct sqlite database.

     tv_grab_zz_sdjson_sqlite --manage-lineups --config-file $HOME/.mythtv/SD.xmltv

    Provide your Schedules Direct username and password.

    Choose 5: Initialize/update the local database,
    accept default location for database,
    accept default for confirm passwordhash, and
    choose 0: Exit lineup management

  3. Choose lineups.

    Note that I previously added lineups using Tvheadend/Kodi/LibreELEC.

     tv_grab_zz_sdjson_sqlite --configure --config-file $HOME/.mythtv/SD.xmltv

    Accept default for Database for Schedules Direct EPG: [/home/mythtv/.xmltv/SchedulesDirect.DB],
    answer yes to the lineups you need and no to the others,
    accept defaults for all other questions.

    Program exited on its own.

  4. Test tv grabber without downloading episode guide data.

     tv_grab_zz_sdjson_sqlite --days 0 --config-file $HOME/.mythtv/SD.xmltv

    YOU WILL NEED THIS INFO LATER FOR THE CHANNEL EDITOR:

    Note that the output contains the channel number along with the associated XMLTV ID in the form I68327.json.schedulesdirect.org which is needed in mythsetup later to associate the scanned channel number with the schedules direct guide data.

  5. Choose channels you want.

     tv_grab_zz_sdjson_sqlite --manage-lineups --config-file $HOME/.mythtv/SD.xmltv

    Choose 6: Manage database lineup channel selection,
    choose the lineup to manage,
    choose the channels to be selected for guide data (e.g., 3: Set all existing lineup channels as selected),
    choose 0: Exit lineup channel management, and
    choose 0: Exit lineup management

  6. Switch back to the 'pi' userid.

     exit

    Reconfigure MythTV Backend

  7. Run myth setup. (This is a GUI so run on RPi console)

     ~/run_mythsetup.sh

    When backend GUI starts configure the following:

    Note that navigation is via the arrow keys, tab, shift+tab and escape keys. Enter key or Space bar often pops up list or toggles setting.

    
    # ####################
    # Set security PIN and disable transcoding jobs
    #
    1. General
         Program Schedule Downloading Options
           Automatically update program listings:   Enable   # Arrow right
             Guide data arguments:                  --no-allatonce
         # Use ESC key to **Save then Exit**
    .
    # ####################
    # Ensure capture card EIT scan is disabled
    #
    # Choose 1st capture card
    2. Capture cards
         [HDHOMERUN: 104F3D29]
           Card type   HDHomeRun networked tuner               # Arrow right
             Recording Options                                 # Arrow right
               Use HD HomeRun for active EIT scan:   disable
         # Use ESC key to **Save then Exit**
    .
    # ####################
    # Create entry for SD (Schedules Direct) episode guide
    #
    4. Video sources
         (Delete all video sources)        # We will no longer use EIT EPG
         (New Video Source)                # Choose once - **after a long wait** creates "New Video Source" entry
         New Video Source                  # Choose this new entry
           Video Source Name:         SD   # Make video source match what was done in XMLTV setup which is "SD"
           Listings Grabber:               # Space bar to pop up list
                                           # Choose **Multinational (Schedules Direct JSON web services with SQLite...)**
           Channel frequency table:   us-bcast
         # Use ESC key to **Save then Exit**
    .
    # ####################
    # Associate each capture card with a video source
    #
    # Associate 1st capture card
    5. Input Connections
         [HDHOMERUN: 104F3D29](MPEG2TS)->(None)
           Video Source:                 SD
           .
           Scan for Channels                 # Choose this **after** above.
             Scan                            # Scroll down and choose Scan.
                                             #   Wait while scan proceeds.
                                             # When scan complete at "Found X channels" choose "Insert All".
                                             # Choose "OK"
                                             # Choose "Exit"
         # Use ESC key to **Save then Exit**
    .
    # Associate 2nd capture card
    5. Input Connections
         [HDHOMERUN: 104F3D29](MPEG2TS)->(None)
           Video Source:                 SD
         # Use ESC key to **Save and Exit**
    .
    # ####################
    # Associate channel number with Schedules Direct XMLTV ID
    #     NOTE: Can also set channel visible/not visible or delete channel entirely
    6. Channel Editor
         # For each Schedule Direct channel
           # Choose channel number
             Channel Options - Common
               XMLTV ID                           # Press "Enter"
                 I#####.json.schedulesdirect.org  # Type in XMLTV ID from data obtained earlier
           # Use ESC key to **Save and Exit**
    

Use ESC key to back out and exit.

At If you've added or altered channels, please run 'mythfilldatabase' on the master backend to populate the database with guide information. prompt choose OK.

Note when I exited the GUI it crashed.

  1. Run mythfilldatabase to populate guide data.

    This will take a long time when run the first time.

     sudo su --login mythtv -c "mythfilldatabase --no-allatonce"
  2. Run mythfrontend. (This is a GUI so run on RPi console)

     ./run_mythfrontend.sh

    Check the guide data. Mine had 18 days of data.

K. Ensure Raspberry Pi uses Full TV Screen

Sometimes the image from the RPi does not use the whole TV screen. Fortunately there are several options available to address this situation. Following are the things I tried in order to use the whole screen of my 40" Samsung 1080p TV.

  • Try TV picture setting Screen Fit. Image did not take up the whole screen.

  • Try /boot/config.txt parameter disable_overscan=1 Image became smaller.

  • Try /boot/config.txt parameter overscan_scale=1 Image still smaller than screen.

  • Try /boot/config.txt parameters to force an HDMI screen resolution. Image didn't change.

      hdmi_drive=2   # Uncomment this hdmi_drive line if using sound via HDMI cable
      hdmi_group=1   # CEA (Consumer Electronics Association - TV manufacturers)
      hdmi_mode=16   # 1920x1080 60 Hz
    
      # For Benq FP222WH 22" monitor use:
      # hdmi_drive=1  # Normal DVI mode (no sound via monitor)
      # hdmi_group=2  # DMT (Digital Monitor Timings - typically used by monitors)
      # hdmi_mode=58  # 1680x1050 60 Hz
  • Finally through some trial and error I was able to get the RPi to use the whole TV screen with the following /boot/config.txt parameters:

      # uncomment the following to adjust overscan. Use positive numbers if
      # console goes off screen, and negative if there is too much border
      overscan_left=-10
      overscan_right=-10
      overscan_top=-22
      overscan_bottom=-22

At this point I was pleased that the image from the RPi was using the whole screen on my TV.

L. Configure Kodi

Here we configure the Kodi MythTV PVR Client to work with the MythTV backend.

  1. Start Kodi. (This is a GUI so run on RPi console)

     kodi
  2. Navigate to Add-ons -> My Add-ons -> PVR clients -> MythTV PVR Client and press Enter.

  3. Choose Configure and set the following:

    MythTV Backend Hostname or IP: 192.168.1.60

  4. Choose OK

  5. Navigate to Enable and press Enter to activate add-on.

  6. Press Escape three times to get back to main menu.

    Enable Expert Mode

  7. Navigate to Gear icon (Settings) -> Player -> (gear icon) Standard and press Enter twice to cycle through options to arrive at Expert.

    Enable Closed Captions

  8. Navigate to Language -> Enable parsing for closed captions and press Enter to toggle option to enabled.

  9. Press Escape twice to get back to main menu.

TV option should now be enabled on main Kodi screen.

To exit Kodi navigate to the Power icon (circle with line though top) press Enter, and choose Exit.

M. Enable Menu at Boot for Mythfrontend and Kodi

Here we set up a menu to run at startup. The menu will provide choices to start mythfrontend, kodi, etc.

MythTV PVR menu:

MythTV PVR menu

  1. Create mythmenu.sh script file.

    Edit ~/mythmenu.sh file.

     nano ~/mythmenu.sh

    Copy and paste the following lines:

    ----- begin mythmenu.sh file -----

    #!/bin/bash
    #
    # MythTV PVR Menu
    
    # Check if running via SSH, if so skip menu, it should only run locally.
    SSH=$(printenv | grep SSH_CLIENT)
    if [ -n "$SSH" ]; then
        exit 1
    fi
    
    # Global Variables
    OPT1="MythFrontend"
    OPT2="Kodi"
    OPT3="Backend-setup"
    OPT4="Load-TVGuide"
    OPT5="Reboot"
    OPT6="Shutdown"
    OPT7="Exit"
    
    # Set infinite loop
    while true; do
    
    # Display menu
    CHOICE=$(
    whiptail --title "MythTV PVR" --menu "Choose an option" 20 78 12 \
        "$OPT1"  "Watch and Schedule Recordings" \
        "$OPT2"  "Watch and Schedule Recordings via Kodi UI" \
        "$OPT3"  "Configure mythbackend" \
        "$OPT4"  "Run mythfilldatabase --no-allatonce" \
        "$OPT5"  "Reboot" \
        "$OPT6"  "Shutdown now" \
        "$OPT7"  "Exit menu"  3>&2 2>&1 1>&3
    )
    
    # Make decision
    case $CHOICE in
        "$OPT1") ./run_mythfrontend.sh;;
        "$OPT2") kodi;;
        "$OPT3") ./run_mythsetup.sh;;
        "$OPT4") sudo su --login mythtv -c "mythfilldatabase --no-allatonce";;
        "$OPT5") sudo reboot;;
        "$OPT6") sudo shutdown -h now;;
        "$OPT7") clear && exit;;
    esac
    
    done

    ----- end mythmenu.sh file -----

    Save file and exit editor with Ctrl+X, Y, and Enter key presses.

    Make the file executable with:

     chmod 755 ~/mythmenu.sh
  2. Configure auto start of mythmenu.sh file.

    For simplicity we simply add an invocation line at the end of the .bashrc file. For more technically correct methods see RaspberryPiTips.com: How to Auto Start a Program on Raspberry Pi? (4 ways)

    Edit .bashrc file.

     nano ~/.bashrc

    Append to the end of the file the following lines:

     # Display MythTV PVR menu
     /home/pi/mythmenu.sh

    Save file and exit editor with Ctrl+X, Y, and Enter key presses.

Now when the RPi is rebooted it will display our menu of MythTV PVR options.

Watch and Record TV

Here I tested and confirmed that the RPi4 was capable of simultaneously recording two shows and watching a recording at the same time.

Recording

Recording rules can be added via:

  • Mythfrontend menu Manage Recordings

  • Kodi menu TV -> Guide.
    Note that Add timer can be used for a repeating recording rule, whereas Record is for a single recording.

  • Web browser visit to http://192.168.1.60/mythweb

Watching

Recorded content can be watched via:

Video Playback Results

  • Mythfrontend was okay, but some judder (image jumps in video playback) were present.

  • Kodi provided great playback quality. There was some video jitter while navigating menus, but this did not appear during playback.

  • Web browser visit to http://192.168.1.60/mythweb had reasonable playback quality using Firefox on my Intel core i7-7700K desktop computer running Kubuntu 18.04.

The judder in mythfrontend playback of interlaced content was disappointing. I was looking for smooth playback quality. I wondered if I could do better with some overclocking.

Overclock Testing with Mythfrontend

Note that some form of cooling is required when overclocking to prevent the RPi4 from overheating.

I tried a few overclock parameters and watched the same recordings (sports are good due to fast panning motion). While testing I monitored the RPi via an SSH session and following commands:

  • To check CPU and other speeds in Hz (note not MHz):

    for k in arm core H264 isp v3d uart pwm emmc pixel vec hdmi dpi; do echo "`vcgencmd measure_clock $k`  $k"; done
  • To continually watch CPU temperature (Ctrl+C to stop):

    watch -n 1 vcgencmd measure_temp

  • To monitor CPU load:

    top

Overclock Results for Mythfrontend

/boot/config.txt parameters Max Temp (°C) Observations
no overclocking 55 Okay video quality for many TV shows,
some judder (jump in video playback)
over_voltage=2, arm_freq=1750 63 Still has some judder
over_voltage=6, arm_freq=2000 76 Still has some judder

Unfortunately overclocking did not get rid of all judder from mythfrontend playback so I removed overclocking.

Computers with Great Video Playback Quality

For reference I tested and confirmed the following systems have great video playback quality with no tearing or judder:

  • 2017 NVidia Shield running MythTV Android (mythfrontend-20200716-arm64-v31.0-79-g89d1991ef2.apk for CC choose OpenGL High Quality video playback profile and increase Max CPUs to 4) or
    MythTV Android TV Leanback Frontend (leanfront-v0-252-gb6d91a8.apk works with CC) using the RPi4 for mythbackend.

  • Raspberry Pi 2 with LibreELEC 9.2.1 and Kodi 18.6 with MythTV PVR Client addon installed using the RPi4 for mythbackend.

  • Raspberry Pi 4 4GB with Raspberry Pi OS Lite 2021-01-11 and Kodi 18.7 with MythTV PVR Client addon installed using the RPi4 for mythbackend. More specifically Kodi and mythbackend are running on the same RPi4 concurrently. Note that there are some display jitters while navigating the Kodi menus, but these did not adversely impact video playback.

Conclusion

Mythbackend on the Raspberry Pi 4 4GB has proven to be a solid backend that reliably records TV shows and delivers recordings to other display frontends. If this is all you need then enough said.

Mythfrontend on the RPi4, however, has room for improvement. While it displays ATSC MPEG2 720p content smoothly, ATSC MPEG2 1080i interlaced content has visible judder (image jumps in video playback). This situation may improve as RPi4 software matures.

Fortunately there are other good playback alternatives. These are kodi running directly on the same RPi4, or using a different frontend computer such as an NVidia Shield.

If video quality and closed captions are important to you and you desire a combined MythTV frontend and backend then you will be better served with an x86-64 based computer solution.

However if closed captions are not high on your list and you don't mind the Kodi user interface, then the RPi4 can be a satisfying low power combined frontend and backend PVR solution.

References

While researching how to set up a Raspberry Pi 4 (4GB) computer with MythTV I found the following references useful:

MythTV

MythTV Video

MythTV Remote Control - IR KeyTable

Raspberry Pi Configuration

Static IP Address

Desktops, Kodi and Scripting


Appendix A: Incomplete steps to Configure RPi4 Boot from USB Hard Drive

WARNING: I tried these steps but did not get it booting from USB to work for me.

I suspect that I need on the USB hard drive a vfat partition containing the /boot contents in order for the the RPi4 to boot from the USB hard drive. For now I will continue to use the microSD card to boot the RPi. The root file system is running from the USB hard drive.

Steps to switch over to booting from the USB hard drive.

  1. Configure RPi4 for USB boot.

     sudo raspi-config
    • Choose 8 Update and wait fro raspi-config to reload.

    • Choose 6 Advanced Options -> A6 Boot order -> B1 USB boot.

    • Choose Finish.

    • At Would you like to reboot now? choose Yes.

    This additional reboot with microSD card still installed is needed to enable USB boot capability.

    For reference only the tail portion of the console output follows:

    ----- begin console output -----

     BCM2711 detected
     Dedicated VL805 EEPROM detected
     *** INSTALLING /tmp/tmp.jyn5RGmrch  ***
     BOOTFS /boot
     EEPROM update pending. Please reboot to apply the update.

    ----- end console output -----

  2. After RPi reboots, shutdown.

     sudo shutdown -h now
  3. Disconnect power from RPi.

  4. Remove microSD card.

  5. Reconnect power to RPi to boot from USB.


Appendix B: Enable Closed Captions for MPEG4

From my original experimentation I discovered that 1080i (interlaced) MPEG2 video playback performed best using the MMAL decoder. This decoder was also able to display closed captions in the video stream.

However, this was not the case with MPEG4 - the closed captions would not display. When I originally built this PVR I recall later adding an OpenGL profile for MPEG4 so that closed captions could be displayed. Since that time I have forgotten how I did that.

With this recent rebuild of the PVR using another HDD I have discovered that the V4L2 decoder works for video playback and closed captions of MPEG4. Following is how I adapted the video profiles to enable closed captions with both MPEG2 and MPEG4.

  1. In Mythfrontend go to Setup -> Video -> Playback -> Current Video Playback Profile - MMAL and press Right arrow.

  2. Go to MMAL acceleration (decode only) & OpenGL YV12 and press Enter.

  3. Set Video Formats to mpeg2video.

  4. Press Escape and choose Save then Exit.

  5. Go to Playback -> Current Video Playback Profile - MMAL and press Right arrow.

  6. Choose Add New Entry.

    There should now be 2 Current Video Playback Profiles:

    -> MMAL acceleration (decode only) & OpenGL &V12
    -> Standard & OpenGL YV12

  7. Choose Standard & OpenGL YV12.

  8. Set the following:

    Video Formats:                                  mpeg4   # was blank/empty
    Decoder:             V4L2 acceleration  (decode only)   # was Standard
    Max CPUs:                                           4   # was 1
    Delinterlacer quality (single rate):   Medium quality   # was None
    Delinterlacer quality (double rate):   Medium quality   # was None
  9. Press Escape and choose Save then Exit.

  10. Back out to main menu.

The Medusa Deception novel - free first in series
News   Documentation     Copyright (c) 2013-2024 Curtis Gedak

Get GParted at SourceForge.net. Fast, secure and Free
	Open Source software downloads Valid HTML 4.01! Correct CSS!