Linux Crumbs
Simbiotic - A Cyberpunk Thriller Novel

Build a Cheap PVR using Raspberry Pi 3, LibreELEC, Kodi, Tvheadend, & HDHomeRun

Summary

This article is both a tutorial and a proof of concept. The tutorial describes the hardware required and the steps involved to build your own Personal Video Recorder to record Over-The-Air TV shows available for free with a TV aerial. The proof of concept explores what is possible using low end hardware for a PVR.

The solution uses LibreELEC installed on a Raspberry Pi 3. The LibreELEC distro provides easy installation of the GNU/Linux operating system, Kodi media player, and Tvheadend PVR software. At completion of the steps you will be able to record up to 2 television stations simultaneously while also watching a recorded TV show.

This article was written in December 2017.

Brief History of Document Updates:

Update 2020-10-15: Change Configure Tvheadend section to recommend North Americans use a full scan of channels 2 through 52 by selecting a Pre-defined muxes of United States: us-ATSC-center-frequency-8VSB-062009.

Update 2019-12-05: Updated instructions for LibreELEC 8.2.5.

Update 2019-03-31: Upgraded to LibreELEC 8.2.5 and added audio_pwm_mode=0 to /flash/config.txt to fix analog audio crackling problem with LibreELEC 8.2.4 and 8.2.5.

Update 2018-11-16: Added section "L" instructions to improve ability to recover properly after a power outage so that TV programs can be recorded without manual intervention.

CAUTION:   PVR is Unstable if Inadequately Cooled.

The PVR as originally built without heatsinks was not stable. Under load the RPi3 would hang due to overheating.

To address this issue I added aluminum heatsink cooling fins to the GPU/CPU and Ethernet chips.

A better solution is to seek out a passively cooled aluminum case that contacts the GPU/CPU to disperse heat (e.g., no noisy cooling fan). For example I ordered the following aluminum case. Overall this aluminum case reduced operating temperatures by more than 10 °C compared to the aluminum heatsink cooling fins I had used previously.

Contents

Completed PVR

Following is a picture of the completed RPi3 PVR in operation.

Raspberry Pi 3 PVR

Background

Since 2011 when my spouse and I cut the cord on cable TV and built a Mythbuntu PVR we have been extremely satisfied. That was 6 years ago, and that doesn't mean that I haven't been curious about potentially less expensive options. One System On a Chip (SOC) board that intrigues me is the Raspberry Pi (RPi).

Previously I built a frontend to our MythTV PVR using Kodi on a RPi2 and MythFrontend on a RPi2. From that experience I learned that Kodi appears to have been supported for a longer time on the RPi.

Because I have only read about others using a Raspberry Pi as either a MythTV frontend, or a MythTV backend, but not both at the same time, I figured I would investigate other options for building a combined frontend/backend RPi based PVR.

This investigation led me to discover Tvheadend, which is supported on the LibreELEC GNU/Linux distribution.

NOTE:   Tutorial Assumes Access to Computer, microSD Card Reader, and TCP/IP Network

In addition to the Raspberry Pi 3 used in this tutorial as the base for the PVR, I also used a computer running GNU/Linux (kubuntu 16.04) to access a web browser, terminal window, and ssh command. You might instead use Windows and Putty for ssh.

You will also need a TCP/IP home network with two free Ethernet ports and access to the Internet.

Hardware Selection

When selecting the hardware it is a good idea to have some goals to help guide decisions. For this proof of concept PVR I desired the following features:

  • Must be quiet (PVR directly attached to TV)
  • Must be both backend (record) and frontend (play)
  • Must support recording at least 2 shows at once
  • Must be reasonably neat and tidy (reduce cable clutter)
  • Should keep costs as low as reasonably possible

With this proof of concept I wanted to explore the limits of what was possible using a Raspberry Pi 3 as a PVR. I wished to build a PVR for a low cost and which did not require an externally powered USB hub. I researched specifications and theoretical boundaries to come up with my choices of hardware components.

Specifications

First the dry reading. If you wish to skip over the specifications, feel free as you can refer back to these if necessary.

RPi3 specifications:

  • SoC: Broadcom BCM2837 (roughly 50% faster than the Pi 2)
  • CPU: 1.2 GHZ quad-core ARM Cortex A53 (ARMv8 Instruction Set)
  • GPU: Broadcom VideoCore IV @ 400 MHz.
  • Memory: 1 GB LPDDR2-900 SDRAM.
  • USB 2.0 ports: 4.
  • Network: 10/100 Mb/sec Ethernet, 802.11n Wireless LAN, Bluetooth 4.0.

RPi3 Power Supply/Requirements:

  • Recommended Power Supply: 5.1 Volts at 2.5 Amps.
  • Power Draw: 0.7 Amps to 1 Amp.
    If you need to connect a USB device that will take the power requirements above 1 Amp, then you must connect it to an externally-powered USB hub.

USB 2.0 specifications:

  • Bandwidth: 480 Mbits/sec

North American ATSC digital Television standard specifications:

  • Net bit rate up to 19.39 Mb/sec, which rounds up to 20 Mbits/sec.

Theoretical Boundaries

A single hour of recording an ATSC MPEG-2 TV show can be up to 9 GB in size.

  9 GB = ( (20 Mbits/sec) * (60 sec/min) * (60 min/hour) ) / (8 bits/Byte)

