Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.




47 posts

Geek
+1 received by user: 10


Topic # 151407 24-Aug-2014 16:05
5 people support this post
Send private message

A few people requested that I do a write up on exactly how I set up TVHeadend server on a Raspberry Pi, for Freeview access on multiple DVB-T tuners. So here it is.

I'm also including instructions on setting up a second Pi with Openelec as a client for this, but you can just as easily use XBMC installed on any computer.

NOTE: These instructions are for the terrestrial Freeview HD service, and assume you already KNOW that you have sufficient Freeview HD coverage at your house. All this tutorial is for is to distribute Freeview from a central location to places you don't have decent coverage, or (as in my case) don't have an aerial port where you want to put the TV, or if you don't have a TV, but want to use your PC instead.

For the record, this setup should work for Freeview satellite, if you replace the DVB-T tuner for a DVB-S tuner, but as I don't have a DVB-S tuner, I can't comment on that.

Related: If anyone can recommend a good, small, low-cost USB DVB-S tuner, please let me know. :-)

=======================
SERVER

=======================

What you need:
- Raspberry Pi (with SD card and power supply)
- DVB-T Tuner - I got three of these from TradeMe.
- Aerial Cable

Optional:
- USB HDD (for recording programmes)
- Multiple tuners (for watching channels on different multiplexes at the same time)
- Powered USB Hub (likely required if you want multiple tuners and a hard drive - this one works nicely) 

1. Install Raspbian 

The instructions on the site are better than any I would provide, so please refer to those. I would suggest you set Debian up with console access only. X Windows would simply add extra load to the Pi.

Once complete, SSH into your Pi (or login if you have a screen and keyboard) using the default "pi" user. The remaining steps all assume you're logged in as this user.

2. Setup the DVB-T Tuner(s)

Given the large number of possible DVB-T tuners out there, I can't provide instructions on how to get Linux drivers for all of them. However, a large number of the cheaper ones probably use the same chipset, which is the ITE9135 chipset. The drivers for that chipset (which includes the tuner linked above) can be downloaded from my Dropbox. If that link doesn't work, let me know.

You can download this file straight to the right location on your Pi with the following commands:

 

cd /lib/firmware

 

sudo wget https://dl.dropboxusercontent.com/u/6101726/Raspbian/dvb-usb-it9135-02.fw

 

Now plug in the USB DVB-T, and type:

 

dmesg

 


You're looking for a line that says something like:

 

usb 1-1.4.1: dvb_usb_v2: 'ITE 9135 Generic' successfully initialized and connected

 


If you see that, you're good to go. If not, feel free to reply below with the messages you do see, and I'm sure someone here will be able to help figure out why it's not working. :-)

Note, if you have multiple tuners of the same type, you only need to install the firmware once. They all use the same file.

At this point, make sure you've got everything plugged in. If you have an external USB drive, plug that in now, and the same with all the DVB-T devices you have.

You also want to connect the DVB-T tuners to an aerial. I have a UHF aerial on the roof, with an 8 way splitter in the cupboard under the stairs. Since that's where I've put the Pi, the tuners are all connected to this splitter with their own cables.

Depending on where you are, you may get away with an internal aerial. I tested my setup with the tiny aerial that came with the tuner, but I can see the Waiatarua tower from my office chair. It's more likely you'll need to hook it up to an aerial on your roof.

3. Install TVHeadend

The simplest way to do this is by installing from the TVHeadend Debian repository. To allow access to the repository, run the following commands:

 

curl http://apt.tvheadend.org/repo.gpg.key | sudo apt-key add -

 

sudo apt-add-repository http://apt.tvheadend.org/stable

 


This adds the repository to your server so you can install from it. Now you need to edit the /etc/apt/sources.list file, and add the following line (sorry, use of nano or vi is beyond the scope of this write up):

 

deb http://apt.tvheadend.org/stable wheezy main

 


Then finish the installation by running:

 

sudo apt-get update

 

sudo apt-get install tvheadend

 


And get a drink or three. That last one can take quite a while, especially if you've got a slower SD card. Once it's finished, it will automatically start the server for you, and also sets it up so it will start whenever the Pi restarts.

You will be asked to complete some information, such as providing an admin login username and password.

4 (optional). Set up the USB Hard Drive

If you want to add a USB hard drive for recording programmes, or for timeshift (live pause), then you will need to set it up first.

