Saturday, November 14, 2020

 

How I installed MythTV v31 on my RPI 4

UPDATE: May 4, 2021 because mythtv-light has moved and download is now different

The purpose of this blog is to create a repeatable set of instructions so I can duplicate my basic installation of Raspberry PI OS and MythTV on a Raspberry PI 4 so I can start my tests with the same baseline every time.

The hardware is:
  • Raspberry Pi 4 with 4GB DRAM from Canakit as a starter kit.
  • StarTech/Eluteng SATA to USB Cable - USB 3.0 to 2.5” SATA III Hard Drive Adapter
  • Samsung 860 QVO 1TB Solid State Drive (MZ-76Q1T0) V-NAND, SATA 6Gb/s
  • SiliconDust HDHomeRun Connect Quatro tuner
The kit had a microSD card, HDMI cable, powers supply, and a case with fan.
  1. It helps keep things stable with your system if you set your AP/router to automatically assign the same IP to a device each time it boots. Having the HDHR Quatro and the RPI 4 always have their same IP each time they boot solves a lot of problems before they happen.
  2. Install the Raspberry Pi Imager on a Linux, Mac, or Windows 10 computer.
  3. Use the Raspberry Pi Imager to get the latest Raspberry Pi OS. For simplicity, I used the Desktop version of the OS. The Imager will write the OS to your boot memory device.  In my case the RPI4 has the latest bootloader flashed to the eeprom so I plugged in the USB3 SATA adapter with the SSD drive into my Windows laptop and imaged the SSD with the Raspberry Pi OS image.
  4. Install the USB4 SATA SSD into one of the USB3 slot on the RPI4.
  5. Plug in a HDMI TV and Keyboard/mouse, and LAN cable.
  6. Turn on the RPI 4
  7. After booted,  configure the regional stuff, set wait on network at boot, and turn on ssh. 
  8. Also use raspi-config to use Fake KMS if it's not already.
  9. Reboot.
  10.  Install 'gdebi-core' with sudo apt install gdebi-core
  11.  Download a bunch of great PI utility scripts. git clone https://github.com/MikeB2013/pi-utils.git
  12.  See the Mythtv mythtv-light wiki for more detail on getting the mythtv-light package.https://www.mythtv.org/wiki/MythTV_Light
  13. Basicially, download the correct mythtv-light package from https://dl.orangedox.com/pCBmBm. Navigate to MythTV-light, raspberry-pi, version number. Download the mythtv-light package. If you want to install plugins download the mythplugins-light package as well.
  14.  Now install Mythtv-light by: sudo gdebi mythtv-light-xxxxxx.deb    #change the name to match what was downloaded.
  15. At this point the mythtv frontend is installed so now I want all the stuff needed for the backend. Use the pi-utils script pi-mythbackend-helper.sh to do this.
  16.  The script has sudo commands when needed so run as 'pi'
  17. run sudo raspi-config and set the boot/autologin to console autologin as pi since we don't want a desktop environment for performance reasons.
  18. After the script ends you need to reboot.
At this point I'm ready to setup the backend.  My first setup will be for OTA EPG Guide Video source using SiliconDust HDHR tuners. Then I'll add a section on using a Video source for XMLTV EPG guides.

NOTE! if I modify /boot/config.txt to overclock the arm clock and over_voltage. I get errors in the official run_mythfrontend.sh.  So I now use this as my run_mythfrontend.sh on my RPI4

#!/bin/bash

# script to run mythfrontend from version 31 on Raspberry Pi under Raspian Buster using EGLFS
# can be added to .bashrc to allow autostart of mythfrontend on boot

# Last Modified 24 July 2020

# Author Mike Bibbings

#check for any arguments on command line, if so use for mythfrontend command, so we can use different parameters
#e.g. run_mythfrontend.sh --logpath /home/pi --loglevel debug
# if no arguments set --logpath /tmp
if [ -z "$*" ] ; then
ARGUMENTS="--logpath /tmp -O PowerOffTVOnExit=0"
else
ARGUMENTS="$*"
fi

# set perfomance mode, not sure if needed for Pi4, do it anyway
echo performance | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor


RESOLUTION="1920x1080@60"

echo "Setting screen to $RESOLUTION"


#for QT debug add to command line QT_QPA_EGLFS_DEBUG=1 QT_LOGGING_RULES=qt.qpa.*=true
QT_QPA_EGLFS_ALWAYS_SET_MODE="1" QT_QPA_PLATFORM=eglfs mythfrontend $ARGUMENTS
# fixup keyboard after exit from mythfrontend, bug in QT causes segment fault which kills keyboard input
kbd_mode -u
# restore cursor
setterm  --cursor on