With a single ATSC TV stream of 20 Mb/s it is theoretically possible (but less likely in real word situations) to have a maximum of:

  • 5 concurrent streams on a 100 Mb/s TCP/IP network.
  • 24 concurrent streams on a USB 2.0 bus.

Rationale for Hardware Choice

The above specifications and theoretical boundaries led me to realize that if I were to encounter a bandwidth limitation, it would most likely be due to a network constraint and not a USB bus constraint.

Also because I did not wish to use an externally powered USB hub (extra cables / rats nest) and because there is limited power available via the RPi3 USB bus I had to make another choice. I figured that I could only connect one device to be powered by the RPi3 USB port: Either the TV tuner, Or the hard drive, But not both.

The two tuners I considered were:

The hard drive storage options I considered were:

This meant the potential combinations I could use for a maximum use scenario of watching one recording with two recordings in progress were:

  • Option A: Silicon Dust HDHomeRun Connect with 2 TB USB HDD
    • Cost: $260
    • Network Bandwidth:
      40 Mbits/sec = (20 * 2 incoming TV source streams to RPi3)

  • Option B: Hauppauge WinTV dualHD with 2 TB NAS
    • Cost: $295
    • Network Bandwidth:
      20 * 1 incoming TV recording from NAS to watch
      + 20 * 2 incoming TV source streams to RPi3
      + 20 * 2 outgoing TV streams to NAS to record
      --------------------------------------------------------------
      100 Mbits/sec (the theoretical maximum of 100 Mb/sec Ethernet)

I chose Option A not because it was less expensive by $35, but more importantly because Option A would add significantly less traffic to my home network.

Hardware Component List

Following is a list of components I assembled and their costs in November 2017.

Category Component Cost
Computer Raspberry Pi 3 Model B (1.2GHz quad-core ARM CPU with 1 GB RAM) 60
Case Clear Plastic Case

Even Better is this aluminum case with no heatsinks required
10
Heatsink Aluminum Heatsink Kit (added due to initial overheating issues) 10
Power Supply Micro USB Power Supply (2.4 Amp) 15
Storage Kingston 8 GB microSDHC Card (Class 10) with SD Adapter 10
Keyboard iPazzPort Wireless Mini Keyboard 20
MPEG-2 License MPEG-2 License from Raspberry Pi Store 5
Hard Drive Seagate Backup Plus Slim 2TB Portable External Hard Drive 100
TV Tuner Silicon Dust HDHomeRun Connect network dual tuner 160
Grand Total   $ 390

Note that you will also need a TV aerial, coax cable, Ethernet cable, and either an HDMI cable (New TV) or a 3.5mm to RCA composite audio/video cable (Old TV).

Note also that I opted for the above USB hard drive because it was reported to work when directly connected to the RPi3.

TIP: You can often save some cash by purchasing the top five or six components in a Raspberry Pi 3 kit.

A. Download and Uncompress LibreELEC to MicroSD Card

Use the following instructions to download and write the LibreELEC image to the microSD card.

  1. Download LibreELEC disk image for RPi2/3:

    Visit LibreELEC - Downloads.

    I recommend installing LibreELEC-RPi2.arm-8.2.5.img.gz which includes Kod 17.6.
    Originally for this tutorial I had downloaded LibreELEC-RPi2.arm-8.2.1.img.gz.

  2. Insert the MicroSD card into your computer.

  3. Determine the which /dev/device it is.

    dmesg | tail

    Example output:

    $ dmesg | tail
    [  227.218363] sdhci-pci 0000:01:00.2: PCI INT A -> GSI 16 (level, low) -> IRQ 16
    [  227.218396] sdhci-pci 0000:01:00.2: Refusing to bind to secondary interface.
    [  227.218413] sdhci-pci 0000:01:00.2: PCI INT A disabled
    [  227.218884] jmb38x_ms 0000:01:00.3: enabling device (0000 -> 0002)
    [  227.218906] jmb38x_ms 0000:01:00.3: PCI INT A -> GSI 16 (level, low) -> IRQ 16
    [  227.218931] jmb38x_ms 0000:01:00.3: setting latency timer to 64
    [  227.617315] mmc1: new SDHC card at address 0001
    [  227.617720] mmcblk1: mmc1:0001 SD8GB 7.32 GiB
    [  227.621661]  mmcblk1: p1 p2
    [  228.753036] EXT4-fs (mmcblk1p2): mounted filesystem with ordered data mode. Opts: (null)

    From above output the device is /dev/mmcblk1 (we ignore the partition portion p2).

    WARNING:   It is very important to identify the correct device. Use of the wrong device path can result in loss of data and/or the operating system.

  4. Ensure that the device is unmounted by checking the output from df to see if the device is in use.

    Example output:

    $ df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda1        6734812 5612328    780368  88% /
    udev              499152       4    499148   1% /dev
    none              506428       8    506420   1% /tmp
    tmpfs             101288     844    100444   1% /run
    none                5120       0      5120   0% /run/lock
    none              506428      72    506356   1% /run/shm
    none              506428     572    505856   1% /var/log
    none              506428       0    506428   0% /var/tmp
    /dev/mmcblk0p1  15615056 1183088  14431968   8% /media/mmcard16gb
    /dev/mmcblk1p1    261868  111280    150588  43% /media/0F39-638F
    /dev/mmcblk1p2   7177771   83036   7094735   2% /media/0c0676d8-24f7-43c4-8bed-d19e6ea3a147

    If the device is in use then unmount each mount point.

    Using the example above we unmount two locations from mmcblk1:

    sudo umount /media/0F39-638F
    sudo umount /media/0c0676d8-24f7-43c4-8bed-d19e6ea3a147
  5. Write the image to the microSD Card.

    Be sure to use the correctly identified device! In this example the device path is /dev/mmcblk1.

    zcat ~/Downloads/LibreELEC-*.img.gz | sudo dd of=/dev/mmcblk1 bs=4M
    sync
  6. Remove the microSD Card.

