Tuesday, October 21, 2014

Raspberry Pi DVR - The final configuration

I have finally reached the end of my Raspberry Pi DVR project.  My goal was to turn a Raspberry Pi into a DVR to record over-the-air broadcast TV.  To that end I have spent the last month experimenting with all the major distros available for the Raspberry Pi in an effort to determine the best distro.  Below is a step by step summary of my final configuration.

I ended up using Raspbain Wheezy as the operating system.  I downloaded the latest image (September 2014) direct from the Raspberry Pi Foundation's website.

Download the Win32 Disk Imager on your Windows computer.  Use this tool to write the above Raspbian image onto your SD card.

Stick the SD card into the Raspberry Pi and plug in power.  During first boot the Raspberry Pi configuration screen will come up.  I made the following changes.

  • Select "Internationalization Options" and then "Change locale."  Place a check by "en_US.UTF-8 UTF-8."
  • Select "Internationalization Options" and then "Change time zone."  Linux handles time zones differently than Windows.  Instead of selecting your time zone by name or UTC offset, you instead select a region and a city near you.  So for me I select Americas and Los Angeles.
  • Select "Internationalization Options" and then "Change keyboard layout."  For me I selected "Generic 104 key" and "English US."  This step is important as the default keyboard layout is English UK with things like the pound sterling symbol.
  • Select "Advanced Options" and then "Overscan."  Set this option to disabled.  Older analog TVs have overscan where the image is smaller than what the TV can display.  If I do not disable overscan then on my computer monitor I have half an inch of black all the way around the outside edge.  Disabling overscan corrects this.

Note: I did NOT set the Raspberry Pi to autoload the GUI (X desktop) on startup.  Because this will be a headless unit, having X running is just wasted resources.

Now would be a good time to configure the Raspberry Pi "BIOS."  Shutdown Linux, remove the SD card, and stick it into a Windows machine.  Append the following lines to config.txt:
arm_freq=800
core_freq=300
force_turbo=1
max_usb_current=1
The first 3 lines add a little overclocking which is totally safe, but definitely helps out.  The last line is required for the model B+ to take full advantage of the new USB power circuitry.  By default, the model B+ will deliver up to 600mA of power to the 4 USB ports.  However, with the above setting it can deliver up to 1,200mA (assuming you are using a good quality 2A power supply).  600mA might be enough under normal uses, but with the TV tuner and wifi card on top of keyboard and mouse, you will need the extra amps.

Next I need to configure my wifi.  I manually started the GUI desktop with the command "startx"  I used the shortcut on the desktop to configure my wifi connection.  There are ways to do this from the console, but it was just easier to do it graphically.

Now that the network is setup, we can configure the Raspberry Pi on my network.  By default Linux does not play well with other computers on the network.  Access to and from the Pi works only when using IP address and not computer names.  To fix that we need to install a networking package called Samba.  To install Samba run the command "sudo apt-get install samba samba-common-bin"

The next step is to give your Pi a computer name.

  • Run the command "sudo nano /etc/hosts"  There should be a line with "127.0.0.1   raspberrypi"  Change the "raspberrypi" to whatever name you wish to use.
  • Run the command "sudo nano /etc/hostname"  This should be a single line text file.  Replace the text with the name you entered above.
  • Commit the above changes with the command "sudo /etc/init.d/hostname.sh"  [I am not sure if this step is required.]
  • Reboot your Raspberry Pi.  After the reboot it should have a new computer name and you should be able to access computers via name.


In my setup, I want the Raspberry Pi to record TV programs directly to my NAS box.  To do that I need to mount the NAS box so that the Raspberry Pi can access it.  First, change to the /mnt folder.  Run the command "sudo mkdir nas"  This will create a folder /mnt/nas.  This folder will become the mount point for the NAS drive.  Now run the command "sudo nano /etc/fstab"  Scroll to the bottom and enter the following:

//<server>/<share> /mnt/nas cifs username=<user>,password=<pwd> 0 0

Where <server> is the name or IP of the NAS box and <share> is a shared folder where to save the videos.  Also <user> and <pwd> are the credentials used to access the NAS box.  After rebooting the Pi again, you should be able to browse to the NAS box at /mnt/nas.

To get my Hauppauge 950Q TV tuner working, I need to manually download the firmware file.  I started the X desktop again and used the Epiphany web browser.  I downloaded http://www.kernellabs.com/firmware/xc5000/dvb-fe-xc5000-1.6.114.fw.  I then moved the file to /lib/firmware

After all this work, it is finally time to install and configure tvheadend, which is the software that performs the actual TV recording and streaming.  This step is not trival, so I will cover everything in a dedicated post.

The final step, once all this is configured, is to ensure the Raspberry Pi is up to date.  Run the command "sudo apt-get update" which checks for available updates (but does not install them).  Then run the command "sudo apt-get dist-upgrade" to download and install the updates.  I have found that the second command often times hangs toward the end.  If this happens, unplug the Pi and plug it back in.  Once it comes back up rerun these two commands.  If they succeed then you are done.  However, they might fail and tell you to run another command first.  Run the command it tells you to run and that should clear up any problems.

There you have it.  An end to end configuration guide for turning a Raspberry Pi into a DVR for TV recording.  I hope you found this guide helpful!


Update: This addendum covers changes I made to help with tvheadend crash problems.

6 comments:

  1. Thank you so much for your month long+ work and subsequent blog. I have the same interest in utilizing my rPi collection. This blog has been very helpful in confirming my own experiments and issues, as well as helping the decision making process. Thanks again.
    -m

    ReplyDelete
  2. I am trying to get this to work in Openelec/Kodi, but it seems the commands don't work the same. My very limited Linux experience is hindering my progress. I was wondering if you tried Openelec? I have had the Hauppauge stick since 2009 and used to use this often, but not so much in the last couple years. I would like to integrate this as a full media hub.

    ReplyDelete
  3. Greetings:

    I'm using the same Hauppauge 950q USB tuner.

    Question: Why did you choose to use the "dvb-fe-xc5000-1.6.114.fw" instead of the "dvb-fe-xc5000c-4.1.30.7.fw" version also listed? How did you decide?

    I could only get mine to work with the latter.

    Thanks!

    Neil

    ReplyDelete
  4. Found it - in mine, anyway.

    In the /var/log/syslog file, after a reboot, one line reads thusly "tveeprom 3-0050: tuner model is Xceive XC5000C (idx 173, type 88)". This indicates mine needs the xc5000c firmware.

    Does yours actually say xc5000?

    Neil

    ReplyDelete
  5. Thank you, one question though - I want to use this with my plex dvr, if thats not possible (yet) - what application would you recommend for the Roku to view the OTA from the Raspberry pi 2?

    ReplyDelete
  6. great work freezer, where did you buy it, and how did you built that antenna for the dvr? please let me know.thanks.

    ReplyDelete