exit 0

Mythtv-setup for HDHR tuners with OTA EPG Program Guide

  1. Move the ~/pi-utils/run_* scripts to ~/
  2. Run ./run_mythsetup.sh and start with the General settings
  3. In Host Address Backend Setup, set Security PIN (required) to "0000"
  4. In Capture cards I created 4 new tuners, all set for HDHomeRun Networked Tuner. I selected the same Tuner IP address for all 4 since my HDHR is a Quatro and has 4 tuners. If you only have one HDHR box, then you'll only see one HDHR Tuner IP to select.
  5. On the first tuner I set Record Options -> Use HD HomeRun for active EIT scan to selected, but set it to Unselected for the other 3 tuners. This helps balance the EPG scanning vs. the locked tuners for other applications.
  6. In Video Source, I created 1 new source named OTA and for Grabber I selected Transmitted guide only (EIT)
  7. In Input connections, I edited the first input. I selected MPEG2TS in Input name list. In Display Name I put HDHR1.  In Video Source I selected OTA and then scanned for channels.
  8. Once the Scan was complete I inserted all, exited and saved.
  9. I setup the other 3 Input connections but did not run scan for them. They should be set the same except for the Display name where I used HDHR2-4.
  10. In Channel Editor I made some channels not visible and saved.
  11. In Storage Groups I set the Default to /srv/mythtv/recordings and DB Backups to /srv/mythtv/db_backups. You can setup the other storage group directories if you want.
  12. Exit setup which restarts mythtv-backend.service.
  13. Now you can run mythtv frontend with: ./run_mythfrontend.sh
  14. Once in the frontend I went to setup and changed:
    1. In Setup Wizard -> Audio Configuration I selected ALSA:hw:CARD=b1,DEV=0
    2. I also selected Dobly Digital, etc and 5.1 Speakers.
    3. In Video I selected MMAL, Standard Decoder and OpenGL software.
  15. At this point video and audio will work from the tuners. My optional settings are:
    1. In General -> Shutdown/Reboot Settings -> Customize exit menu options I chose "Show quit"
    2. In Theme Chooser I chose Mythbuntu 30.1
    3. In Video -> Playback -> General Playback -> Automatically mark a recording as watched to selected
    4. In Video -> Playback -> General Playback -> Action on playback exit to Always prompt (excluding Live TV)
    5. In Video -> Playback Groups -> Default Group -> Skip ahead to 60 and Skip back to 15.
  16. I don't run Commercial flagging since that doesn't work well for my usually recorded programs so I edit the default recording rules to not post process commercial flagging.

Change to using an EPG from Schedules Direct via XMLTV json.