B. Insert MicroSD Card and Power on Raspberry Pi

At first power up the image will be resized to use the entire microSD card, and then the RPi3 will reboot.

  1. At Welcome to LibreELEC screen choose Next.

  2. At Hostname prompt change or leave name LibreELEC and choose Next.

  3. At Networking screen with Wired and Wireless networks listed choose Next.

  4. At Sharing and Remote Access screen under Configure Services enable SSH and disable Samba. Choose Next.

    Enable Samba if you wish to access Windows network shares.

    Note that username is root and pasword is libreelec.

  5. At Thank you screen choose Next.

TIP:   Recommend Disabling LibreElec Automatic Updates

New issues can be encountered if/when LibreElec automatically upgrades the system. For example I heard audio crackling when playing TV show recordings after LibreElec automatically updated to 8.2.4 and to 8.2.5.

To disable LibreElec automatic Upgrades:

Navigate to Gear icon (System) -> LibreElec -> Updates.
Change Automatic Updates to manual.
Reboot to stop any currently downloading system update in progress.

C. Enable MPEG-2 Hardware Video Decoding

If you have not already done so, purchase an MPEG-2 license key from the Raspberry Pi Store. Cost is ~2 British Pounds. The license key will be sent to the email address you provide (can take up to 72 hours).

Note that a VC-1 license key is also available, but it is not needed to view North American Over-The-Air content which is in MPEG-2 format.

  1. Lookup the IP Address in Kodi for the Raspberry Pi.

    Navigate to System (gear icon at top) and press Enter.

    Navigate to System information and press Enter.

    Make note of the IP address.

    In this example we will use 192.168.1.68.

    Press Escape twice to back out to the main screen.

  2. Open a terminal window on a different GNU/Linux computer and make a secure shell connection to the IP address of your Raspberry Pi.

    Be sure to use the IP address for your RPi3 on your network.

    ssh root@192.168.1.68

    The password is libreelec all lowercase.

  3. In the SSH session mount the /flash directory with read and write privileges.

    mount -o remount,rw /flash
  4. Edit the /flash/config.txt file to add the MPEG-2 license key.

    nano /flash/config.txt

    Locate the decode_MPG2 line, remove the # and space at the front, and add your MPEG-2 license key.

    decode_MPG2=0x8ff5a5c7

    If you wish to share a microSD card image with multiple RPi3s then you can string together a maximum of 8 licenses. For example:

    decode_MPG2=0x8ff5a5c7,0xd4cb22af,0xe05b40bc,0xa54335b8,0x5964579b,0xafd24232
  5. Fix analog audio crackling with LibreELEC 8.2.4 and 8.2.5 [Optional]

    If you experience analog audio crackling, such as when playing OTA MPEG2 1080i recordings, then add the following config.txt parameter.

    audio_pwm_mode=0
  6. Potential fix for overscan issue [Optional]

    If the edges of the kodi display are not visible on the physical screen, then try adding or uncommenting the overscan_scale=1 config.txt parameter.

    overscan_scale=1
  7. Save and exit the editor with Ctrl+X.

  8. Return the /flash directory back to read only privileges.

    mount -o remount,ro /flash
  9. Reboot the Raspberry Pi. This will close the SSH session.

    reboot

If you wish you can check if the MPEG-2 decoder is enabled via an SSH connection with the following command:

vcgencmd codec_enabled MPG2

The MPEG-2 hardware video decoder should now be enabled.

D. Enable 3.5mm Headphone Jack Audio [Optional]

  1. Navigate to System (gear icon at top) and press Enter.

  2. Navigate to System Settings and press Enter.

  3. Navigate to Audio and press Enter.

  4. Navigate right to Audio output device and press Enter.

  5. Navigate down to PI: HDMI and Analogue and press Enter.

  6. Press Escape twice to back out to main screen.

E. Set Time Zone Details

  1. Navigate to System (gear icon at top) and press Enter.

  2. Navigate to Interface settings and press Enter.

  3. Navigate to Regional.

  4. Navigate right to Language.

  5. Navigate down to Timezone country and press Enter.

    Set the following:

    Timezone country    # e.g., Canada
    Timezone            # e.g., America/Edmonton
  6. Press Escape twice to back out to main kodi screen.

F. Disable Wireless Networks [Optional]

The reason for disabling wireless networks is to reduce the power required by the RPi3 and hence have more power available for the hard disk drive. By default Bluetooth is already disabled.

  1. Navigate to System (gear icon at top) and press Enter.

  2. Navigate to LibreELEC and press Enter.

  3. Navigate to Network.

  4. Navigate right to Wireless Networks.

  5. With Active highlighted press Enter.

  6. Press Escape twice to back out to main kodi screen.

G. Enable OTA TV Show Subtitles

