Building a HTPC with Mythbuntu 9.10

So I decided it’s time to build a HTPC so I can record TV and also use time shifting when watching live TV.

I’ve tried several products, be it software packages or whole linux distributions, including Windows Media Center, Apple Front Row, vdr, c’t-vdr, yavdr, freevo and mythTV. That last one I liked most by what it offered, so I gave it a try. I stumbled upon many things on my way though. I’ll write down the ones I remember here, perhaps it’ll help someone some day.

0. Keep mythTV up to date!

This is an edit, I found out about this after I wrote down the rest of this article, but it’s a very good idea to do this right after you install mythbuntu. Doing the following will make sure that you have the latest bugfixes. You need to enable the so-called auto builds.

  1. Download this .deb file to your machine and install it with
    sudo dpkg -i mythbuntu-repos.deb
  2. When asked, choose your version number (most likely the smaller one)
  3. Update your system:
    sudo apt-get update
    sudo apt-get upgrade

1. Shutdown issues

I don’t really know the cause for this. I’m using an ASUS M2NPV-VM motherboard with NVIDIA nForce 430 integrated graphics (including a composite and s-video TV-out). The chipset does get quite hot, about 76°C I’ve seen.

When shutting down mythbuntu, sometimes it works, sometimes after leaving X the screen stays blank and the machine hangs. No switching to another TTY, no ping… I have to press the power button for >4 secs. There is nothing in the logs because the logger is already shut down at that point. So this might be a hardware issue, but I suspected the proprietary nvidia driver. Since it always seemed to happen when switching from XFCE to the boot splash screen, I edited the grub.cfg (yes, mythbuntu now uses grub2…) and changed “splash” to “nosplash”. Not quite as fancy, but as long as it makes shutting down work, well. This seems to fix the issue.

2. MythWelcome always starts MythFrontend issue

That one was quite a bitch.

When you have frontend and backend on the same machine, you might want two different startup/shutdown behaviours. When you turn on your HTPC, it should start the frontend and stay on until you exit it. When the machine starts automatically to record a scheduled recording, it should not start the frontend so it can shutdown itself after having finished the recording. This was not possible on my machine.

Edit: Nowadays, MythFrontend has a timed “standby mode” that will allow the backend to shut down the machine after a configurable time of inactivity.

First I modified the ~/.config/autostart/mythtv.desktop to start mythwelcome instead of the frontend, because uncommenting the “#MYTHWELCOME=TRUE”  line in /etc/mythtv/session-settings, as suggested in several howtos, didn’t make it start on boot. Now mythwelcome has that nice option in its settings: “automatically start mythfrontend”.

Normally when mythwelcome starts up it checks to see whether the system was started to record something or because of a wakeup/shutdown period. If not it will automatically start the frontend. You can disable this feature by unchecking this option.

As nice as it sounds, it didn’t work. It just always started the frontend. So I edited the autostart entry again so it wouldn’t start mythwelcome but a script that I wrote:

# start mythwelcome into the background
/usr/bin/mythwelcome &
while [ 1 ]; do
    STARTUP=`cat $FILE`
    if [ "$STARTUP" = "auto" ]; then
        echo "" > $FILE
        exit 0
    elif [ "$STARTUP" = "user" ]; then
        echo "" > $FILE
        /usr/bin/mythfrontend &
        exit 0
    elif [ "$STARTUP" = "" ]; then
        sleep 1

Now I created this file and made it writable for everyone:

sudo touch /home/mythtv/startup.txt
sudo chmod 777 /home/mythtv/startup.txt

In the backend setup on the startup/shutdown settings page, I wrote

echo $status > /home/mythtv/startup.txt

into the “startup command” field. This makes the backend write “user” or “auto” into that file whenever the machine is booted, depending on whether you switched on the machine or it booted itself to record.
My script checks this file for these expressions. If it’s empty because the backend is not yet started up, the script waits a second and then tries again. When it found “auto” or “user”, it clears the file to prevent doing the wrong thing on next boot when the backend doesn’t write to the file fast enough.