Plug the disk in, and run the following:

 

sudo fdisk -l

 


This will show you the connected disks. Assuming you've only got one USB disk installed, it should appear as /dev/sda, but make sure of that before you continue. Note if you have multiple disks, these instructions may not be the best to follow, as they really do assume you've only got one. You have been warned.

To prepare the disk for use, you will need to format it. THIS WILL DELETE EVERYTHING ON IT, so make sure it's a disk with nothing you care about on it.

 

sudo fdisk /dev/sda

 


Change as appropriate for your disk.

Delete all existing partitions by pressing d, and selecting each in turn. Then press c to create a new partition, and allow it to fill the disk. Save your changes by pressing w.

Now format the new partition:

 

sudo mkfs.ext4 /dev/sda1

 


Once formatted, mount the disk to make sure it's all working. I put my mount point into /media, but you can put it where you like.

 

cd /media

 


If the directory "usb" exists, great, if not, create it with:

 

sudo mkdir usb

 


Then mount the USB drive in that directory, and create a directory for TVHeadend to use:

 

sudo mount /dev/sda1 /media/usb

 

sudo mkdir /media/usb/data

 

sudo chmod 0777 /media/usb/data

 


Now you want to make sure your disk is loaded each time you restart the Pi. Edit /etc/fstab (again, I'm not going to tell you how to use vi), and add the following line at the end:

 

/dev/sda1 /media/usb ext4 defaults 0 0

 


Once done, I would suggest rebooting the Pi, then logging back in, and making sure you can still access the USB drive at /media/usb/, and that you can write to the /media/usb/data/ directory as the "pi" user (ie - without sudo).

5 (optional). Configure the EPG

The method Freeview uses to broadcast the EPG over-the-air is apparently a little difficult for TVHeadend to use. Thankfully there are some kind people that provide a download the the data in a convenient format. To use this, you'll need to add a script to your Pi.

 

cd /usr/bin

 

sudo wget https://dl.dropboxusercontent.com/u/6101726/Raspbian/tv_grab_nz-py

 

sudo chmod a+x tv_grab_nz-py

 

This provides the script that TVHeadend can use to download the data, but you do need to configure it first. Note that download is from my Dropbox account again, and I've made a small change to the script that is available elsewhere.

The script originally had an issue with the accented character in the word Maori, which caused the script to crash. This version just removes that character, so when you see "Mori Television", that's why.

 

sudo /usr/bin/tv_grab_nz-py --configure

 


Run through the prompts to select the channels you want. I just said yes to all of them, which is unfortunately not the default. Note there are some missing (eg. YESSHOP), and some that no longer exist (eg. U).

Now onto the fun part.

6. Configure TVHeadend

To make sure everything is available, it's a good idea to restart TVHeadend before you start to configure it. This makes sure it can see the EPG script and tuners if you've added them after installing it.

 

sudo service tvheadend restart

 


From your PC, log into the TVHeadend admin site with the credentials you set up way back in step 3. This will be by entering the IP address into your browser (eg http://192.168.1.50:9981/).

6.1 EPG

Let's start with the EPG, as TVHeadend can figure out the channels automatically if that's already there. Go to Configuration -> Channel/EPG -> EPG Grabber. If you've added the script correctly, you should be able see it as "XMLTV: New Zealand (py)" in the "Module" list for the Internal Grabber section. If you can't see it, go back and make sure it's been set up correctly as above.

Set the grab interval to 1 day. The online file is only updated daily, so more than that is unnecessary.

6.2 Adapter Setup

Now jump over to Configuration -> DVB Inputs. If everything is working as expected, you should be able to see your USB tuners listed in the drop-down box on the TV Adapters tab. If they're not there, it's likely the driver isn't installed properly. Jump back up to step 2 above, and make sure that's working before coming back.

Assuming you do see your tuners in the list, select one of them.

If you have multiple tuners, you probably want to give it a useful name, otherwise make sure the following options are ticked:

 

Enabled
Autodetect muxes
Idle scanning
Close device handle when idle

 

The rest should be unticked, or left at default values. Save. Do this for each adapter you have.

6.3 Multiplexes

Now for any adapter, switch to the multiplexes tab, and click "Add mux(es) manually...". Set the bandwith to 8MHz, and everything else to auto. For the frequency, the only list I've found is here. Unfortunately, I know that list is wrong, but it's a good starting point.

For the Waiatarua tower in Auckland, the frequencies you want are 538MHz, 570MHz, 586MHz and 602MHz. Since you need to enter them in kHz, enter 538000 etc. Add them all one by one, until you've got all 4 in. Then click the "Save Changes" button at the top.

At this point TVHeadend should scan the muxes to find channels. Leave it for a while to give it a chance to do this, then head to the Services tab. With luck, you'll see a whole bunch of channels, including duplicates, and some that don't work.

Once all the services are showing happily, head back to the General tab under the adapter list, and hopefully you can click the "Map DVB services to channels..." button. If not, or if the number under "Muxes awaiting initial scans" on the right is not 0, wait a bit longer, or try refreshing the page, and coming back here.

Click "Map DVB services to channels...".

If you have multiple adapters, you need to copy the multiplexes to them. Go back to the Multiplexes page for the adapter you have already set up, and select all the multiplexed (hold down Shift and click each in turn). Then click the "Copy to another adapter..." button, and select one. Repeat for each extra adapter.

6.4 Channels

Now head over to Configuration -> Channel/EPG -> Channels. There should now be a list of channels ready to be viewed. Hopefully most of them have an entry under the "EPG Grab source" columns as well. If not, double click the column and match it as appropriate.

Similarly, you can change or add the channel number assignments by double clicking on the "Number" column and entering what you like. Once you've set it up as desired, make sure you click the "Save Changes" button at the top.

6.5 (optional) Recording

Go to Configuration -> Recording. For the "Recording system path", enter the path that you mounted your USB drive on. I would recommend using a subdirectory in case you want to put anything else in there.

 

/media/usb/data/pvr

 


Select all the other options as desired. I don't believe the "Skip Commercials" option works in NZ, but we can always hope. :-)

Click "Save configuration".

=======================

At this point it should all be working. If you go to the "Electronic Program Guide" page, you should see a (horribly formatted) list of programs. If you have VLC installed, you can quite easily test it.

Click a currently showing program in the EPG, then click the Play link. This will open a box that will say you don't have the VLC Mozilla plugin. Right click the "Direct URL" link, and copy the link.

Open VLC, then File -> Open Network. Paste in the URL, and click Open. The username and password are the same as you entered for the admin (note you can set up different usernames via Configuration -> Access Control in the TVHeadend admin). You should now be watching TV.

======================
CLIENT
======================

If you want to setup a Raspberry Pi client, start with step 1. If you want to set up any other XMBC installation, jump to step 2. Note it's WAY easier to install XBMC on your PC to test before trying to set it up on a Raspberry Pi.

1. Install OpenELEC

What you need:
- Raspberry Pi (with SD card, power supply and HDMI cable)

Note - get the official Raspberry Pi image from this page. They haven't updated the installation instructions with the new image location. I'm running the 4.1.4 beta, and it seems perfectly stable to me.

I'm not going to cover setting up network, remote controls etc here. If you need help with that, I would recommend Googling, or asking in another stream. It's been pretty well covered.

Aside: If you prefer RaspBMC or Xbian, they'll both work too, and the instructions below are still valid for them. I prefer OpenELEC over RaspBMC as it seems much more responsive in the menus, and seems to start playing videos quicker. I haven't tried Xbian myself.

2. Configuring XBMC (note this works for all XBMC clients, not only OpenELEC)

Quick tip - if you're configuring OpenELEC on a Raspberry Pi, there are remote control apps for both iOS or Android that make it a lot easier. Not only do they have all the necessary buttons, but you can use the on-screen keyboard too!

Go to the System -> Settings menu, then select Add-Ons -> Disabled Add-Ons -> Tvheadend HTSP Client. Enable it, then click Configure, and enter the IP address, username and password of your server.

Back in System -> Settings, select Live TV. Under the General options, make sure it's Enabled, then select "Reset the PVR database". You should see the system pulling all the channel data from the server.

Configure everything else as desired.

Now you should be able to select Live TV from the main menu, and view the EPG, and all the channels shown in the TVHeadend admin page.

If the TV channels are interlaced, you can fix that by selecting the "Video" options while viewing a channel (bring up the OSD and look for the Reel icon). Switch Deinterlace Video to "Auto", then select "Set as default for all videos", and close.

If you see unwanted subtitles, bring up the OSD and select the "Sound" options (speaker icon), deselect "Enable subtitles", and again select "Set as default for all videos".

Test the PVR functionality by selecting a program in the EPG, and selecting record. Since recordings are saved by the server, you can play them back on any XBMC client you have, which is a nice feature. You can also download the saved files from the TVHeadend web admin if you want to do that.

You should be able to view all the channels without issue on a Pi XBMC client, including HD channels. The Pi is a fantastic little computer, and is quite able to cope with this.

=======================

Well, I hope somebody finds this useful. If/when you find errors in what I've written, or if I've missed something, please let me know and I'll fix this post.

If you have any questions or comments, please fire away, and I'll be happy to help out as I can. If you're an incredibly generous soul and want to donate a USB DVB-S tuner for me to try out, get in touch. laughing

Create new topic


47 posts

Geek
+1 received by user: 10


  Reply # 1114658 24-Aug-2014 17:17
Send private message

Note I've just discovered the timeshift functionality isn't working. From what I can gather, this is a known issue with TVHeadend, and I'm going to keep looking into it.

582 posts

Ultimate Geek
+1 received by user: 34


  Reply # 1114659 24-Aug-2014 17:19
Send private message

For a lot of common tuners the necessary firmware is available in the linux-firmware-nonfree package. It easily installed on Ubuntu/Debain with

 

sudo apt-get install linux-firmware-nonfree

 
 
 
 




47 posts

Geek
+1 received by user: 10


  Reply # 1114671 24-Aug-2014 17:29
Send private message

Turns out there is a bug with the maximum buffer size in the Timeshift. If you go to Configuration -> Recording -> Timeshift, make sure it's enabled, then TICK the unlimited option for maximum size, it all starts working.

Note "On Demand" means it will start buffering only if you click Pause, but you can't rewind live TV at all. With "On Demand" unticked, it will start buffering as soon as you start watching the channel, much like MySky does.

209 posts

Master Geek
+1 received by user: 19


  Reply # 1116737 27-Aug-2014 17:34
Send private message

Really good guide!
Great to have a NZ flavour

I got my USB tuners working with firmwares seemingly more available than last year when I tried

Only pointer I have is: a couple of sections have the commands bunched on one line, I managed to figure out the separation by looking at where the sudo word was.

TVheadend installed easily as advertised and configuration guide is great especially with the frequency instructions for akl

I do still have to test the channel streams with a client but all looking great so far



47 posts

Geek
+1 received by user: 10


  Reply # 1116739 27-Aug-2014 17:37
Send private message

groynk: Really good guide!


Thanks for that.

Only pointer I have is: a couple of sections have the commands bunched on one line, I managed to figure out the separation by looking at where the sudo word was.


Yeah, unfortunately some of the formatting was lost for some reason when I posted it, and by the time I'd noticed, I couldn't edit it any more. Sorry about that.

45 posts

Geek
+1 received by user: 2


  Reply # 1121767 4-Sep-2014 12:41
Send private message

I have a similar 3 tuner setup on a Pi.

One thing you need to do for a multi-room setup is for each DVB Adapter, under Multiplexes, make sure only 1 Mux is enabled per adapter. This ensures that if 2 clients select a channel on the same mux, only a single adapter will be in use.  If you have all muxes enabled on all adapters, a 2nd client will just grab another adapter even if another one is already receiving the desired mux.

It is possible to pull the EPG from the MHEG5 stream by using rb-download, mheg5grab.sh, and mheg2xmltv.sh.

212 posts

Master Geek
+1 received by user: 37


  Reply # 1122218 4-Sep-2014 22:31
Send private message

Great guide thank you.

As mentioned elsewhere, I was running TVHeadend Server on Openelec (XBMC), but after seeing this post I decided to try doing it this way as it seemed a waste of precious RPi resources running XBMC just to run the TVHeadend Server.

The set up went without fault, and I can tell already that it is performing better than what it was previously - mainly seeing it as less time to buffer when switching channels.

One tip that I've found is that sometimes when fiddling with the tuner settings you may need to fully shut down and power off the RPi to reset the tuners, mine seem to sometimes get in a "stuck" state where they stop responding or give inconsistent responses.



47 posts

Geek
+1 received by user: 10


  Reply # 1122438 5-Sep-2014 11:22
Send private message

xontech: Great guide thank you.

As mentioned elsewhere, I was running TVHeadend Server on Openelec (XBMC), but after seeing this post I decided to try doing it this way as it seemed a waste of precious RPi resources running XBMC just to run the TVHeadend Server.

The set up went without fault, and I can tell already that it is performing better than what it was previously - mainly seeing it as less time to buffer when switching channels.


I'm glad it helped.

One tip that I've found is that sometimes when fiddling with the tuner settings you may need to fully shut down and power off the RPi to reset the tuners, mine seem to sometimes get in a "stuck" state where they stop responding or give inconsistent responses.


I've not had any issues with tuners getting stuck at all. I have needed to restart TVHeadend any time I add or remove a tuner, as it obviously doesn't check for that (which is fair enough), but I've never had to restart a Pi completely.





47 posts

Geek
+1 received by user: 10


  Reply # 1122455 5-Sep-2014 11:40
Send private message

So I feel I should post a followup to this guide. I've been using this setup for a few weeks now, and for the most part it's worked really well. I'm still really impressed with how well the Pi handles something like this.


However I have hit one problem.

The other day I was recording a program (I haven't done that a huge amount) in HD, and started watching another HD stream, and there was quite a lot of stuttering. Some quick debugging showed that this was because both the recording and the timeshift were writing to the disk, along with the outbound network traffic, which saturated the USB 2 hard disk capabilities. Disabling the timeshift resolved the issue at the time.

However, I don't want to disable timeshift, and this issue would  also happen with timeshift alone if watching multiple HD channels. With that in mind, I'm starting to think the Pi is not the best solution for the server if you want to use it as a central PVR device. If recording was done on the clients, the Pi would be more than enough, but when the server does all the recording you'll probably need more.

So I've got hold of an Intel NUC, and will be upgrading the server end of the setup this weekend. I chose the NUC mainly for size and price. Advantages it has over the Pi as a server are quite obvious:

 

  • Internal SATA hard disk - I'm planning to use a 7200RPM HDD, but also have an SSD handy if the spinny disk doesn't give me the performance I need.
  • USB 3 for external hard disk - Also planning two disks, one for recordings and one for timeshift. USB 3 makes that feasible, and should increase performance further without the SSD.
  • Gigabit ethernet
  • Dual-core 2.4GHz processor - I went for the Celeron. It should be plenty, given the 700MHz single-core Pi is not hitting a CPU limit, though there are i3 and i5 versions available.
  • 4GB RAM instead of 512MB - not sure this is particularly useful given the intended usage, but it certainly can't hurt.
  • Built-in wifi - that I won't be using, but nice to have.
On top of hardware, I'm planning to build TVHeadend myself for the server, which means I can run the latest 3.9, rather than the 3.4 build that is the most recent available for the Pi.

I'll post an update with my experience here later.

Create new topic



Twitter »

Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:





News »

CPTPP text and National Interest Analysis released for public scrutiny
Posted 21-Feb-2018 19:43


Foodstuffs to trial digitised shopping trolleys
Posted 21-Feb-2018 18:27


2018: The year of zero-login, smart cars & the biometrics of things
Posted 21-Feb-2018 18:25


Intel reimagines data centre storage with new 3D NAND SSDs
Posted 16-Feb-2018 15:21


Ground-breaking business programme begins in Hamilton
Posted 16-Feb-2018 10:18


Government to continue search for first Chief Technology Officer
Posted 12-Feb-2018 20:30


Time to take Appleā€™s iPad Pro seriously
Posted 12-Feb-2018 16:54


New Fujifilm X-A5 brings selfie features to mirrorless camera
Posted 9-Feb-2018 09:12


D-Link ANZ expands connected smart home with new HD Wi-Fi cameras
Posted 9-Feb-2018 09:01


Dragon Professional for Mac V6: Near perfect dictation
Posted 9-Feb-2018 08:26


OPPO announces R11s with claims to be the picture perfect smartphone
Posted 2-Feb-2018 13:28


Vocus Communications wins a place on the TaaS panel
Posted 26-Jan-2018 15:16


SwipedOn raises $1 million capital
Posted 26-Jan-2018 15:15


Slingshot offers unlimited gigabit fibre for under a ton
Posted 25-Jan-2018 13:51


Spark doubles down on wireless broadband
Posted 24-Jan-2018 15:44



Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.