After spending a few days trying to figure out how to enable OTA TV show subtitles I had almost given up when I stumbled across this forum post for Kodi 17 Alpha 2 Video setting for Parse CC. Originally it appeared that the setting was not available from the Kodi 17 Krypton default Estuary skin, but was available in the previous Kodi default Confluence skin. Later on I learned that one must enable a higher settings level to view the closed caption setting. Following are the steps to enable closed captions / subtitles.

Enable Closed Captions

Here we enable the ability to parse for closed captions contained within the recorded ATSC TV shows.

  1. Navigate to System (gear icon at top) and press Enter.
  2. Navigate to Player settings and press Enter.
  3. Navigate to bottom of menu and change Settings level from Standard to Expert by using Enter key.
  4. Navigate to Language.
  5. Navigate right then down to Enable parsing for closed captions and press Enter to toggle to active.
  6. Navigate left then down to bottom of menu and optionally change Settings level back to Standard from Expert by using Enter key.
  7. Press Escape two times to back out to main menu.

Activate MCE Remote Subtitle Button [Optional]

These steps should enable the Subtitle, Teletext or Closed Caption button on an MCE remote control so you can easily toggle closed captions on and off without having to go through the menu.

  1. Open a terminal window on a different GNU/Linux computer and make a secure shell connection to the IP address of your Raspberry Pi.

    Be sure to use the IP address for your RPi3 on your network.

     ssh root@192.168.1.68

    The password is libreelec all lowercase.

  2. Change to the ~/.kodi/userdata/keymaps directory.

     cd  ~/.kodi/userdata/keymaps
  3. Create/edit remote.xml file.

     nano remote.xml
  4. Cut and paste the following content.

     <?xml version="1.0" encoding="UTF-8"?>
     <keymap>
       <FullscreenVideo>
         <remote>
           <teletext>ShowSubtitles</teletext>
         </remote>
       </FullscreenVideo>
     </keymap>
  5. Save the file with Ctrl+O and exit with Ctrl+X.

H. Install Tvheadend Add-ons

Tvheadend Server

From main Kodi menu:

  1. Navigate to Add-ons, right to Install from repository and press Enter.

  2. Navigate to LibreELEC Add-ons and press Enter.

  3. Navigate to Services and press Enter.

  4. Navigate down to Tvheadend Server 4.2 and press Enter

  5. On Install press Enter.
    Wait for download to complete.

  6. Navigate up to .. and press Enter.

At time of writing Tvheadend v4.2.3-20 was installed.

Tvheadend HTSP Client

  1. Navigate to PVR clients and press Enter.

  2. Navigate down to Tvheadend HTSP Client and press Enter.

  3. On Install press Enter.
    Wait for download to complete.

  4. Navigate to Configure and press Enter.

  5. Navigate down to Timer Settings and change:

    Default Lifetime: Forever (tvh 4.1+)

    Previously was 3 months.

  6. Navigate to OK and press Enter.

  7. Press Escape twice to back out to main kodi screen.

I. Attach USB Hard Drive (if not already connected)

  1. Exit Kodi and power down by navigating to the Power icon and press Enter.

  2. Navigate to Power off system and press Enter.

  3. Disconnect Raspberry Pi 3 power supply from wall or switch off power bar.

  4. Attach USB hard drive.

  5. Connect Raspberry Pi 3 power supply or switch on power bar.

  6. Kodi should now boot.

Note that the default file system on the Seagate hard drive is NTFS. If you wish to be able to attach the drive to a Windows computer, then keep the NTFS file system. I did this just to see if it would work (it does). Otherwise I recommend reformatting the partition to the ext4 filesystem for its superior ability to keep fragmentation to a minimum.

J. Create Recordings Folder on Hard Drive

  1. Navigate to System (gear icon at top) and press Enter.

  2. Navigate to File manager and press Enter.

  3. Navigate to Seagate_Backup_Plus_Drive and press Enter.

    Kodi File manager

  4. Press C to pop up a context menu.

  5. Navigate to Make new folder and press Enter.

  6. Type in recordings and press Enter.

    Kodi File manager

Note that by default the Seagate USB hard drive was automatically mounted on /var/media/Seagate Backup Plus.

  1. Press Escape twice to back out to main kodi screen.

K. Configure Tvheadend from a Computer Web Browser

Find the IP address of your LibreELEC box. From main kodi menu:

Settings -> System Information.