With the RPI 4 in the state as setup above I started this sequence of instructions to switch from OTA to Schedules Direct for my EPG.

  1. Switch to user 'mythtv' by: sudo su mythtv and then cd $HOME
  2. Follow the help on the mythtv xmltv wiki page at  https://www.mythtv.org/wiki/XMLTV#Setup_with_tv_grab_zz_sdjson_sqlite
  3. Run the commands: 
    1. tv_grab_zz_sdjson_sqlite --manage-lineups --config-file $HOME/.mythtv/SD.xmltv
    2. Enter login info for Schedules Direct
    3. Enter 5 to initialize the database
    4. Take the defaults and exit.
  4. Run the command:
    1. tv_grab_zz_sdjson_sqlite --configure --config-file $HOME/.mythtv/SD.xmltv
      • Answer yes to the lineup you want to use and no to the others, then take the defaults and exit
    2. Run the commands:
      1. tv_grab_zz_sdjson_sqlite --days 0 --config-file $HOME/.mythtv/SD.xmltv
      2. tv_grab_zz_sdjson_sqlite --manage-lineups --config-file $HOME/.mythtv/SD.xmltv
      3.  Select Manage database lineup channel selection. Then Choose which channels are selected.
      4. Now go through and pick yes or no on the channels you want data on.
      5. You may have to do the option 5 again if you missed a channel or selected wrong,
      6. exit
    3. Switch back to user 'pi' by :exit
    4. Run the mythtv-setup by: ./run_mythsetup.sh
    5. In General -> Job Queue (Backend-Specific) -> I deselected Allow commercial Jobs and Allow transcoding jobs. (not needed for me)
    6. In General -> Program Schedule Downloading Options -> Automatically update program listings -> Guide Data Program execution start/end I set them to 2 and 5
    7. In General -> Program Schedule Downloading Options -> Automatically update program listings -> Run guide data program at time suggested by the grabber I deselected.
    8.  I've never had the problem of running out of memory while mythfilldatabase is running, but some have, so I've add the Guide Data Argument option: --no-allatonce
    9. On Capture cards deselect the "Use HD HomeRun for Active EIT scan" in Recording Options for any tuner you had it enabled on.
    10. In Video Sources Delete all video sources. Then add a New video source.
    11. In the Video Source make the Video source name match what was done in XMLTV setup which is "SD"
    12. Select Listing grabber to be Multinational (Schedules Direct JSON web services with SQLite...
    13. Save and exit.
    14. In Input Connections go through each and select Video Source "SD" and only do the scan in the first Input Connection.
    15. In Channel Editor you may need to revisit any changes done before as the rescan will have undone them.
    16. Exit which restarts the mythtv-backend.service.
    17. The next step may not be necessary because on my RPi4 starting the mythtv-backend.service triggers the mythfilldatabase to run when you exit.  So you may want to wait for 5 minutes to see if the EPG fills automatically.
    18. Switch back to user 'mythtv' and run "mythfilldatabase"
    19. Once mythfilldatabase completes, exit back to user 'pi'
    20. Run the mythfrontend by: ./run_mythfrontend.sh and see how the guide has changed.  18 days of data.

    Wednesday, August 5, 2020

    Forwarding ‘root’’s mail on Raspberry PI OS to gmail account

    1.  Install ‘mailutils’, ‘postfix’ and ‘libsasl2-modules’ with:
    sudo apt install mailutils postfix libsasl2-modules
    2.  Edit “/etc/postfix/main.cf”
    Change the line that reads “inet_interfaces = all” to “net_interfaces = loopback-only”
    Change the line that reads “relayhost = “ to “relayhost = [smtp.gmail.com]:587”
      Add the lines:
    smtp_use_tls = yes
      smtp_sasl_auth_enable = yes
      smtp_sasl_security_options =
      smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
    3.  Create the file “/etc/postfix/sasl/sasl_passwd” to enable authentication 
    add the line “[smtp.gmail.com]:587    username@gmail.com:password”
    The user address I use is an email account that I created especially for my computers to use as a ‘from’ address
    4.  Run “sudo postmap /etc/postfix/sasl/sasl_passwd”
    5.  Run “sudo systemctl restart postfix”
    6.  To forward mail sent to ‘root’ I need to edit the ”/etc/aliases” file
    sudo nano /etc/aliases 
    add  “root: youremail@yourdomain.com” below the “postmaster:  root”  line.
    7. Update the system’s aliases with “sudo newaliases”

    Monday, December 16, 2019

    Installing Mythtv on a Raspberry PI 4

    How I installed Mythtv on my RPI 4

    The purpose of this blog is to create a repeatable set of instructions so I can duplicate my basic installation of Raspbian Buster and mythtv on a Raspberry PI 4 so I can start my tests with the same baseline every time.

    The hardware is:
    • Raspberry Pi 4 with 4GB DRAM from Canakit as a starter kit.
    • StarTech.com SATA to USB Cable - USB 3.0 to 2.5” SATA III Hard Drive Adapter
    • Samsung 860 QVO 1TB Solid State Drive (MZ-76Q1T0) V-NAND, SATA 6Gb/s
    • SiliconDust HDHomeRun Connect Quatro tuner
    The kit had a microSD card, HDMI cable, powers supply, and a case with fan.

    1. It helps keep things stable with your system if you set your AP/router to automatically assign the same IP to a device each time it boots. Having the HDHR Quatro and the RPI 4 always have their same IP each time they boot solves a lot of problems before they happen.
    2. Download the Raspbian Buster with Desktop. (2020-02-13-raspbian-buster.zip)
    3. Use balenaEtcher to flash the zip onto the microSD
    4. Install the MicroSD into the RPI 4
    5. Install the SATA SSD into the SATA to USB Cable and plug the cable into a USB3 slot
    6. Plug in a HDMI TV and Keyboard/mouse
    7. Turn on the RPI 4
    8. The boot process walks through setup of region, language, Screen overscan, WiFi, and updates. I ignored the WiFi since I'm using wired LAN.
    9. Reboot
    10. Since my TV is 4K UHD and I want only 1080P HD because of the Mythtv recording types for OTA 1080i and 720P, it works better for me to resize the screen using Preferences -> Screen Configuration and set the screen to 1920x1080 60P.
    11. Just in case, there are issues with some USB3 SATA converters which adversely affect disk performance on Pi4. See https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=245931&hilit=uas
    12. For me this came down to adding the text usb-storage.quirks=aaaa:bbbb:u  to my /boot/cmdline.txt at the beginning of the line of parameters. The link above tells you how to find your specific aaaa:bbbb.
    13. From the Mythtv Forum I used a script to setup the rootfs on the SATA SSD for speed and reliability using a script found in this post pi-SDtoHD-helper.sh. The boot partition is still on the microSD card.
    14. Unmount the SSD if it was mounted.
    15.  Run the script: sudo ./pi-SDtoHD-helper.sh -d /dev/sda
    16.  Reboot and note the rootfs is on the SSD using lsblk.
    17. Since by default the screen will blank every so often you need to install the Screen Saver just so you can disable it.
    18. So I did: sudo apt install xscreensaver.  I needed to reboot at this point for Screensaver to work properly.
    19. To install mythtv you need to refer to the Mythtv wiki for Raspberry PI wiki for Raspberry_Pi
    20. Using sudo raspi-config I setup the gpu memory split to 320. While in raspi-config I also set the interface option of SSH to be enabled and the Boot option of Wait for Network since I'm using a networked tuner and sometimes do maintenance with ssh.  Now reboot.
    21. EDIT: Setting audio is still a work in progress. What I've documented below works for Stereo and 5.1 under some conditions. If I don't create the .asoundrc file I have to select audio device ALSA:hw:CARD=ALSA,DEV=2 to get 5.1 working with Digital Audio Capabilities E-AC-3 being the only one checked.
    22. Since I'm on a RPI 4 I only had to setup the .asoundrc file in the Digital Audio with ALSA section by cutting and pasting into $HOME/.asoundrc from the wiki text.
    23. Follow the instruction in the Mythtv wiki for Mythtv Light MythTV Light
    24. I used mythtv v30 so I: sudo nano /etc/apt/sources.list and added the line for version 30 for Buster.
    25. I did the wget instruction listed next.
    26. Next I did the sudo apt update and sudo apt install mythtv-light
    27. At this point the mythtv frontend is installed so now I want all the stuff needed for the backend. There is a helper script on the forum that will do all this. Look at: mythbackend-helper
    28.  So I did  ./pi-mythbackend-helper.sh   (Script has sudo commands when needed so run as 'pi')
    29. After the script ends you need to reboot and do the mythtv-setup work.
    30. I needed to disable the CEC remote stuff and add that option to some commands in the application menu.
    31. So in Application Menu (Raspberry Icon) look for Sound and Video -> Mythtv Frontend, then right click on it to bring up the properties.  Add -O libCECEnabled=0 to the end of the command line in Desktop Entry tab.
    32. In Application Menu (Raspberry Icon) look for Preferences -> Mythtv Backend Setup, then right click on it to bring up the properties.  Add -O libCECEnabled=0 to the end of the command line in Desktop Entry tab.  Also remove the @env@ from the start of the command line.
    At this point I'm ready to setup the backend.  My first setup will be for OTA EPG Guide Video source using SiliconDust HDHR tuners. Then I'll add a section on using a Video source for XMLTV EPG guides.

    Mythtv-setup for HDHR tuners with OTA EPG Program Guide


    1. Run the mythtv-setup from the Application menu and start with the General settings
    2. In Host Address Backend Setup, set Security PIN (required) to "0000"
    3. In Capture cards I created 4 new tuners, all set for HDHomeRun Networked Tuner. I selected the same Tuner IP address for all 4 since my HDHR is a Quatro and has 4 tuners. If you only have one HDHR box, then you'll only see one HDHR Tuner IP to select.
    4. On the first tuner I set Record Options -> Use HD HomeRun for active EIT scan to selected, but set it to Unselected for the other 3 tuners. This helps balance the EPG scanning vs. the locked tuners for other applications.
    5. In Video Source, I created 1 new source named OTA and for Grabber I selected Transmitted guide only (EIT)
    6. In Input connections, I edited the first input. I selected MPEG2TS in Input name list. In Display Name I put HDHR1.  In Video Source I selected OTA and then scanned for channels.
    7. Once the Scan was complete I inserted all, exited and saved.
    8. I setup the other 3 Input connections but did not run scan for them. They should be set the same except for the Display name where I used HDHR2-4.
    9. In Channel Editor I made some channels not visible and saved.
    10. In Storage Groups I set the Default to /srv/mythtv/recordings and DB Backups to /srv/mythtv/db_backups
    11. Since I'm running the setup as user 'pi' it complained on exit about file permissions on some test files. So I did sudo chmod 777 /srv/mythtv/recordings  and sudo chmod 777 /srv/mythtv/db_backups
    12. Start mythtv-backend by: sudo systemctl start mythtv-backend
    13. Now you can run mythtv frontend from the Applications Menu
    14. Once in the frontend I went to setup and changed:
      1. In Setup Wizard -> Audio Configuration I selected ALSA:mythtv:CARD=ALSA
      2. I also selected Dobly Digital, etc and 5.1 Speakers.
      3. In Video I selected OpenMax Normal
    15. At this point video and audio will work from the tuners. My optional settings are:
      1. In General -> Shutdown/Reboot Settings -> Customize exit menu options I chose "Show quit"
      2. In Theme Chooser I chose Mythbuntu 30.1
      3. In Video -> Playback -> General Playback -> Automatically mark a recording as watched to selected
      4. In Video -> Playback -> General Playback -> Action on playback exit to Always prompt (excluding Live TV)
      5. In Video -> Playback Groups -> Default Group -> Skip ahead to 60 and Skip back to 15.
    16. I don't run Commercial flagging since that doesn't work well for my usually recorded programs so I edit the default recording rules to not post process commercial flagging.
    17. Since I use a bluetooth remote instead of a CEC enabled remote I need to pair that remote by clicking on the bluetooth icon in the menu bar at the top right.

    Change to using an EPG from Schedules Direct via XMLTV json.

    With the RPI 4 in the state as setup above I started this sequence of instructions to switch from OTA to Schedules Direct for my EPG.

    1. Switch to user 'mythtv' by: sudo su mythtv
    2. Follow the help on the mythtv xmltv wiki page at  https://www.mythtv.org/wiki/XMLTV#Setup_with_tv_grab_zz_sdjson_sqlite
    3. Run the commands: 
      1. tv_grab_zz_sdjson_sqlite --manage-lineups --config-file $HOME/.mythtv/SD.xmltv
      2. Enter login info for Schedules Direct
      3. Enter 4 to initialize the database
      4. Take the defaults and exit.
    4. Run the command:
      1. tv_grab_zz_sdjson_sqlite --configure --config-file $HOME/.mythtv/SD.xmltv
        • Answer yes to the lineup you want to use and no to the others, then take the defaults and exit
      2. Run the commands:
        1. tv_grab_zz_sdjson_sqlite --days 0 --config-file $HOME/.mythtv/SD.xmltv
        2. tv_grab_zz_sdjson_sqlite --manage-lineups --config-file $HOME/.mythtv/SD.xmltv
        3. Accept the default for my lineup and select option 5, 1, then 5.
        4. Now go through and pick yes or no on the channels you want data on.
        5. You may have to do the option 5 again if you missed a channel or selected wrong,
        6. exit
      3. Switch back to user 'pi' by :exit
      4. Stop Mythtv backend by: sudo systemctl stop mythtv-backend
      5. Run the mythtv-setup from the Applications Menu
      6. In General -> Job Queue (Backend-Specific) -> I deselected Allow commercial Jobs and Allow transcoding jobs. (not needed for me)
      7. In General -> Program Schedule Downloading Options -> Automatically update program listings -> Guide Data Program execution start/end I set them to 2 and 5
      8. In General -> Program Schedule Downloading Options -> Automatically update program listings -> Run guide data program at time suggested by the grabber I deselected.
      9. On Capture cards deselect the "Use HD HomeRun for Active EIT scan" in Recording Options for any tuner you had it enabled on.
      10. In Video Sources Delete all video sources. Then add a New video source.
      11. In the Video Source make the Video source name match what was done in XMLTV setup which is "SD"
      12. Select Listing grabber to be Multinational (Schedules Direct JSON web services with SQLite...
      13. Save and exit.
      14. In Input Connections go through each and select Video Source "SD" and only do the scan in the first Input Connection.
      15. In Channel Editor you may need to revisit any changes done before as the rescan will have undone them.
      16. Exit
      17. Restart mythtv-backend with: sudo systemctl start mythtv-backend
      18. The next step may not be necessary because on my RPi4 starting the mythtv-backend.service triggers the mythfilldatabase to run.  So you may want to wait for 5 minutes to see if the EPG fills automatcially.
      19. Switch back to user 'mythtv' and run "mythfilldatabase"
      20. Once mythfilldatabase completes, exit back to user 'pi'
      21. Run the mythfrontend from the Application Menu and see how the guide has changed.  18 days of data.