This was the only way how I could get it to work as supposed. Before, I tried running mythshutdown --status and grabbing its exit code, but it always gave me “1” (manual startup), so that was of no use (maybe that’s even the same way mythwelcome checks for automatic startup).

EDIT: Every now and then, this didn’t work as well. After a nightly recording, the machine kept running, and when I shut it down and booted it the next time, it shut itself down immediately after because it didn’t start the frontend.

So I had to increase the idle time to 60 seconds so I can start the frontend myself. But when I power on the machine and go get myself a coffee, it has shut down when I come back. I hope I can get this running properly some day.

3. Hauppauge IR receiver and remote

There are tons of tutorials on the web explainig how to do this. The only thing was that I had to use /dev/input/eventX (sometimes it was event5, sometimes event4…) – so I had to write an udev rule to create a symlink to the actual event being used on boot (again, several howtos for that on the web).

4. Automatic boot for scheduled recordings

I’ve read about several ways to accomplish this, from ACPI wakeup and wake on LAN to using “nvram-wakeup”. And this is what I started using. It didn’t recognise the board, but it comes with this “guess-helper” tool which worked like a charm. My command to set the wakeup time is

sudo /usr/sbin/nvram-wakeup -A -s $time -C /etc/nvram-wakeup.conf -w 0

What a string huh? The -A means use directISA, I have to use that because I have no /dev/nvram device. Since I can specify a number of seconds to boot before the recording starts in mythbackend, I don’t need nvram-wakeup adding another five minutes, so I used “-w 0”. And with my board, I couldn’t just set the wakeup time and shutdown, I need a reboot so the changes take effect. There are several howtos that tell you how to modify your grub or lilo configuration so it will reboot and poweroff immediately after, but as you might remember, my brand new version of mythbuntu uses grub2, so all that stuff wasn’t applicable anymore. I found this site though which had exactly the information I needed:

  1. put this into /etc/grub.d/40_custom:
    exec tail -n +3 $0
    # This file provides an easy way to add custom menu entries.  Simply type the
    # menu entries you want to add after this comment.  Be careful not to change
    # the 'exec tail' line above.
    menuentry "PowerOff" {
        save_env saved_entry
  2. in /etc/default/grub change the GRUB_DEFAULT line to this:
  3. change your shutdown command to
    sudo grub-set-default PowerOff && sudo /sbin/reboot

Then run update-grub to apply the changes.
Of course you have to make sure that grub-set-default is in the sudoers file in the NOPASSWD line for the mythtv group. What happens is that mythtv reboots the machine, and when grub loads, it powers it off right away.

5. German weather data

I found two scripts providing data for German cities, this one uses and this one Both are working fine

6. Cinema data

Found a parser for google movies here.

7. Integrate web radio into MythTV

Have found something here and here, will try that. I used the one that uses VLC for web radio playback. Works like a charm, despite the fact that the solutions I’ve looked at so far use an external player, be it VLC or Xine, that’s launched into the foreground, so you can see an ugly GUI and the task bar of mythbuntu. Although it was very easy to make my remote work with VLC, it’s not the optimal solution. It could be improved a little with a nice skin, or perhaps there’s a command line argument that makes VLC launch in fullscreen. This, combined with a nice visualisation or something, could be nice. Gotta have a look at that.

Launching it into the background is not an option because then you will most likely not be able to control it with the remote.

The only downside is that the mainmenu.xml that you have to edit to have an additional entry for the web radio gets updated every now and then, so your changes are gone and you have to restore that file from a backup or make the changes needed again.

8. Enable recording multiple channels at the same time (DVB multiplex)

As per

Who knows, perhaps this will even enable me to watch live TV while recording, as long as the channels are on the same multiplex.

Edit: Yeah, it does! In backend setup > tuner cards > my card > record options, I changed the number of maximal parallel recordings to four (as there are four channels per multiplex in German DVB-T) and voilà, the backend status in the web interface shows four encoders. Awesome! While recording a channel and watching it simultaneously, I can switch to the three other channels of that multiplex. And I can now – of course – record up to four shows simultaneously, as long as they’re on channels which share the same multiplex. And a few scheduled weekly recordings no longer collide with each other.

This feature also allows me to make “start recording 3 minutes early and end it 3 minutes late” as a default setting. I already had tried that, but it failed when, for instance, I wanted to record two back-to-back Lost episodes (say 20.15 to 21.10 and 21.10 to 22.05). Now that’s no longer a problem.

I love this machine.

9. Test how MythTV behaves when viewing live TV and a recording is scheduled to take place

Done: it just shows an OSD overlay which tells you that MythTV has a scheduled recording to start in X seconds (that’s a 30-second countdown) and you can choose to…

  • quit live TV and record
  • continue watching live TV and don’t record
  • switch to the channel of the recording to record and watch it at the same time

And who knows, perhaps there will be another option, now that I configured multiplex (see 8.), allowing me to switch to one of the four possible channels and record.

10. Enable mythweb on special port with authentication

Since I wanted to access mythweb from the internet, I decided to run it on a special port and enable HTTP authentication. This is how I got it working:

  1. Enable the auth_digest module:
    sudo a2enmod auth_digest
  2. Edit the default-mythbuntu:
    sudo vim /etc/apache2/sites-enabled/default-mythbuntu

    and add “listen 12345” before the first line (where 12345 is the port you want to access mythweb from). Also, in the second line, change the 80 in <VirtualHost *:80> to your port or to *

  3. Edit the mythweb.conf:
    sudo vim /etc/apache2/sites-enabled/mythweb.conf

    and uncomment the auth block (“AuthType” to “Satisfy”)

  4. run
    sudo htdigest -c /var/www/htdigest MythTV some-user-name
  5. restart apache:
    sudo /etc/init.d/apache2 restart

Now you should be all set. I added a port forwarding rule in my NAT router for that port, after that I could access my mythweb at http://my.home.ip.address:12345/mythweb with the username and password I had set with htdigest.

11. Automatically start a VNC server on boot

Sometimes you need a mouse and/or keyboard, so a VNC server would come in handy. I’ve chosen x11vnc because I had some trouble getting the common vnc4server to run properly. This is how it works:

  1. Install it:
    sudo apt-get install x11vnc
  2. Set a password:
    x11vnc -storepasswd
  3. Edit ~/.x11vncrc:
    vim ~/.x11vncrc

    and make it look like this:

    # without loop, the server would stop running after a VNC session
    # use the password you have set
    # set it to the display of the X session (you probably need to adjust this)
    -display :0
  4. To add x11vnc to the “autostart”, go to Applications -> Settings -> Session and startup, change to the “automatically started applications” register, click “Add” and put “x11vnc” into all three fields.

Now reboot or log out and back in. Then try to open a VNC connection to your machine on default port 5900 to test.
Most google hits for making a VNC server run under linux led me to grey screens or starting a new X session, but my goal was to VNC into the currently active session obviously.

After all, it was a bit of a hassle, but more than worth it. A tiny HTPC made of old computer parts that records all my favourite shows, allows me to pause live TV, automatically skips commercial breaks, plays my movies and music and draws just 70 watts (at least when it’s idle). And once configured and set up, it’s really easy to operate, easier than hacking show view numbers or start and end times into the good old VCR.

It has a webinterface in which you can create recording schedules, see what’s on TV, change mythtv’s settings, manage your recordings and even watch them, either via download or via .asx stream. Yes, you can stream your recordings wirelessly to your laptop and watch them in bed. EVEN WHILE THEY’RE STILL BEING RECORDED. Steve Jobs would say “awesome”.

It even has a webinterface for the iPhone, although there are not too many features in it yet. You can see which shows have been recorded and what’ll be recorded next. You can also delete recordings there. And there’s a “remote” button, didn’t do anything yet, but it seems they’re gonna make the iPhone a wireless remote. Nice.

And the greatest thing about it is: it’s completely free. The mythTV software is free, the codecs it uses are free, the drivers are free, the whole OS it runs on is free. Every piece of software used is completely free.

Leave a Reply

Your email address will not be published. Required fields are marked *