Now on computer with a web browser visit http://**RPi3-IP-Address**:9981.
(e.g., http://192.168.1.68:9981)

  1. At Welcome - Tvheadend - your TV streaming server and video recorder screen enter your language details.

    **Web interface**
      Language:    English (US)
    
    **EPG Language (priority order)**
      Language 1:  English (US)

    Tvheadend Welcome

    Click Save & Next.

  2. At the next Welcome - Tvheadend - your TV streaming server and video recorder screen I didn't change any settings.

    On this screen you could configure additional security settings. For this proof of concept I did not set any restrictions.

    If you do choose to set an admin user/password for the web interface then you will need to enter this in the Tvheadend HTSP Client settings on the LibreELEC box. These settings are available at Add-ons -> Install from repository -> LibreELEC Add-ons -> PVR clients -> Tvheadend HTSP Client -> Configure -> Connection settings: Username/Password.

    Tvheadend Welcome

    Click Save & Next.

  3. At the Network settings screen configure the TV tuners.

    In my case both HDHomeRun ATSC-T Tuners were automatically detected. I only had to set the Network type on each tuner to ATSC-T Network.

    Tvheadend Network settings

    Click Save & Next.

  4. At the Assign predefined muxes to networks screen select the appropriate pre-defined mux.

    For North America in the drop down menu for Pre-defined muxes choose a full scan from channel 2 to channel 52 by selecting United States: us-ATSC-center-frequency-8VSB-062009.

    Tvheadend Assign predefined muxes to networks

    Click Save & Next.

  5. At the Scan status screen wait for the scan to complete.

    The scan should find TV channels available in your area. In my case it found 6 channels which is all of the Over-The-Air TV channels available in my area.

    Tvheadend Scan status

    Click Save & Next.

  6. At the Service mapping screen select Map all services.

    Tvheadend Service mapping

    Click Save & Next.

  7. The Finished screen indicates that the guided setup is complete.

    Tvheadend Finished

    Click Finish.

  8. The Tvheadend backend will next scan the TV stations for OTA Electronic Program Guide data.

    Tvheadend Finished

    Note that you should not wait for the scan to complete.

    Out of curiousity I did wait over 30 minutes for the Electronic Program Guide scan to complete. I noticed that when one scan completed it moved down to start the scanning the next TV show title. My guess is that this might run all the time especially with different TV shows starting on the half hour.

  9. Set the recordings directory.

    Click on Configuration tab then Recording tab.

    Under Recording file options set:

    **Recording system path**:   /var/media/Seagate Backup Plus/recordings

    Click Save.

    Note that the default location /storage/recordings is on the MicroSD card. MicroSD cards are slow and generally not large enough to hold ATSC MPEG2 recordings which can be up to 9GB per hour of content.

    Tvheadend Configuration Recording

  10. Close the Web Browser.

L. Improve Power Outage Recoverability

After power outages the Tvheadend service does not always restart properly. I suspect the issue is that it takes a while for the Internet modem, router, HDHomeRun tuner, and RPi3 to all acquire working Network IP addresses. If the RPi3 is up and running first, it might fail to contact the HDHomeRun tuner and hence not configure Tvheadend properly to record TV programs.

The following steps try to alleviate this issue of no upcoming recordings on TV screen / Tvheaded not properly started after a power outage.

Add a time delay to the startup of Tvheadend.

  1. Navigate to Add-ons -> My Add-ons -> Services -> Tvheadend Server 4.2 -> Configure.

  2. Select DVB on left-hand side.

  3. Enable Delay the start of Tvheadend.

  4. Set Seconds delay = 30.

  5. Select OK on right-hand side.

  6. Press Escape three times to back out to main kodi screen.

Make RPi3 wait for network before starting Kodi and Tvheaded.

  1. Navigate to Gear icon (System) -> LibreELEC.

  2. Select Network on the left-hand side.

  3. Navigate to Advanced Network Settings on right-hand side.

  4. Enable Wait for network before starting Kodi by pressing Enter.

  5. Navigate down to Maximum Wait Time (Sec.).

  6. Change from 10 (default) to 180 seconds.

  7. Select Done.

  8. Press Escape twice to back out to main kodi screen.

Watch and Record TV

At this point you should be able to watch live TV in Kodi and also record and watch TV programs.

Screen shot of Kodi with active recording of two TV shows simultaneously. Kodi actively recording 2 TV shows

Watch Live TV

  1. Navigate to TV -> Channels.

  2. Select a channel and press Enter.
    The TV show will be displayed with the menu overlayed.

  3. Press Enter to remove menu overlay.

  4. Press M to display lower menu control bar.

  5. Select square icon and press Enter to stop playing.

  6. Press Escape to return to TV menu.

Record TV - Manual VCR Style

To add a recording rule based on channel, start time, and end time:

  1. Navigate to TV -> Timers and press Enter.

  2. Navigate to Add timer... and press Enter.

  3. Choose details such as Channel, Start date/time, and End date/time.

  4. Navigate to OK and press Enter.

  5. Press Escape to return to TV menu.

Record TV - Electronic Program Guide

You can also record TV shows using EPG data:

  1. Navigate to TV -> Guide and press Enter.

  2. Select a TV show and press Enter.

  3. Choose a single or multiple recording:

    • To record a single instance of a show choose Record.
    • To create a rule to record multiple instances or episodes of a show choose Add timer.
  4. Adjust record/timer details if desired.

    I suggest changing the Lifetime from the default value of 3 months to forever.

  5. Navigate to OK and press Enter.

  6. Press Escape to return to TV menu.

Watch Recording

  1. Navigate to TV -> Recordings and press Enter.

  2. Select TV show title and press Enter.

  3. Select TV show episode and press Enter.

  4. Press M to display lower menu control bar.

  5. Select square icon and press Enter to stop playing.

  6. Press C to display context menu.

  7. [Optional] Navigate to Delete and press Enter if you wish to delete TV show episode.
    Navigate to Delete and press Enter.

  8. Press Escape to return to TV menu.

View Closed Captions

To display subtitles / closed captions while viewing Live TV or a recording:

  1. Press M to bring up menu.

  2. Navigate right to the Subtitles icon.

  3. Navigate up to Enabled and press Enter to toggle to active.

  4. Press Escape to dismiss the menu

Observations

Following are some of the observations I noted while working with this proof-of-concept PVR.

General

  • Duration of testing was 10 days.

  • A total of 96 TV shows were recorded containing over 70 hours of content.

  • Tvheadend proved stable and reliable.

  • On one occasion after staging the PVR for pictures and then re-assembing again, the tvheadend service failed to start. To restart the Tvheadend service I navigated to Add-ons -> My add-ons -> Services -> Tvheadend Server 4.2 and clicked Disable, waited a short time, then clicked Enable.

  • Kodi would occasionally crash/restart when I wasn't actively using it, but this did not adversely affect recordings in progress.

  • Kodi crashed one time while I was trying to watch a channel that had poor reception. Once I re-positioned the aerial for better reception I never again experienced a crash while watching either Live TV or a recording.

  • Over-The-Air Electronic Program Guide data was sparse with only a handful of hours of data in advance. For example on Nov 30th:

RPi3 Temperature Under Load

After encountering RPi3 overheating issues under load, I added two aluminum heat sinks. I then used an SSH session to monitor the temperature every 10 seconds with the following command:

watch -n 10 vcgencmd measure_temp

From some Internet research I learned that the RPi3 operating temperature range is ~0 to 80 deg C, and that the System-On-a-Chip (SOC) will throttle down at about 80 deg C.

Following are the temperatures under load that I observed in my house which is at 20 degrees Celsius:

RPi3 with
Aluminum
Heatsinks
(°C)
RPi3 with
Aluminum
Case
(°C)
Work Load
59 49 When not watching and not recording.
61 50 When not watching but 1 recording in progress.
63 54 When watching live TV with 0 recordings in progress.
68 56 When watching live TV with 1 recording in progress.
71 59 When not watching but 2 recordings in progress.
76 63 When watching recording with 2 recordings in progress.

From the above it appears that the RPi3 gets very close to the operating maximum of 80 °C when under full load of watching a recording concurrent with two recordings in progress, even with aluminum heatsinks installed.

With the aluminum case which provides passive cooling with parts of the case in contact with the CPU/GPU, RAM, and Ethernet chips, the temperatures are at least 10 °C cooler.

RPi3 Resource Usage Under Load

Following is a screen shot of resource usage when the RPi3 was under the following load:

  • active recording of two TV shows at the same time
  • active viewing of another previous recording

Screen shot of top command under heavy load:

Terminal top command under load

From the above screen shot we can see that much of the resources available on an RPi3 are being used. The four CPUs are working quite hard because the load average is 2.73. A quad core processor is considered 100% utilized at a load average value of 4.0. Also while there is only 162 MB of RAM shown as used, only 33 MB of RAM is shown as free for other processes. I suspect Kodi with 660 MB virtual memory uses a large internal cache.

These statistics indicate that under this load scenario the RPi3 is managing to keep up, but there is not much in the way of free resources available for additional tasks.

Pros

  • Low cost (less than half the cost of my x86-64 based MythTV PVR)

  • Low 17.5 watt maximum power requirement
    17.5 watts = ( (5 Volts * 2.5 Amp RPi3 power supply) + (5 Volts * 1 Amp HDHomeRun power supply) )

  • Supports basic PVR functions of record, play, pause, fast forward, rewind

  • Supports watching one recording while actively recording two TV shows

  • Supports Kodi add-ons for additional Internet stream viewing options

Cons

  • Less stable (Kodi occasionally crashes and restarts, but this does not adversely affect recordings)

  • Limited upgrade options (most RPi3 resources in use under load so adding extra tuners not likely feasible)

  • Less options for skip forward / skip back and slower response compared to MythTV which is virtually instantaneous.

Conclusion

This proof-of concept has shown that these tutorial instructions are a viable way to build a functional PVR using a Raspberry Pi 3, a USB hard drive, and an HDHomeRun Connect network dual tuner.

The PVR as built was able to display a recording while also actively recording two TV shows simultaneously.

While this solution is tempting for its lower cost, my spouse and I have come to appreciate the flexibility, upgradability, and reliability of our Mythbuntu PVR with 4 TV tuners that also supports content streaming via Firefox and Kodi so we have the best of all worlds.

Thanks for reading. I hope you enjoyed this article.

References

While working on this article I found the following references useful:

Appendix A: Trials and Tribulations

Initially the system was not very stable and was prone to hang due to overheating. This was resolved by adding aluminum heatsink cooling fins. Following are descriptions of the events that occurred during my testing:

Date / Timestamp  Description
2017-11-30 8:00pm RPi3 was hung after running ~3 hours. A dimmed Kodi TV Recording screen was still displayed. There was no response to keyboard or remote, and I was unable to SSH in. While I did not observe the cause of the hang an hour after it happened (based on still image with time in display) I suspect that the RPi3 overheated. I had to cycle the power get the system working again.
2017-12-01 9:53am Kodi crashed and restarted by itself. At the time I was trying to tune in a channel with poor reception and fast forward in a pixelated recording.
2017-12-01 10:17am Kodi crashed and restarted by itself. At the time I wasn't doing anything. This Kodi restart did not appear to affect the recordings in progress at the time.
2017-12-02 11:27am While viewing Modern Family recording, I tried to view OTA subtitles and couldn't find these (one recording was active at same time). Next I tried to Browse for subtitles. Shortly thereafter the RPi3 hung with a high temperature thermometer icon in the upper right corner of the screen (RPi3 was hot to touch). Uptime was ~25 hours. Had to power off and wait for RPi3 to cool down.
2017-12-02 11:51am On power-up Kodi complained Tvheadend HTSP Client didn't respond properly. There was no data shown for TV Channels/Guide/Recordings, etc. Powered down again.
2017-12-02 11:53am On power-up Kodi complained Tvheadend HTSP Client didn't respond properly. There was no data shown for TV Channels/Guide/Recordings, etc. Powered down again. Powered down again and will leave down for longer period.
2017-12-02 12:38pm On power-up Kodi complained Tvheadend HTSP Client didn't respond properly. Powered down again and will leave for powered off while I contemplate options to reduce the chance of overheating. One theory is that the RPi3 got too hot from powering both RPi3 and USB hard drive. Another more likely theory is that the RPi3 got too hot from high GPU and CPU load.
2017-12-02 1:29pm Added aluminum heatsink cooling fins to RPi3 GPU/CPU and Ethernet chip. On power-up Kodi complained Tvheadend HTSP Client didn't respond properly. I forced an update of the Tvheadend HTSP Client add-on, rebooted, and finally there was no complaint about Tvheadend HTSP Client.
2017-12-03 11:32am Kodi displays same TV screen I left it on previously.
2017-12-04 10:04am I noticed that Kodi was not on the same TV screen I had left it on previously. Because uptime reports 10:04:54 up 1 day, 20:34, it appears that only kodi restarted and not the whole OS.
2017-12-04 11:30am Kodi crashed and restarted by itself. At the time I wasn't doing anything. This Kodi restart did not appear to affect the recordings in progress at the time.
2017-12-04 7:13pm Change skin from Kodi Krypton default of Estuary to previous Kodi version default of Confluence. Finally I can enable parsing for closed captions / subtitles in OTA TV shows.
2017-12-05 9:45am Kodi displays same TV screen I left it on previously. Uptime reports 09:45:33 up 2 days, 20:15.
2017-12-05 2:38pm Kodi not on the TV screen I left it on previously. Because uptime reports 14:39:06 up 3 days, 1:08, it appears that only kodi restarted and not the whole OS.
2017-12-05 3:19pm Change skin back to Kodi Krypton default of Estuary.
2017-12-06 10:24am Kodi not on the TV screen I left it on previously. Because uptime reports 10:24:59 up 3 days, 20:54, it appears that only kodi restarted and not the whole OS.
2017-12-06 2:09pm Kodi not on the TV screen I left it on previously. Because uptime reports 14:09:21 up 4 days, 39 min, it appears that only kodi restarted and not the whole OS.
2017-12-06 3:51pm Kodi displays same TV screen I left it on previously. Uptime reports 15:51:03 up 4 days, 2:20.
2017-12-07 9:43am Kodi not on the TV screen I left it on previously. Because uptime reports 09:43:09 up 4 days, 20:12, it appears that only kodi restarted and not the whole OS.
2017-12-07 10:50am Kodi crashed and restarted right before my eyes. I hadn't been doing anything on the system for the past hour or so.
2017-12-08 10:04am Kodi not on the TV screen I left it on previously. Because uptime reports 10:04:22 up 5 days, 20:34, it appears that only kodi restarted and not the whole OS.
2017-12-08 1:56pm Kodi displays same TV screen I left it on previously. Uptime reports 13:56:03 up 6 days, 25 min.
2017-12-08 8:01pm Kodi displays same TV screen I left it on previously. Uptime reports 20:01:44 up 6 days, 6:31.
2017-12-09 11:33am Kodi not on the TV screen I left it on previously. Because uptime reports 11:33:24 up 6 days, 22:03, it appears that only kodi restarted and not the whole OS.
2017-12-09 2:12pm RPi has now been running successfully for a week. Uptime reports 14:12:34 up 7 days, 42 min. Although Kodi crashes from time to time, it automatically restarts itself and does not adversely affect recordings in progress.
2017-12-10 11:15am After I staged the PVR components for pictures and then re-assembled it, the Tvheadend service did not start on boot (much content was missing from the TV menu like Recently played channels and Recent recordings). I tried rebooting the RPi3 but Tvheadend still failed to start.

To restart the Tvheadend service I navigated to Add-ons -> My add-ons -> Services -> Tvheadend Server 4.2 and clicked Disable, waited a short time, then clicked Enable. I'm not sure why the the Tvheadend service failed to start in the first place, but wanted to note how I worked around the issue in case this happens to someone else.
2017-12-22 1:25pm Received aluminum case with passive cooling. Disassembled RPi3 from plastic case and removed aluminum heatsink cooling fins. Placed RPi3 in aluminum case (be sure to remove microSD card first to make more room for easier installation). After re-assembling all components, the Tvheadend service did not start on boot (much content was missing from the TV menu like Recently played channels and Recent recordings). I did notice that the RPi3 IP Address had changed.

To restart the Tvheadend service I navigated to Add-ons -> My add-ons -> Services -> Tvheadend Server 4.2 and clicked Disable, waited a short time, then clicked Enable.

Added temperatures for aluminum case to RPi3 Temperature Under Load table.
2018-06-10 11:35am Noticed overheat temperature symbol in upper right of display. Next recording on screen was for June 10th 10:30pm so I think it had not been overheated for long. Kodi was unresponsive to key presses. Aluminum case was hot to touch. We had just experienced hot exterior temperatures and I had noticed the interior was 25+ deg C, though this might not have been the cause. Powered off RPi3 to allow case to cool.
2018-06-10 1:00pm Case was now cool. Powered on RPi3. No upcoming recordings shown. Rebooted. Now have upcoming recordings on display.
2018-06-17 3:00am - 6:05am Power outage. On restoration of power the RPi3 PVR restarted, but no upcoming recordings shown on TV screen. I suspect that the HDHomeRun tuner or the Router were not operational when the RPi3 started. Restarting RPi3 fixed problem.
Perhaps a delay is needed on the start of Tvheadend?
2018-06-18 ~11:00am Try adding a 2 second delay to startup of Tvheadend.
Navigate to Add-ons -> My Add-ons -> Services -> Tvheadend Server 4.2 -> Configure. Select DVB on left-hand side. Enable Delay the start of Tvheadend. Set Seconds delay = 2, was 1. Click OK on right-hand side.
2018-06-22 ~11:50am Power outage (~4 minutes). On restoration of power the RPi3 PVR restarted but no upcoming recordings shown on TV screen. I suspect that the 2 second delay was insufficient because the router takes a while to go through it's power up checks before it acquires an IP address and begins dispensing DHCP IP addresses.
Set Seconds delay = 30.
2018-08-16 ~6:49pm Power outage (~2.4 hours). On restoration of power the RPi3 PVR restarted but no upcoming recordings shown on TV screen. It seems that the 30 second delay was not sufficient. After manually rebooting Tvheadend started properly.
2018-08-22 ~6:50pm Instruct RPi3 to wait for network before starting Kodi.
Navigate to Gear icon (System) -> LibreELEC. Select Network on the left-hand side. Navigate to Advanced Network Settings on right-hand side. Enable Wait for network before starting Kodi. Change Maximum Wait Time (Sec.) from 10 to 180. Rebooted to make sure system still works properly. Now need to wait to see what happens with the next power outage.
2018-11-16 ~8:50am While testing an Android app that scans the local network for hosts, I noticed that the RPi3 was not responding to a ping. The RPi3 was hot to touch, even though it is Winter here and the ambient temperature in the house is 20 deg C or less. The SiliconDust HDHomeRun was responding to pings.
Further investigation showed Kodi stuck on the TV screen with a time of 10:23pm and a notice that the next recording was for Nov. 14, 2018 at 7:00pm. Hence the RPi3 had been unresponsive for at least two days.
Fix by turning off power for a while and then turning power back on.
2018-11-22 ~7:42pm Noticed that the RPi3 was showing a black screen. I could ping the RPi3 but was unable to login via ssh as there was no service listening on the ssh port.
Fix by turning off power for a while and then turning power back on.
2018-11-29 ~10:07am Kodi stuck on TV screen showing 2:14pm and next recording on 11/28/2018 7:00pm. RPi3 not responding to ping.
This problem could be fixed by cycling the power off and on.
At this time I bring to a close the test of using an RPi3 as a PVR.
2019-01-14 ~11:06am Update to LibreELEC 8.2.3 and begin testing RPi3 PVR again.
2019-03-31 ~10:15am Update to LibreELEC 8.2.5 and add audio_pwm_mode=0 to /flash/config.txt to fix analog audio crackling problem with LibreELEC 8.2.4 and 8.2.5.
2019-04-06 ~11:00am Tried a Raspberry Pi 2 (RPi2). Performance was good; however, there was some occasional pixelation when watching a recording while two recordings were in progress. Noticed Closed Captioning (CC) only displayed the first sentence of recent Modern Family recordings, and did not follow along with the dialog.

Switched back to RPi3 from RPi2. Same issue with CC noticed.

Downgraded to LibreELEC 8.2.3 and problem with CC is still there. Tried with recent Kim's Convenience recordings and there was no problem with CC.

Upgraded to LibreELEC 8.2.5 and noticed CC problem with recent Modern Family recordings still exists. There was no problem with CC with recent Kim's Convenience recordings. Hence it appears that there is some issue with LibreELEC 8.2.x and CC and recent Modern Family recordings.

Decided to keep PVR setup as RPi3 with LibreELEC 8.2.5.
2019-04-13 11:45am Increase recording file retention.
Navigate to Gear icon (System) -> PVR & Live TV settings -> Recording and change Default recording lifetime from default 99 days to maximum of 365 days.
2019-12-05 12:49pm This PVR continues to run well going on two years now.
2020-06-08 10:00am Recently two of my local channels migrated to a different frequency as part of a Digital Television (DTV) Allotment Plan. As such I changed the Configure Tvheadend section to use the full scan of channels 2 through 69 by selecting Pre-defined muxes of United States: us-ATSC-center-frequency-8VSB-062009. Previously for me this was Canada: ca-AB-Calgary.
2021-01-22 10:00am Shutdown and stop testing with this RPi3 Tvheadend PVR. Now using MythTV on an RPi4 4GB.
2021-02-11 1:30pm Update RPi3 Tvheadend PVR to LibreELEC 9.2.6 with Kodi 18.9.

Restart testing of this RPi3 Tvheadend PVR in parallel with testing RPi4 4GB MythTV PVR.

For reference I wrap up the trials and tribulations with a screen shot of the top command after running for 7 days:

Terminal top command after 7 days

Happy hobby computing with your Raspberry Pi.

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!