Sunday, January 05, 2014

Mythtv backend running on a Raspberry Pi


Disclaimer! the Mythtv devs have always frowned on the idea of low powered boxes like the Pi running the backend due to the load when rescheduling. In practice I have found it very useable on a dual tuner box only recording freeview which is about 30 or 40 channels. Any advice and guidance here is absolutely unofficial and neither me or the mythtv devs can be responsible for anything not working as advertised

Since my AMD64 based media centre which was used as a combined backend/frontend for Mythtv died suddenly I have rebuilt the system around a Raspberry Pi backend with recordings being viewed on either XBMC on Android tablets or a Raspberry Pi running RASPBMC. The power consumption has dropped from about 100w to about 5w so a large saving.

The Backend is on a RPi with a Kworld USB TV tuner stick, and a 1.5TB hard drive in an external case. The backend currently runs 0.26.

Movies, TV shows, and music are all stored in directories which are available across the network as either CIFS (windows) or NFS shares. These are accessible from Myth frontends and XBMC.

This blog is a run through of what I did to set up the backend on the Raspberry Pi

What you gonna need

  • A Raspberry PI 
  • A class 10 SD cards. My backend uses a 16GB and the frontend an 8GB
  • A Powered USB Hub. the new PiHub from Pimoroni will be about the best if you are after a new one.
  • 1 or more External hard disks for the backend storage.
  • A Usb TV tuner. The Kworld one from Maplin's in the UK works great for me and others. If you are going to use an alternative then research carefully. I had a Terratec from ebay and could not get it to work. Check the RPi compatibility list carefully
I also use a Microsoft MCE remote control, which worked out of the box with RaspBMC. Some TVs work with the CEC pass through which is great, although mine doesn't as it is a few years old now..

Installing the Backend

To install the Mythtv backend, first download and install raspbian onto the RPi.
Make sure you use a validated Class 10 SD card. I'm running  a 16GB card which is fine.

Before you install Mythtv, ensure that IPv6 is enabled on the Pi. Otherwise when the backend is installed and started it will immediately fail.

To start IPv6 enter the following command sudo modprobe ipv6
Add ipv6 as a new line to /etc/modules to ensure it is started automatically at boot.

Luckily Jalto on the Raspberry Pi forums has already built a set of packages for Mythtv and Raspbian.

In a nutshell, download and extract the package to the root of the filesystem

cd /
sudo wget http://dl.dropbox.com/u/4581144/mythtv-rpi_packages.tgz
sudo tar -zxvf mythtv-rpi_packages.tgz


Add the following line to /etc/apt/sources.list, using your favourite text editor. Note that you will need to sudo this (e.g. sudo nano /etc/apt/sources.list)

deb file:/mirrors local local

Update Apt

sudo apt-get update

Install the Mythtv backend.  We don't need the frontend or most of the plugins, so leaving them out saves some space, and saves on needing to install an X server.

sudo apt-get install mythtv-backend

All the other packages such as MySQL should be installed automatically as well.
Note that when MySQL does install you will need to provide a password for the root SQL account.  Make a note of it and keep it safe.

I found that everything installed happily except for Mythweb for some odd reason. No one else on the forums has mentioned it, so it may be an oddity for me.

Once installed you will need to set Mythtv up, which is done using the mythtv-setup app.  There are many good guides on how to do that, not least on the Mythtv wiki itself, so I'm not going to give much more than a quick overview.

Rather than do that locally, I ran it on my Ubuntu powered laptop via remote X using the following command, just as the user (use the correct Ip for the backend)

ssh -X pi@000.000.000.000 /usr/bin/mythtv-setup

It ain't very quick, but it does save on installing and starting X on the RPi itself, which is an advantage if the backend is just hidden in a corner.

There are 7 sections.

1: General
Here you will need to enter details such as the Ip address, Tv format (Pal in the UK). Most other settings can be left as default. I would disable transcoding and advert detection jobs as these can be cpu-heavy.

2: Capture cards
Here you will identify the capture cards used by Mythtv. Add a new capture card and set the type to "DVB Capture card". Myth should then detect the available cards of that type and allow you to choose.

3: Recording profiles
Leave these settings at the default.

4: Video sources
you will need to create a new video source. You can either use EIT, which is basically the over the air programme guide delivered as part of the freeview signal, or XMLTV. I use XMLTV configured to pull data from the Radio Times site in the UK. This gives me 14 days of programme data and is updated daily. Just select the grabber and then finish.

5: Input connections
Mythtv can have tuners for differing sources (freeview, freesat etc) and can also have different data sources. This section is where you marry up the tuners to the video sources. you can also set the starting channel number and scan for channels. on the second screen you can set tuner priority should you wish to.

