Saturday 14 July 2012

XBMC, TVHeadend and watching live TV

 As some of you may have followed in earlier posts I've been replacing our old Sky satellite setup with my own setup here at home. Well over the past month or so its improved considerably so I thought I'd write up where I'm up to with the whole setup and how the family are getting along with it.

Firstly the problem, Sky is expensive and to be honest the majority are repeats and most of the channels we frequently watch are FTA (Free-to-air/satellite) in the UK, so dropping Sky was logical. So I then had the Sky dish and the problem of how to feed it into the house setup. Firstly the front-end. I've used XBMC since the early days on the original XBOX thanks to Bunnie Huang and his amazing books, etc. (Google it!). So I'm happy with XBMC, so setting that up on a small footprint PC with quiet fans and HDMI out. I bought a cheap Nvidia card with HDMI out (Cost around £35), as these cards can do hardware decoding, this is important as it takes the load off the PC's CPU and very important when your machine isn't the most powefull on the planet. So with that in the PC (It's a slim-line Dell so fitting the Nvidia was a pain, the case doesn't quite close properly, but its hidden out of sight so not a problem). The HDD in the XBMC machine isn't too important, big enough to hold the XBMC install is enough as you won't really be storing anything on it. Save your disks for the 2nd bit of hardware! Networking is also important, make sure its cabled up right and if possible use Gigabit network cards+switches as it'll speed the whole system up (Although for HD tv you can get away with 100Mbps as HD tv streams are 35Mbps (at worst) dropping down to 6Mbps.

Install XBMC: Simply download their Live CD XBMCUbuntu, burn that and run it. There is the option to install, choose that and wait whilst it flattens your HDD, partitions, installs, etc. Now a word of caution. Make sure your graphics card, hardware, etc, are all plugged in at install, as the installer does a really good job of installing the right components if it finds the right hardare. It'll save you a world of pain later! So now you should be booting XBMC from HDD and getting things looking reasonable. You can tweak this as you need. Insert a MS media centre remote for remote control/IR functions (Pretty much any will do, I found the older silver ones work better than the newer branded editions (HP badged, etc, I found didnt work reliably). There should be little else you need to do.

To get TV functions into XBMC you need the latest packages, Pulse-Eight provide these in an easy script, SSH to your XBMC machine, then run these commands:

       cd /tmp; wget; chmod +x; ./

Thats all one one line to make copy/paste easier! What this does is grab the install script from Pulse-Eight, set it to executable and run it. This adds a repository into Ubuntu with the relevant updates, upgrades and does it all for you. When its done, just reboot and you should have XBMC again but this time it will have additional TV functions hiding. This is all we do with XBMC for now.

