Raspberry Pi

From MythTV Official Wiki
Jump to: navigation, search

Software-update-available.png This page is up-to-date as of MythTV version 29, the current release is 29.0

Overview

The Raspberry Pi is cheap and can be a decent frontend for a MythTV backend. The Raspberry Pi is a credit-card sized computer that costs around $30 barebones. Once you add a case, power supply and SD card it will run about $55. It supports HDMI output for audio and video, as well as composite video and analog stereo. When using HDMI it also supports CEC so that you can use the TV remote control to control MythTV. This is very converient for places where you cannot have a full size computer, such as kitchen. With its case, the Raspberry Pi is about the same size as the DTA devices from cable companies.

As of version 0.28, MythTV frontend is supported on Raspberry Pi 2 and above. There is also an unofficial release of 0.27 that works on Raspberry Pi 2.

Kodi has a plugin that supports mythtv frontend features. Kodi is a multimedia package that has very good support for Raspberry Pi.

MythTV frontend

Operating System

The Raspberry Pi supports several linux variants.

Raspbian

This is the original operating system for Raspberry Pi and supports all features of MythTV frontend.

For installable packages see MythTV Light.

Ubuntu (not recommended)

Several flavors of Ubuntu are available for Raspberry Pi.

  • Ubuntu Server
  • Xubuntu
  • Lubuntu
  • Ubuntu Mate

When using Ubuntu you can use the Mythbuntu PPA to download the latest package.

When running on Ubuntu some MythTV features do not work (these all work with Raspbian):

  • CEC does not work. You cannot use a TV remote to control MythTV.
  • OpenGL ES does not work. On-screen displays have to use softblend which can cause jerkiness in the video and audio.
  • There are reports that HDMI Audio does not work well.
  • There is a report that recent builds of MythTV do not work at all.

I strongly recommend using Raspbian rather than Ubuntu. Raspbian is optimized for this type of application. The developers are focused on Raspbian.

Arch Linux

There is a version of Arch Linux for Raspberry Pi.

Setup on Raspbian

First you need to have a MythTV backend set up on your local network. The Raspberry Pi will function as a remote frontend. It is best to use a wired connection, rather than wifi, especially if you are playing High Definition content.

  1. Download and install a Raspbian full desktop image on a microSD card. If needed, older Raspbian images can be downloaded here.
  2. Boot Raspberry Pi with microSD card.
  3. Configure gpu_mem=256 using sudo raspi-config
  4. If you are running the August 2017 version of Raspbian Stretch you will need to upgrade the firmware, as follows.
sudo apt update
sudo apt dist-upgrade
sudo rpi-update
  1. Purchase and install an MPEG-2 License Key from the Raspberry Pi Store.
  2. See MythTV Light for instructions on downloading and installing a debian package that matches your Mythbackend version (e.g. 0.27, 0.28, 29).
  3. Start mythfrontend from the menu using Sound & Video -> MythTV Frontend, or from a terminal window with mythfrontend
  4. If you encounter video or audio issues you might need to experiment with different mythfrontend Setup values, and /boot/config.txt values.
  5. If you notice general stability problems (application hangs - in particular when navigating between menus or starting/stopping playback) check the settings of the MySQL server on the backend. If it's running MySQL v5.7 or newer there is an issue with query caching when using multiple clients with different versions. Jessie currently comes with MySQL client v5.5. See Optimizing_Performance#MySQL_Database_Tweaks.

If "MythTV frontend" does not appear in the menu, run the following commands:

rm ~/.cache/menus/*
lxpanelctl restart

Do not enable the experimental desktop GL driver. When this is activated, video playback does not work.

Video Playback Profile

The "OpenMax High Quality" profile is best for most cases, but will not work on Ubuntu systems. If that is not available, is jerky or does not work, use "OpenMax Normal".

Advanced hardware deinterlace does not work on certain combinations on MythTV and Raspbian. If you use the latest versions of both it will work correctly.

GPU Memory

When using "softblend" OSD renderer or "OpenMax Normal" profile, GPU memory must be at least 128 MB. When using another OSD renderer or "OpenMax High Quality" profile, GPU memory must be set as 256 MB or more. If you have stuttering performance, try increasing the GPU memory.

Audio

On Raspberry Pi, ALSA and OpenMax are supported audio output renderers. ALSA supports stereo output through either analog or HDMI devices. OpenMAX also supports both analog and HDMI devices, with more digital output options that ALSA.

ALSA Audio

Set the Audio device to "ALSA:default" to use the default output device. The default device is determined at boot time, or can be forced using the raspi-config utility. Alternatively select a specific ALSA device from the list. Make sure to select speakers as "Stereo". If you want to select Dolby Digital or DTS options you will need to add the bcm2835.conf file as described below, and select device ALSA:IEC958.

If there is a hiss from the speakers, add this line to the /boot/config.txt:

disable_audio_dither=1

To enable the MythTV volume control, set "Mixer Device" to "ALSA:default" and mixer controls to "PCM".

Low volume from 3.5mm jack

If you are using an analog TV or one without HDMI audio, you can use the analog audio from the 3.5mm jack on the Raspberry Pi. On digital channels this may give a low sound volume through a TV set. You can get good results with a software pre-amplifier.

Create file .asoundrc in your home directory. Paste the content from here:

~/.asoundrc
pcm.!default {
	type hw
	card 0
}

ctl.!default {
	type hw
	card 0
}


# Set your DEFAULT device to the softvol plug-in
# NOT to a hardware card device
#
# The "!" means completely override the previous default
# Not just changing/adding to it.
pcm.!default {
  type plug
  slave.pcm "softvol"
}

# Configure softvol
pcm.softvol {
  type softvol

  # Send softvol's output to dmix
  slave {
    # pcm "dmix"
    # If you wanted to you could send the output to a card directly
    # But in most cases it's better to send it to dmix and let
    # dmix handle where to send it. You can add a whole extra section
    # to configure dmix and where it sends output, but I'm
    # not covering that here.

    ## Use Card 0 Device 0 instead of dmix
    pcm "hw:0,0"
    ## Use Card 2 Device 0 instead of dmix
    # pcm "hw:2,0"
  }

  # Add a control slider in your mixer interfaces
  # i.e. KMix and alsamixer
  control {
    name "Pre-Amp"
    card 0
    # i.e. card 0 or card 2
  }

  # Minimum dB when slider is at 0%
  min_dB -5.0

  # Maximum DB when slider is at 100%
  # 40 is too much
  max_dB 10.0

  # How many levels the slider should go through
  # i.e. how granular do you want your control to be
  resolution 12
}

Select ALSA:default as your sound device (you may have to key it in if it is not in the list)

Add these to your .profile or somewhere where they will run before you start the frontend:

amixer set PCM Playback 100%
amixer set Pre-Amp Playback  9

You can adjust the values as needed. You can also run alsamixer to see and adjust the pre-amplification.

Digital Audio with ALSA

On Raspbian, ALSA audio performs better than OpenMax for AC3 & DTS 5.1 passthrough via HDMI. To enable AC3 and DTS passthrough you will need to define a new ALSA device.

sudo nano /usr/share/alsa/cards/bcm2835.conf

Paste the content from here:

/usr/share/alsa/cards/bcm2835.conf
#
# Configuration for the bcm2835 soc found on RPi
#

<confdir:pcm/iec958.conf>

bcm2835.pcm.iec958.0 {
	@args [ CARD AES0 AES1 AES2 AES3 ]
	@args.CARD {
		type string
	}
	@args.AES0 {
		type integer
	}
	@args.AES1 {
		type integer
	}
	@args.AES2 {
		type integer
	}
	@args.AES3 {
		type integer
	}
	type hooks
	slave.pcm {
		type hw
		card $CARD
		device 1
	}
	hooks.0 {
		type ctl_elems
		hook_args [
			{
				interface PCM
				name "IEC958 Playback Default"
				lock true
				preserve true
				value [ $AES0 $AES1 $AES2 $AES3 ]
			}
		]
	}
}

Reboot, start myth, navigate to /Setup/Audio and select the new ALSA IEC958 device which appears in the list of available devices. Select AC3 / DTS as appropriate for your amplifier / TV and test to ensure passthrough is working as expected. No mixer is required and you may select either Stereo or 5.1 speakers, both should work.

OpenMAX Audio

Important.png Note: OpenMAX digital audio only works properly with MythTV version 0.28-55-g2faf5fe or later, released 19 September 2016

With OpenMAX audio, the audio selection in raspi-config is not used. In MythTV frontend setup you can select OpenMAX analog or hdmi. If you select hdmi you can select digital options. See Digital Audio below. Digital Audio works better with ALSA.

When using OpenMAX audio, set "Mixer Device" to "OpenMAX" and mixer controls to "PCM".

If you hear no audio after selecting OpenMAX, check the volume control setting. Sometimes when switching audio devices the system defaults to zero volume.

Digital Audio

Digital passthrough of Dolby Digital (AC3) and DTS can be selected when using ALSA:IEC958 with the bcm2835.conf file listed above(see Digital Audio with ALSA), or with OpenMAX:hdmi selected.

  • Dolby Digital can be selected. This enables pass through of Dolby Digital audio to your TV or surround sound receiver. You need either a surround sound receiver or a TOSLINK output from your TV to pass the Dolby digital through to your surround sound system.
  • 5.1 or 7.1 speakers can be selected. If you do not select Dolby Digital, the system will use multi-channel PCM. You need a surround sound receiver that has HDMI input and supports multi channel PCM. Note that TOSLINK does not support multi-channel PCM.

When selecting Dolby Digital, if you select 5.1 or 7.1 channels, you may also have situations where MythTV uses multi-channel PCM. This happens if MythTV is doing any audio processing, for example software volume control or sound stretch. If you select Dolby Digital and are using TV speakers or using a cable from your TV to your surround system, you should select stereo speakers, even if you have 5.1 or 7.2 speakers. Dolby Digital surround sound will still be passed through to all of your speakers by your sound system.

In the audio setup the "Speaker Test" will only work on left and right speakers unless you have a surround sound receiver that has HDMI input and supports multi-channel PCM.

System Performance

To provide adequate system performance for smooth audio and video try these steps. Playing smooth video requires the full capacity of the Raspberry Pi, and getting the best results for your situation calls for finding the right combination of settings.

  1. Make sure you are using an OpenMAX Video Playback profile. Others, such as Normal or Slim will give very poor results.
  2. Set the Raspberry Pi into performance mode as follows:
    echo "performance" |sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    This needs to be run after each reboot.
  3. If you are using a Raspberry Pi 2, overclock using the setting in raspi-config. Use setting High (High 1000MHz ARM, 500MHz core, 500MHz SDRAM, 2 overvolt). This will not damage your RPI2 or void the warranty.
  4. Use ALSA:Default for audio rather than OpenMAX. Leave speakers as Stereo and do not check any of the Digital options (Dolby Digital, etc.).
  5. If OpenMAX High Quality results in jerky audio or video, select OpenMAX Normal.
  6. New releases of Raspbian include pulseaudio. Disable pulseaudio as follows. Edit /etc/pulse/client.conf. Uncomment the line autospawn=yes and replace the yes with a "no".
  7. Increase the GPU memory. If you are using features like HD, Digital Audio, OpenMAX High Quality it may be necessary to go up to 320MB. Higher screen resolutions need more GPU memory.

Subtitles

When displaying subtitles you may find that the video or audio becomes jerky. This is more likely with Raspberry Pi 2 than with Pi 3. If that happens go to Setup->Video->Playback->Playback Profiles (3/8) -> Edit. Change Osd Renderer to "threaded". This will cause a slower response to keyboard events but will give smoother audio and video with subtitles.

When playing recordings from USA TV you may find that subtitles are not available. To see the subtitles, edit the /boot/config.txt file and comment or remove the MPEG2 license, reboot. This may result in Jerky video with Raspberry Pi 2, but works well with Raspberry Pi 3. When running without an MPEG2 license on Raspberry Pi 2, set Osd renderer to softblend for least jerkiness.

On Screen Display

There are three OSD renderers available. Here are results of testing the various scenarios of on screen display renderers.

With MPEG2 license

With USA TV recordings you may not see any subtitles.

OSD Render When OSD is displayed Keyboard When Subtitle Displayed
Audio Video Audio Video
PI2 softblend Slight Jerk Jerky OK Smooth Jerky
PI2 opengl Smooth Smooth OK Smooth Jerky
PI2 threaded Smooth Smooth SLOW Smooth Smooth
PI3 softblend Smooth Smooth OK Smooth Smooth
PI3 opengl Smooth Smooth OK Smooth Slight Jerk
PI3 threaded Smooth Smooth SLOW Smooth Smooth
Without MPEG2 license

This may be used to support subtitles for USA TV, or just because you don't want to spend $2.50.

OSD Render When OSD is displayed Keyboard When Subtitle Displayed
Audio Video Audio Video
PI2 softblend Jerky Jerky OK Jerky Jerky
PI2 opengl Jerky(*) Jerky(*) OK Jerky Jerky
PI2 threaded Jerky(*) Jerky(*) SLOW Jerky Jerky
PI3 softblend Smooth Smooth OK Smooth Smooth
PI3 opengl Smooth Smooth OK Smooth Smooth
PI3 threaded Smooth Smooth SLOW Smooth Smooth

(*) - Jerky even without OSD display

Time Stretch

The 'Time Stretch' feature of MythTV allows for speeding or slowing playback of video and audio in a range from 0.5x to 2.0x.

The Raspberry Pi 2 and 3 have limited processing power. Slowdown will work for all values down to 0.5x. Speedup will work up to around 1.3 or up to 2.0 depending on the content and your setup.

The limiting factor on increasing speed is the video decoding. With 1080i at 30fps or 720p at 60fps the speedup can go up to around 1.3. Trying to go higher causes jerkiness and slowdown. With 720p at 30fps or 480p, speedup works fine up to 2.0x.

If you need to speed up HD content beyond what works you can first transcode to 720p or less at 30fps or less.

Remote Control with CEC

The Raspberry Pi supports CEC. If you connect to a CEC compatible Television set, you can use the TV remote control to control the Raspberry Pi. You will find that if the TV remote has play, stop, pause controls, that these can be used. Unfortunately many TVs which support CEC do not support the numeric keys.

To test and configure CEC, start up the MythTV frontend and navigate to Setup->Edit Keys. find any key and select a blank box at the bottom. Press enter. It will prompt you to type a key. Press keys on your remote until one shows a response. Press escape when asked whether to assign it. This way you can see which keys are available. Now you can navigate in the Edit Keys and assign your remote keys. With Global Select, up, down. left, right you can control most of MythTV. Additional buttons can be set to Menu, Information, Play, etc.

If you are using a TV or display monitor that does not support CEC, the CEC feature of MythTV may cause the start of mythfrontend to be slow as it retries CEC. In that case you can disable CEC by adding this parameter to the mythfrontend startup command:

-O libCECEnabled=0

mythfrontend uses CEC to turn your TV on when it starts up and to turn it off after mythfrontend exits. To prevent it from turning off your TV when the frontend exists, add this parameter to the mythfrontend startup command:

-O PowerOffTVOnExit=0

The following other settings are available and can be set this way:

-O PowerOffTVAllowed=0
-O PowerOnTVAllowed=0
-O PowerOnTVOnStart=0

Autostart MythTV on boot

I use the following script to start MythTV automatically on boot:

#!/bin/bash
#
# Run MythTV Frontend on Raspberry Pi 2 on Boot
#

# use "performance" mode to prevent the Pi from going into "power saving" mode
# where it slows down the CPU, and causing problems playing HD
echo performance | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

# Use your MythTV Backend values here.
IPADDR=xxx.xxx.xxx.xxx
MACADDR=xx:xx:xx:xx:xx:xx

# Waits
WAITIP=7
WAITBACKEND=40

# Wake up MythTV Backend if not responding
ping -c 2 $IPADDR
if [ $? -ne 0 ]; then
  wakeonlan $MACADDR
  echo "Waiting $WAITBACKEND seconds for MythTV Backend to boot..."
  sleep $WAITBACKEND
fi

sudo ntpdate-debian

# Run mythfrontend
logrotate --state /home/pi/log/logrotate.state /home/pi/log/logrotate.conf
mythfrontend --logpath /home/pi/log

You can then call the above script from

~/.config/lxsession/LXDE/autostart

or

~/.config/lxsession/LXDE-pi/autostart

to autostart MythTV.

Running without a desktop environment or window manager

Info from Doug Larrick[1]

1. Install 'matchbox-window-manager' package. This is a very lightweight window manager.

2. Set up to autologin to the pi account on boot in /etc/lightdm/lightdm.conf

3. Create a small script to restart mythfrontend if it exits; mine is in file /home/pi/bin/mythloop (must be set executable):

   #!/bin/bash
   while true; do
   mythfrontend
   sleep 3
   done

4. Create ~/.xsession file as follows:

   #!/bin/sh
   /home/pi/bin/mythloop &
   exec matchbox-window-manager

Finally, once this is done and working, ssh into the Pi, run 'top' and sort by memory / cpu, and deconfigure or uninstall stuff that's consuming a significant amount of either.

Setup on Ubuntu (not recommended)

The same process as for Raspbian works with Ubuntu, with a few differences.

Audio

Use the Setup, Audio to select your audio device. On Ubuntu, PulseAudio is available and selecting PulseAudio:default works better than Alsa:default in this system. You may need to try different selections to find what is best in your environment.

CEC

In Ubuntu, MythTV seems to be unable to find the CEC device. This is an outstanding issue for which we do not have a solution yet.

Video Playback Profile

The "OpenMax High Quality" profile and the OpenGL based OSD display do not work on Ubuntu, so you will have only the "OpenMax Normal" features available.

Kodi

Kodi is a multimedia package that has a MythTV plugin. Kodi and the plugin are not part of MythTV. They are a separate installable package. There are packages available that install a customized copy of Linux with the Kodi program.

Compatible With

The Openelec MythTV frontend currently states that it is compatible up to MythTv 0.28 and as it needs the API, then 0.27 is the minimum (Gerdesj (talk) 21:55, 30 August 2015 (UTC))

Detailed Specifications

The Raspberry Pi is a credit-card sized computer that plugs into your TV and a keyboard. The SoC is a Broadcom BCM2835. This contains an ARM1176JZFS, with floating point, running at 700Mhz, and a Videocore 4 GPU. The GPU is capable of BluRay quality playback, using H.264 at 40MBits/s. It has a fast 3D core accessed using the supplied OpenGL ES2.0 and OpenVG libraries.

How to make it work

A lot of work has been done to make XBMC/Kodi perform well on Raspberry Pi.

The steps you have to do are:

  • Install MythTV backend (0.27+) on a separate computer on your LAN.
    • Make sure you set a PIN for the API or set it to 0000
  • Install OpenElec version of XBMC to your Raspberry Pi.
    • Find (scroll down the list) and download the image file
    • Write the image to the SD card using say dd in Linux
    • On first boot Openelec will resize partitions
    • Run through the first run wizard to set host name etc
  • Connect your Raspberry Pi to your LAN and your TV.
  • Turn on the MythTV backend, Raspberry Pi and TV.
  • From within the XBMC/Kodi menu set up the PVR client to point to your MythTV backend.

Normal video playback runs smoothly. Menu navigation and TV program can be a bit laggy. One trick to increase Raspberry PI performance is to overclock the CPU/GPU. On the PI 2 this is unnecessary.

This is a good guide to enabling the PVR (MythTV) front end: kodi.wiki/view/MythTV_PVR#Connecting_Kodi_to_MythTV. Note that you must set a PIN on the backend or set it to 0000. If you don't use 0000 you will need to use the PIN to connect to the backend. The PIN is set in the General section of mythtv-setup.

Finding the plugin can be a bit challenging. On Openelec it is already installed but listed in the "disabled" plugins until you enable it.

More Information

You can purchase an MPEG2 hardware decoder license. Depending on your tuner this may help your recordings play. I have been able to play 1080p live TV from a DVBS2 connected backend on a PI 2 model B running current Openelec out of the box with no additional licenses or over clocking (Gerdesj (talk) 21:55, 30 August 2015 (UTC))

Other Links

  • Tarball by Curtis Gedak
 Built upon Raspbian Jessie for MythTV 0.27 using QT 5.4.0.  Supports
 both XCB (OpenMAX Normal) and EGLFS (OpenMax EGLFS).
See Mythfrontend Setup Tutorial (with MCE Remote Control).
  • MicroSD Image by Piotr Oniszczuk
 Built upon ArchLinux for MythTV 0.28 using QT 5.5.1.
See Beta of MiniMyth2 RPI2 edition.

These builds work with High Definition (HD) 720p and 1080i content on a Raspberry Pi 2 Model B or better. There have been reports that earlier Raspberry Pi models might work with Standard Definition (SD) content and a lower gpu_mem setting.