6: Channel Editor
This (surprisingly) is where you can set the channels including the numbers and Ids etc.
For a first time setup, perform a full scan. there is information and some sample scripts on the Mythtv wiki to make this easier. I find it easier to do a full scan and then manually enter the XMLTV ids from the channel.ids file found in /usr/shared/xmltv/tv_grab_uk_rt/
You will also need to create a text file with the file name format freeview.xmltv in /home/user/.mythtv and enter each xmltv id on separate lines. It is this file that mythfilldatabase uses to determine which channels to grab data for. This process is a pain in the arse frankly, but only needs to be completed once. you will also want to run the icon grab, and possibly change the channel numbers to suit your own desires.

7: Storage directories
In this section you will need to enter the directories where the Mythtv will store and find the various files. Most are obvious apart from possibly default, which is where the directories for storing recordings are located. You can enter multiple directories per group.

8: System Events
This section can be ignored for now. It's for triggering custom actions based on events such as recording start or end

Once complete exit the Setup program, restart the backend and you should then be able to connect either via the Mythfrontend client,, XBMC, or the web client for managing Myth.





11 comments:

Unknown said...

Hi Gary,
What world dongle are you using'
I have a 499, which uses a it9137 chip set.
I cannot find firmware

Unknown said...

Try this:

cd /lib/firmware/

wget -O dvb-usb-af9035-02.fw http://palosaari.fi/linux/v4l-dvb/firmware/af9035/dvb-usb-af9035-02.fw_085e676dc50addf538b6cb18f4ca233a_12.13.15.0_6.20.15.0

wget https://github.com/OpenELEC/dvb-firmware/raw/master/firmware/dvb-usb-it9135-01.fw

Unknown said...

This is great!

Have you noticed any problems running the front end?

Unknown said...

Is it possible to use a raspberry pi to act both as a frontend and a backend ? I'm using version B+ with openelec

Yooper said...

Hi and Thanks for the guide...my server is up and running on my Rpi B+ and my HD HomeRun Dual is kicking ass...Now what seems like it should be a piece of cake...the front end...is proving to be vexing. Tried the mythweb...it's broke. Tried XBMC and the can't find a mythbackend v.26 plugin. Tried mythtvfront end on a mint 13 box...no luck. What is everyone using as a front end?

Unknown said...

Any news about new MythTV packages for the RaspberryPi (now that Pi 2 is released)?

Unknown said...

Tried this and got the backend to start up , but it could not log into the database using the same password that I supplied during installation. I can log in to the database using Emma, not sure what is wrong.

Anonymous said...

installing the backend fails - see below...

pi@raspberrypi:/ $ sudo apt-get install mythtv-backend
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
mythtv-backend : Depends: libmyth-0.26-0 (>= 0.26.0) but it is not going to be installed
Depends: libmythavcodec54 (>= 0.26.0) but it is not going to be installed
Depends: libmythavformat54 (>= 0.26.0) but it is not going to be installed
Depends: mythlogserver but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
pi@raspberrypi:/ $

Blogger Blogger said...

Same issue as Rick Brice... backend has dependencies that fail to install.

sudo apt-get install mythtv-backend
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
mythtv-backend : Depends: libmyth-0.26-0 (>= 0.26.0) but it is not going to be installed
Depends: libmythavcodec54 (>= 0.26.0) but it is not going to be installed
Depends: libmythavformat54 (>= 0.26.0) but it is not going to be installed
Depends: mythlogserver but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

I've Been trying Myth backend on RPi for more than it's worth or make sense... I guess it's not meant to be. I'd rather use few watts rather than hundreds to run a backend... then again it's better to use time more efficiently rather than hit one's head on the wall because it ain't gonna happen due to lack of platform support. So hundreds of watts and different back end it is!

leopheard said...

Thanks for the blog - one problem I was having is when trying to set the backend up on the RPi3 (I'm going to use a RPi3 with Kodi as the frontend), it can't connect to the Mysql database as the server isn't running. I followed all the instructions on the MythTV website but nowhere did it say how to start the server.

Any ideas?

Rich Shumaker said...

This article is over 3 years old. I wanted to find out how you are making out.
Also is there a way to split the tasks of MythTV between RasPi's - Basically the way a server has multiple systems to do things.
Have you used a RasPi B not 2 or PiZero for a Front end either via a MythTV frontend or via the Kodi MythTV frontend?
I have always liked the MythTV guide, it is the best I have ever used. At $25 a year for the listings it is a great deal if you ask me. I want to record using the MythTV backend to a NAS or similar to allow me to watch what I record everywhere. Even if I only use the WebGUI to schedule my MythTV.
Thanks in advance and I hope this comment finds you well.

Rich Shumaker
richshumaker.com