Saturday, June 12, 2010

MythTV on an EeeBox

As many other geeks, I've spent considerable time in my life setting up MythTV and trying really hard to set it up for the perfect media center experience. I'm still struggling with some points, but I've got it working pretty decently, so I thought I'd post the result of my process, along with the still quirky points. Then hopefully somebody can use it for setting up a decent media center, and if I'm really, really lucky, some of you über geeks may have a few tips to share in the comments, so I can iron out the last weird issues.

Please note: I live in Denmark, so certain points in this post may not be relevant to you (especially the XMLTV guide). For that, you'll have to consult other blogs or - shiver! - some actual documentation.

What I bought
To get up and running, I bought the following hardware:
  • EB1012 (an Asus EeeBox with the ION graphics chipset, no optical drives)
  • Anysee EC30 Combo Plus DVB-C/T (a USB tuner supporting both DVB-C and DVB-T, and it comes with a remote control)
Apart from that, I bought an antenna splitter and the shortest, cheapest HDMI cable I could find.

Characteristics of the system
There are thousands of possible setups for running MythTV, and many people have "enterprisey" setups with a monster back-end and several front-ends. So why did I choose this simple setup?
  • Decent power consumption. With everything plugged in and running, expect an average power consumption of about 22W (excluding your TV and other stuff, of course).
  • Discrete. The EeeBox is very quiet, and it hides nicely behind my TV. The Anysee tuner "peeks out" from below, exposing the IR receiver.
  • Enough CPU and GPU power to easily play back all the contents I need to play, including HD content.
  • HDMI, separate digital optical audio (note: the EeeBox comes with a converter to plug into the jack plug at the back of the computer, so you don't need to buy one), enough USB ports, card reader, 802.11n wireless (and gigabit ethernet if you want), eSATA, ...
  • MythTV has a lot of nice features, and Ubuntu lets you fiddle with everything.
The EeeBox "only" has a 250GB harddisk, which may be too small for you. For me, it works, since I like to delete old, watched recordings anyway (and delete the ones I accept that I won't see anyway).

MythTV isn't for the faint-hearted, which this guide should make clear. I expect you to have basic Linux skills, otherwise this guide is probably useless, and in that case you should go for something simpler like EyeTV on a Mac or Windows Media Center on a Windows box.

Installation
Get Mythbuntu 10.04 from mythbuntu.org. Put it on a USB key, and make this USB key bootable.

Well, that's just not as easy as I thought it would be. There are lots of blogs out there telling you how to do it, but the only way I got it working, was with the help of a little Windows program called "Linux Live USB Creator" (http://www.linuxliveusb.com/). It does not recognize Mythbuntu directly, but it supposes it's an Ubuntu variant, which is correct.

Anyway, when you have your bootable USB key ready, put it in one of the USB ports on the EeeBox, and power on the EeeBox while holding down the F8 key on the keyboard.

How you choose to partition your hard disk is entirely up to you. I chose 20GB for the root partition, 5GB for swap, and the rest mounted as "/data". Other values will probably fit your needs better.

When prompted, choose having a combined front-end and back-end.

Update!
When your new MythTV box has booted for the first time, open "Mythbuntu Control Centre", go to the "Repositories" page, and select updates from "0.23 fixes". After that, run Update Manager, install all updates, and reboot.

Without this step, several components of MythTV didn't work properly for me.

Storage paths
Before you start using MythTV for real, remember to adjust the paths in MythBackend that define where recordings, live-tv, etc. go. It's under "Storage Directories". If, like me, you've mounted most of the EeeBox harddisk under "/data", you probably want values such as "/data/mythtv/recordings", "/data/mythtv/livetv", etc.

You should also create these directories in the file system, and remember to give proper rights to the mythtv user. I've just set all these directories to the mythtv user, the mythtv group, and given all rights possible. Perhaps that's a bit too much, but I don't want to spend time fiddling with this.

Drivers
Open "Mythbuntu Control Centre" again, go to the "Graphics Drivers" page, click "Launch Restricted Drivers Manager", and select both "Firmware for DVB cards" and "NVIDIA accelerated graphics driver". You'd think you didn't need the firmware for DVB cards, but without it, you cannot make the Anysee remote control work later.

Tuner in DVB-C mode
(I'm not sure if this first step is necessary - I'll check it out next time I re-install from scratch). Run this from a terminal:

modprobe dvb_usb_anysee delsys=0

Unfortunately, there is both a DVB-C driver and a DVB-T driver recognizing the tuner, so you'll still have trouble using the tuner after this. To fix this, you have to blacklist one of the drivers. In this case, we want to blacklist the DVB-T tuner. Add the following lines to /etc/modprobe.d/blacklist.conf:

# Force Anysee tuner into DVB-C mode
blacklist zl10353

If you want to run in DVB-T mode instead, you have to blacklist "tda10023" instead.

Setting up the tuner in MythTV
The card type must be set to "DVB DTV capture card (v3.x)", and the DVB Device Number should be set to "/dev/dvb/adapter0/frontend0". The next line should then tell you that "Frontend ID" is "Philips TDA10023 DVB-C Subtube DVB-C".

I've set my "Signal Timeout" to 5000ms and "Tuning Timeout" to 20000ms.

Channel search and setup
It's somewhat of a circus setting up channels, since subsequent, identical searches can yield different results. My only advice is to try a few times and then hope you can stitch together your channel setup. Try setting "Signal Timeout" and "Tuning Timeout" high (as I've done - see above).

I use a Danish provider called Stofa, and I can find all of their channels on frequency 346000000, modulation QAM64, symbol rate 6900000. This is probably different for your setup.

Sometimes MythTV tells me it has found a number of "off-air channels". I've no idea what that means, but typically they are channels already found as regular channels anyway.

XMLTV
In Denmark, the main national TV provider, DR, has a service that lets you grab the program information of the most used channels. You can use a grabber like "http://niels.dybdahl.dk/xmltvdk/index.php/DR_2009_grabber".

The XMLTV Perl package is installed by default in Mythbuntu, but you need to install "libparse-recdescent-perl". Then you can put the grabber script in your home directory and create the following script:


#!/bin/bash
LOGFILE=/home/me/mythfilldatabase.log
source /home/me/.profile
mv /var/log/mythtv/tvgrabbed.xmltv.1 /var/log/mythtv/tvgrabbed.xmltv.2
mv /var/log/mythtv/tvgrabbed.xmltv /var/log/mythtv/tvgrabbed.xmltv.1
cd /home/me/
./tv_grab_dk_dr_2009.mgr --days 10 --output /var/log/mythtv/tvgrabbed.xmltv > ${LOGFILE} 2>&1
/usr/bin/mythfilldatabase --file 1 /var/log/mythtv/tvgrabbed.xmltv >> ${LOGFILE} 2>&1

Then set up a Cron job: Run "crontab -e", define a line like:

00 06 * * * /home/me/mythfilldatabase.sh

Additionally, you ned to start "mythtv-setup" and define a new "Video Source" with the name "dr-xmltv" and "No grabber" as "Listings grabber". Under "Input Connections", this video source must be connected to the tuner.

Finally, run your new script. Then in MythWeb you can insert the right XMLTV IDs on the corresponding channels. Run the script again, and you get a proper channel listing in MythWeb.

Sound via HDMI or TOSLINK
If you want sound through the HDMI cable, create the file /etc/asound.conf with the following contents:


pcm.!default {
  type hw
  card 0
  device 3
}


If instead you want sound through the optical digital out, specify device 1.

Start "alsamixer" from a terminal and unmute "S/PDIF 1" by clicking M on it.

Picture quality
Turn on VDPAU in the "Setup -> TV Settings -> Playback", otherwise the EeeBox doesn't stand a chance when playing HD content.

Enable "OpenGL Vertical Sync" under "Setup -> TV Settings -> Playback". Otherwise you get "tearing" in the picture (i.e., the content is updated in the middle of the picture, so you have one part of the picture showing the previous frame, and the rest is playing the next frame).

Still, playback isn't always perfect, since the refresh rate on your TV doesn't necessarily match the refresh rate of the played material. To fix this, you need to do two things: First, go to "Setup -> Appearance", and on the "Video Mode Settings" page, check "Separate video modes for GUI and TV playback". Just choose "Any" as the rate for the GUI, and don't change the values in the "Overrides for specific video sizes" section.

Secondly, open nvidia-settings and uncheck the "Force Full GPU Scaling" on one of the pages. Voila! Playback is now perfect! (At least on my setup :-) )