(NOTE: XBMC has a few problems with standby, resuming usb devices at the moment, this appears to be an Ubuntu issue and not XBMC, so if you set your settings > power savings to standby when power pressed and after resuming you find it won't make the IR remote work you've got the bug. There are loads of forum posts about it. I've tried them all and with no success as yet unfortunately).

If by chance your IR works after resume then you'll want to be able to wake the XBMC machine from its sleep by the remote (So a simple power button press on the remote will wake it). If thats the case you want to look at adding the following to /etc/rc.local:


echo "USB0" > /proc/acpi/wakeup
echo "USB1" > /proc/acpi/wakeup
echo "USB2" > /proc/acpi/wakeup
echo "USB3" > /proc/acpi/wakeup
echo "USB4" > /proc/acpi/wakeup
echo enabled > /sys/bus/usb/devices/7-2/power/wakeup
That last line you need to find the correct numeric value (Instead of 7-2). Do it just by typing lsusb, look for your IR device and the numbers you need are the BUS and DEVICE. So in mine above I had:
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 0644:0200 TEAC Corp. All-In-One Multi-Card Reader CA200/B/S
Bus 002 Device 003: ID 046d:08cc Logitech, Inc. Mic (PTZ)
Bus 007 Device 002: ID 045e:006d Microsoft Corp. eHome Remote Control Keyboard keys
So the last entry is my IR remote, take the 2 numbers 007 002, remove the 0's and you have the 7-2 needed for the wake command. This will allow your USB devices to wake the machine when its in sleep.
Now onto the Satellite part of things. TVHeadend. This is best ran on a separate machine. A few people run it on the same machine as XBMC but this appears problematic and you will also need to leave the machine on, or do some trickery to wake it at the right time to handle recordings, so we're skipping that and using a dedicated machine. The other advantage is you can stick this out of the way (In my case, my modified Garage) so its on all the time. This means you don't need to use quiet fans, etc. So purchase some Satellite/Terrestrial cards. I use 2 satellite cards (DVB-S DVB-S2 are Satellite), and one terrestrial (DVB-T). If you're buying satellite cards then I'd strongly recommend to get DVB-S2 (And not the S1 cards), because some channels in the UK now are only available on the more advanced S2 streams, so to future-proof I'd go DVB-S2. I'd also recommend against combination cards (2 receivers on one card, one sat one terrestrial, etc), as in some cases Linux won't be able to use the different elements separately and you'll end up restricting what to do.
So I installed one DVB-S card, one DVB-S2 card and one DVB-T card (All PCI as USB is also problematic in some cases). I did a normal/basic Ubuntu server installation (No graphical interface needed, but if you're a novice it won't harm). Get it all up to date and then get ready for the other installations.
Next I created a storage area for recordings. On my network I have a NAS (Network Attached Storage) so I used this, however for these instructions I'll show you how to make your TVHeadend server into a basic NAS for TV use. The reason I did this was that it allowed all machines on the network (Regardless of if they ran XBMC or TVHeadend integrated) to view and playback recorded material. On my network at home I used NFS as the majority of my network is Linux-based. So you need to install the nfs server to your TVHeadend machine:
apt-get install nfs-kernel-server
After install you need to create your storage area, so do something like:
mkdir /home/recordedtv
We'll use that to save all our TV to. So you need to export that from NFS:
echo "/home/recordedtv *(rw,sync,no_subtree_check,no_root_squash)" >> /etc/exports
This adds the folder to the export for NFS with a few parameters, WARNING: we are letting anyone that connects full read/write access without restrictions. Only do this if you trust your network, otherwise read up on safer NFS settings.
Now we need to install TVHeadend. At the moment there is some active development which is providing amazing changes to how EPG and the main TVH system works, this work is done by Adam Sutton who has made some great updates to TVH. I've been very lucky in being able to beta-test a lot of code and provide input to its development, so I'm very grateful to Adam who has humoured me all along! So at the moment this would be the branch I would recommend over the main tree or the debian packages. So it's a little more involved compiling but its worth it! So here are a few simple instructions to get you started:
apt-get update
apt-get install build-essential git 
cd /usr/src
mkdir tvheadend
cd tvheadend
git clone
git pull origin initialscan
You should now have a full copy of the latest dev code. Go into that folder (cd tvheadend) and you can then start compiling. I can't remember if there were additional dependencies for TVH so if configure fails you will need to add the dependencies. If you're unsure pop a comment/tweet over to me and I'll help out and update this doc.
cd tvheadend
./configure --prefix=/usr --release
That'll give you a working TVH binary to use. Only a couple more steps to go now! 
Create a user for TVHeadend to use:
adduser tvheadend
You can then use that to run TVH, etc. So change to that user and do a simple setup task. This is because at present the work is in development. So carry out:
mkdir ~/.hts
mkdir ~/.hts/tvheadend
cp -Rp /usr/src/tvheadend/tvheadend/data/epggrab ~/.hts/tvheadend
All this does is creates the TVHeadend config folders, and also copies the libraries needed for EPG grabbing to work.
I tend to run TVHeadend it in a screen process so you can see if any errors occur, so you can do this:
screen (Press enter on the information screen that appears)
cd /usr/src/tvheadend/tvheadend
./build.linux/tvheadend -s -d
That'll fire up TVHeadend. Hopefully it'll run and got exit with an error. If so you can now swap to the webui and start to configure it.
The rest of the config is fairly standard, in the new EPG grabber tab make sure under the OTA section you enable OpenTV: Sky and EIT grabbing. The channel name/number/icon is experimental so you may wish to leave this off for now. Continue on to the TV Adapaters section and setup the rest of your TVH setup as normal. This is documented elsewhere and I've documented under my old XBMC section so take a look there is you're totally new to TVH.
Good luck, and as always please do get in touch if you'd like a bit of extra help with your setup.


No comments:

Post a Comment

Note: only a member of this blog may post a comment.