The remote control
First and foremost you need to open "Mythbuntu Control Centre", go to the "Infrared" page, and check "Enable a Remote Control". Choose "Linux input layer (/dev/input/eventX)". If you cannot find this, it's because you didn't install the proprietary drivers - see above!

Run "cat /proc/bus/input/devices" from a terminal. Near the bottom of the output you'll see something like this:


I: Bus=0003 Vendor=1c73 Product=861f Version=0100
N: Name="IR-receiver inside an USB DVB receiver"
P: Phys=usb-0000:00:04.1-6/ir0
S: Sysfs=/devices/pci0000:00/0000:00:04.1/usb1/1-6/input/input6
U: Uniq=
H: Handlers=kbd event6
B: EV=3
B: KEY=148fc010 2353041 0 0 0 800 108000 4080 304801 9e0000 0 0 ffc

From the "H:" line, you can see that the remote control exists on "/dev/input/event6" - it is probably different on your system, since it depends on which USB port your tuner is in, and which other peripherals you have attached to your EeeBox.

Edit "/etc/lirc/hardware.conf", change the line

REMOTE_DEVICE="/dev/lirc0"

to

REMOTE_DEVICE="/dev/input/event6"

Then you can restart lirc with "sudo service lirc restart".

There is one real downside to doing this: Each time you reboot your EeeBox, you must have the same peripherals attached, otherwise your remote control will appear as another path. I haven't fixed this, but it should be fixable by doing this: Create "/etc/udev/rules.d/60-anysee.rules" (owner root, group root, "-rw-r--r--", just like the other files in that directory) with contents:

ATTRS{name}=="IR-receiver inside an USB DVB receiver", SYMLINK+="input/dvb-ir"

Now the remote control (also) appears as "/dev/input/dvb-ir", so you can set REMOTE_DEVICE in the lirc hardware.conf file to that. However, lirc refuses to use it, and even worse, as long as the udev rule exists, it even refuses to use "/dev/input/event6". So, I need to attach my keyboard and mouse each time I reboot my EeeBox...

Key bindings for the remote control
The remote control's "|<<" and ">>|" buttons are not "mapped" to anything in MythFrontend. I've chosen to let them work as "rewind" and "fast forward", respectively. You do this by opening "~/.lirc/mythtv" and insert the following lines:


begin
  remote = devinput
  prog = mythtv
  button = KEY_NEXT
  config = Right
  repeat = 0
  delay = 0
end

begin
  remote = devinput
  prog = mythtv
  button = KEY_PREVIOUS
  config = Left
  repeat = 0
  delay = 0
end

Playback in MythWeb
A really nice "gimmick" in MythWeb is the Flowplayer media player, which gives a YouTube-like interface to your recordings. In MythWeb, click the "MythTV:" link (upper left corner), select "Settings -> MythWeb -> Video Playback", and select "Enable Video Playback".

Securing MythWeb
There are several guides "out there" that tell you how to fiddle with stuff in /etc/apache2, /etc/httpd, etc. None of those guides seem to work... but that doesn't matter, since you just have to open "Mythbuntu Control Centre" (start it as root), go to the "Plugins" page, and enable password protection.

Start/end of recordings
It's nice to start recording e.g. 2 minutes before the official starting time, and end recording e.g. 5 minutes after the official ending time. In MythWeb, you can alter the setting "DefaultStartOffset" and "DefaultEndOffset". Both are specified in minutes, so I've set them to 2 and 5, respectively. This implies that the default values of the fields "Start Early" and "End Late" in the recording dialog page will be set to 2 and 5 minutes.

Issues still not sorted out
My daily Cron job doesn't always run. However, it successfully runs often enough that I don't have problems with my channel listing.

When I reboot the EeeBox, I need to have my keyboard and mouse attached, otherwise the remote control won't work. It seems like udev and lirc don't like each other.

Update (25th of August 2010): My setup has been working quite badly the last month or so, since the back-end sometimes takes 30 to 40 minutes to change the channel. I've borrowed another Anysee tuner from a friend, but that didn't fix the problem, so either my cable provider is sending a poorer signal (which would be weird, since my TV has no problem), or a bug has been introduced either in MythTV or the kernel driver. At around the same time, the 0.23-fixes branch was ended, and no Mythbuntu updates switched to the 0.23.1-fixes branch. I've switched to the 0.23.1-fixes branch by executing this from the command-line:

sudo add-apt-repository ppa:mythbuntu/0.23.1
sudo apt-get update

I haven't updated MythTV yet (it takes proper planning in a busy household...), so I've yet to see if this helps.

References
Helping me get this far required a number of resources on the net. In all fairness I'll list them here:

2 comments:

  1. Does you Anysee Remote still works fine with Mythbuntu 11.04?

    I'm only able to use the number keys for switching channel and the volume keys.

    ReplyDelete
  2. Oh, sorry about the late reply... don't know if I can configure Blogger to send me an e-mail when comments are added.

    I think it worked fine after I upgraded to Mythbuntu 11.04, but I have ditched the Anysee tuner + remote in favour of a HDHomeRun box and a decent remote. I've described the HDHomeRun change here: http://olefriis.blogspot.com/2010/12/hd-homerun-mythtv-dvb-c.html

    I haven't documented how to make the remote work, simply because it was mostly "plug'n'play". I bought this remote, but other MCE remotes probably work just as well: http://www.opencompany.dk/products.php?showvariant_id=9342

    All you have to do to get the remote working is to choose "Windows Media Center Tranceivers/Remotes (all)" as "Remote Control" in Mythbuntu Control Center and check "Generate dynamic button mappings". At least, this should work in LIRC 0.8.7 and newer.

    In my opinion it's worth the extra money, since the Anysee remote is quite crappy compared to e.g. the Foxconn remote.

    ReplyDelete