freezer
Posts: 11
Joined: Mon Jul 21, 2014 6:17 pm

RPi as a DVR for OTA TV, is it possible?

Mon Jul 21, 2014 8:09 pm

Since the RPi came out I've wanted to get one, but needed a project idea - something to do with it. I now have that idea, I want to turn the RPi into a DVR strictly for time-shifting over-the-air broadcast TV. Basically I want to connect an antenna to the RPi via a USB TV tuner, then have the RPi record shows of my choosing. I wouldn't use the RPi for playback, in fact the RPi would be headless (no monitor, keyboard, or mouse). I figure I'd stick the RPi and antenna in the garage, have it do the recordings, then after each new recording copy the video to my NAS box. From there I can watch it on my desktop computer and/or smart TVs.

Before I start buying hardware for this project, I'm trying to figure out if this is even possible? I know I need to buy the following:
1. RPi (I'm excited about the new B+)
2. The MPEG2 license from the RPi store (I live in the US and over-the-air TV is broadcast using MPEG2).
3. A USB TV tuner (I'm looking at the Hauppauge 950Q)
4. A powered USB hub
5. A USB wireless network adapter

I'll also need software to power all this. That's where I'm just starting my research. For example, I don't know the difference between the different RPi Linux distros. I also don't know what software is available to operate the TV tuner and make the actual recordings. To set this up initially I would connect a monitor, keyboard, and mouse. But once it's up and running I would remove all that and administer things via VNC. I haven't set up a Linux VNC server before, but that's the least of my concerns.

I guess my top questions at this point are:

A) Is this even possible? Does the RPi have enough horsepower to decode the MPEG2 stream and simultaneously record that stream to a video file?
B) Which distro of Linux should I start looking at first?
C) Any recommendations on DVR/PVR software?

I consider myself to be very technical. I'm a software engineer with 16 years programming on Windows. I also have moderate Linux skills. Enough to get around, but definitely not as strong as my Windows skills.

Thanks for any advice.

gkreidl
Posts: 6139
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: RPi as a DVR for OTA TV, is it possible?

Tue Jul 22, 2014 6:11 am

Most important is to find a usb dvb tv device that is supported by linux (preferrably already in the kernel). Check on linuxtv.org.

You don't need the MPEG-2 licence if you don't want to watch the videos on the RPi.

Why do you want to "decode" the video stream? A decoded stream is large and you will have a lot of problems even recording it to disk. Simply save the MPEG TS stream.

If you get a B+ you don't need a powered hub.

There's VDR but I have never used it. I've always created my own solutions. If you are a programmer this shouldn't be a problem for you.

On the RPi I've got the best results using mumudvb in unicast http mode. You can then access the streams across the network (to check them) and simply use something like wget to record the stream. Depending on your NAS, you could even do that on the NAS itself. You can also access all streams from one frequency at the same time. You'll need some kind of web interface to start/stop mumudvb and select channels from any computer on your network.

I wouldn't record to the SD card and then transfer it to your NAS. Mount your NAS drive as a Samba share and record to it directly.

WiFi may be critical but perhaps will suffice for MPEG2 streams. Ethernet is the preferred method (if not possible you can perhaps use some ethernet across power line solution).
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

freezer
Posts: 11
Joined: Mon Jul 21, 2014 6:17 pm

Re: RPi as a DVR for OTA TV, is it possible?

Tue Jul 22, 2014 5:37 pm

gkreidl - thanks for the reply with all the great info. Like I said, I'm just starting the research into this project so I have a lot of questions, some of which are probably dumb or obvious. :)

That's great news that I most likely won't need a powered hub with the B+. I'll be prepared to buy one if it doesn't work, but I'll try it without first.

From what I can tell, the Hauppauge 950Q is supported under Linux (both digital and analog tuning). I may continue to look around, see if I can find a cheaper option as the 950Q is twice the cost of a RPi.

I assumed (incorrectly) that TV recording software would decode the MPEG2 stream then reencode to the new video file. But as you pointed out, this is needlessly complicated. Just record the stream (much less CPU power) and let the viewing program (my smart TV) handle the actual decoding. Also, as you pointed out, I don't need to buy the MPEG2 license. I read somewhere that TVheadend outputs a MKV file with MPEG2 video encoding. I need to verify my smart TVs (Vizio) can handle this. I guess I could always transcode them on my desktop computer, but I want this to be as automated as possible.

As you suggested, I would mount my NAS and record the video directly there. As for my NAS, it's a Synology box which is a pretty capable device. Although admittedly I don't know how to use a quarter of the features.

I wasn't sure if wifi would be fast enough for the stream. I have a dual-band N router, so hopefully it is. If not, I'll just move everything inside the house and use ethernet. But I'll probably try wifi first.

Again, all great info. Thanks for the reply. I think now my big question is which image to use; Raspbian, Raspbmc, or OpenElec? I'll probably try all 3, see which works which does, and if one works better than the others.

gkreidl
Posts: 6139
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: RPi as a DVR for OTA TV, is it possible?

Tue Jul 22, 2014 6:05 pm

Just make sure you buy a good 2A power supply for the B+. There's a new config option that will enable sending 1.2 A to the USB outputs and that will be enough for 2 high power devices (500 mA) and two low power devices (100 mA).
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

houldsworth1
Posts: 1
Joined: Fri Feb 28, 2014 1:55 am

Re: RPi as a DVR for OTA TV, is it possible?

Sat Jul 26, 2014 2:56 am

I'm very interested in this.

As a recent "cord cutter" I've been enjoying paying 1/10th of my previous (basic) cable TV bill by getting almost all of my content through Hulu+

But there are a few things I miss such as those rare occasions when I want to watch sports. OTA TV seems to cover many of these so I just bought a leaf antenna and am now enjoying digital broadcast TV too. But...it's so old school actually only being able to watch whatever is on now.

I have a model B Pi in the basement mostly unused now that the robot project has been finished and people have moved on so this would be an ideal way for me to make use of that so I look forward to the updates.

Thanks!

freezer
Posts: 11
Joined: Mon Jul 21, 2014 6:17 pm

Re: RPi as a DVR for OTA TV, is it possible?

Fri Aug 01, 2014 3:09 pm

After much research I decided it's worth the investment to take on this project. I say "investment" because even though the Pi is cheap, buy the time you add in the cost of all the accessories it's over $100. There are commercial products (like the HDHomerun) that can do the same thing and only cost about $100. But where's the fun in that? The whole idea behind the RPi is it's fun to experiment and learn with. Plus, it's more flexible. Whereas the HDHomerun will only stream and record TV, the RPi could be made to do all sorts of things.

Anyway, I've ordered the following hardware: Hopefully everything will arrive within a week or so. Unfortunately I won't be able to start this project until mid August. My plan is to experiment with 4 different distros; OpenElec, Raspbian, Raspbmc, and Xbian. I want to find which distro works the best for my plan of a headless DVR. I'll report my results back here on this thread.

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: RPi as a DVR for OTA TV, is it possible?

Fri Aug 01, 2014 6:06 pm

freezer wrote: Anyway, I've ordered the following hardware:
  • Set of copper heatsinks
Send those back, YOU DO NOT NEED HEATSINKS OR FANS FOR YOUR RPI they do nothing except make the snake oil salesmen who are selling them a little bit richer.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

freezer
Posts: 11
Joined: Mon Jul 21, 2014 6:17 pm

Re: RPi as a DVR for OTA TV, is it possible?

Mon Aug 04, 2014 3:55 pm

DougieLawson wrote:Send those back, YOU DO NOT NEED HEATSINKS OR FANS FOR YOUR RPI they do nothing except make the snake oil salesmen who are selling them a little bit richer.
I knew before buying them that the RPi doesn't need heatsinks. And I also knew (from reading other users' experiences) that heatsinks don't make much difference, maybe a few degrees. Here's how I view it. Even though I've worked on computers for 20 years now, I've never experimented with different thermal/cooling options nor overclocking. So I want to use the RPi to tinker around with different thermal setups and overclocking settings. And isn't that what the RPi is all about; experimenting, learning, and having fun?

So yes, it was probably an unnecessary purchase, but a few extra dollars to experiment and have fun is worth it to me.

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: RPi as a DVR for OTA TV, is it possible?

Mon Aug 04, 2014 3:57 pm

But what's the point of running any experiment that has no valuable results. I've got a nice bridge to sell you if you'd like it.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

eschmidbauer
Posts: 1
Joined: Wed Aug 06, 2014 1:49 am

Re: RPi as a DVR for OTA TV, is it possible?

Wed Aug 06, 2014 1:51 am

Any update on this? Interested in doing something with a pi

freezer
Posts: 11
Joined: Mon Jul 21, 2014 6:17 pm

Re: RPi as a DVR for OTA TV, is it possible?

Wed Aug 13, 2014 5:51 pm

eschmidbauer wrote:Any update on this? Interested in doing something with a pi
A few days ago the last of the hardware finally arrived (for some reason Amazon took forever to ship the power supply and micro SD). So now I can start work on this. The challenge for me is finding the time to work on this. My goal is to try and complete this by the middle of Sept. which is when the new TV season starts. So hopefully within the next month I'll be able to report back.

tyler4pi
Posts: 1
Joined: Mon Sep 01, 2014 11:02 pm

Re: RPi as a DVR for OTA TV, is it possible?

Mon Sep 01, 2014 11:04 pm

How did this work? I would like try the same.

HiroProtagonist
Posts: 212
Joined: Sat Jun 29, 2013 9:45 am

Re: RPi as a DVR for OTA TV, is it possible?

Thu Sep 11, 2014 2:08 am

freezer wrote:Hopefully everything will arrive within a week or so. Unfortunately I won't be able to start this project until mid August. My plan is to experiment with 4 different distros; OpenElec, Raspbian, Raspbmc, and Xbian. I want to find which distro works the best for my plan of a headless DVR. I'll report my results back here on this thread.
I have a Pi running as a TVHeadend server with 3 DVB-T tuners attached. It works great.

I run Pi's as clients [running RaspBMC] which attach to TVHeadend on the server. However saving your files to a NAS as you plan to do will work as well. Note that if you can mount your storage as NFS this will perform somewhat better than SMB.

For your server Raspbian will be all you need. The other 3 distributions you list are all designed to run XBMC which is ideal for a client, but useless for a server.

freezer
Posts: 11
Joined: Mon Jul 21, 2014 6:17 pm

Re: RPi as a DVR for OTA TV, is it possible?

Tue Sep 16, 2014 9:25 pm

I've started the process of evaluating the different distros for the Raspberry Pi. I want to try each distro to determine which is going to work the best for my needs as a DVR. I'm going to blog about each as I try them. You can read my first review of Raspbian September 2014 image here: http://freezerdev.blogspot.com/2014/09/ ... pbian.html

I'm hoping to test 1 to 2 distros a week, so hopefully I'll have the last one done before October. Once this whole process is done, I'm going to do a followup post with the exact steps I used for the distro I end up choosing.

gkreidl
Posts: 6139
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: RPi as a DVR for OTA TV, is it possible?

Tue Sep 16, 2014 10:04 pm

No word about PVR in your whole report, just repeating things that have been covered a hundred times already.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

HiroProtagonist
Posts: 212
Joined: Sat Jun 29, 2013 9:45 am

Re: RPi as a DVR for OTA TV, is it possible?

Tue Sep 16, 2014 10:47 pm

freezer wrote:I want to try each distro to determine which is going to work the best for my needs as a DVR. I'm going to blog about each as I try them.
I'm hoping to test 1 to 2 distros a week, so hopefully I'll have the last one done before October. Once this whole process is done, I'm going to do a followup post with the exact steps I used for the distro I end up choosing.
Why are you bothering testing 3 distros that are focused on running XBMC for use as a server? It should be obvious that these are not viable options unless you want a single Pi to act as a server + client.

fruitoftheloom
Posts: 21084
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: RPi as a DVR for OTA TV, is it possible?

Wed Sep 17, 2014 5:55 am

HiroProtagonist wrote:
freezer wrote:I want to try each distro to determine which is going to work the best for my needs as a DVR. I'm going to blog about each as I try them.
I'm hoping to test 1 to 2 distros a week, so hopefully I'll have the last one done before October. Once this whole process is done, I'm going to do a followup post with the exact steps I used for the distro I end up choosing.
Why are you bothering testing 3 distros that are focused on running XBMC for use as a server? It should be obvious that these are not viable options unless you want a single Pi to act as a server + client.
He is testing the capabilities of RPi Operating Systems as a Software DVR, I can not see any mention of Server or XBMC in his post :o

http://en.wikipedia.org/wiki/Digital_video_recorder
Retired disgracefully.....
This at present is my daily "computer" https://www.asus.com/us/Chrome-Devices/Chromebit-CS10/

HiroProtagonist
Posts: 212
Joined: Sat Jun 29, 2013 9:45 am

Re: RPi as a DVR for OTA TV, is it possible?

Wed Sep 17, 2014 11:08 pm

fruitoftheloom wrote:
HiroProtagonist wrote:
freezer wrote:I want to try each distro to determine which is going to work the best for my needs as a DVR. I'm going to blog about each as I try them.
I'm hoping to test 1 to 2 distros a week, so hopefully I'll have the last one done before October. Once this whole process is done, I'm going to do a followup post with the exact steps I used for the distro I end up choosing.
Why are you bothering testing 3 distros that are focused on running XBMC for use as a server? It should be obvious that these are not viable options unless you want a single Pi to act as a server + client.
He is testing the capabilities of RPi Operating Systems as a Software DVR, I can not see any mention of Server or XBMC in his post :o
I'm aware of this, but he also says " I wouldn't use the RPi for playback, in fact the RPi would be headless (no monitor, keyboard, or mouse)" - i.e. He's proposing to create a DVR server.

Later he goes on to say: "My plan is to experiment with 4 different distros; OpenElec, Raspbian, Raspbmc, and Xbian" - the last 3 distros are all focused on running XBMC, which on a headless system is utterly pointless.

You can run a combined DVR server/client on the likes or RaspBMC, [I know, I've done it], but for a headless server only one of those choices makes any sense.

scorpios
Posts: 3
Joined: Sun Oct 19, 2014 12:38 am

Re: RPi as a DVR for OTA TV, is it possible?

Sun Oct 19, 2014 12:40 am

So, it's been a while and I'm eagerly awaiting further news. I am following your blog also...

What happened??!


Thanks!

freezer
Posts: 11
Joined: Mon Jul 21, 2014 6:17 pm

Re: RPi as a DVR for OTA TV, is it possible?

Thu Oct 23, 2014 5:34 pm

Sorry it's taken so long to report back on this. I recently finished this project. The short answer is, yes the Raspberry Pi can be used as a DVR to record over-the-air broadcast TV, but it's tricky and not without issue.

I decided to go with a headless Pi in the garage connected to an antenna. To that end, Raspbian was the best distro choice, using tvheadend as the DVR software.

The problems all stem from tvheadend, which is A) difficult to setup and B) difficult to run reliably on the limited resources of the Pi.

For configuration, I blogged all the configuration settings which hopefully will help people configure their own (see link below). As for reliability, you need to do as much as possible to free up memory for tvheadend. You need to disable unnecessary daemons, adjust the CPU/GPU memory shift, etc. But the most important thing you could do to ensure success here is connect the Pi to your network via ethernet. The wifi link is just too much for the Pi to handle. Consider that ATSC digitial TV is about 5GB/hour in size. That means the USB bus on the Pi must handle at least twice that. 5GB coming in via the USB TV tuner, and another 5GB going out over the USB wifi adapter. And it all has to be done in real-time, any delay will result in missed live TV recording. Getting this to work on the Raspberry Pi is tricky. So again, if you wish to make your own Raspberry Pi DVR, try and use ethernet if at all possible. On my blog I talk more about my efforts to get this to work over wifi.

Blog link:
http://freezerdev.blogspot.com/2014/10/ ... ation.html

Good luck to anyone else wishing to replicate my setup!

HiroProtagonist
Posts: 212
Joined: Sat Jun 29, 2013 9:45 am

Re: RPi as a DVR for OTA TV, is it possible?

Thu Oct 23, 2014 11:16 pm

freezer wrote: The problems all stem from tvheadend, which is A) difficult to setup and B) difficult to run reliably on the limited resources of the Pi.

Consider that ATSC digitial TV is about 5GB/hour in size.
I agree that tvheadend can take a bit of setting up. One of the challenges is that each country has a more or less different system, so it's hard to do a one-size-fits-all tutorial.

I can't agree with B) though - I run a 3 - tuner setup on a Pi, and the CPU and memory consumption on the Pi is quite modest , and reliability hasn't been a problem at all.

5GB/hour is quite a chunk, I presume that's because your system is mpeg2? We have mp4 here & recording [and viewing] multiple programs at once hasn't been a problem.

freezer
Posts: 11
Joined: Mon Jul 21, 2014 6:17 pm

Re: RPi as a DVR for OTA TV, is it possible?

Fri Oct 24, 2014 3:05 am

HiroProtagonist wrote: I agree that tvheadend can take a bit of setting up. One of the challenges is that each country has a more or less different system, so it's hard to do a one-size-fits-all tutorial.
It's hard to fault tvheadend. As you say they need to support all types of systems around the world. And let's not forget that it's free software. And to it's credit, it works once you get past the steep learning curve.
HiroProtagonist wrote: I can't agree with B) though - I run a 3 - tuner setup on a Pi, and the CPU and memory consumption on the Pi is quite modest , and reliability hasn't been a problem at all.


Really!?! Well I'd love to know your secret. CPU is never a problem, top reports that tvheadend remains under 20% during active recording. But memory - within a few minutes of recording tvheadend has consumed >90% of the system RAM. How are you saving your video files? To a local USB storage device, over ethernet, or over wifi? I suspect a lot of my memory consumption is from the wifi link.

HiroProtagonist wrote: 5GB/hour is quite a chunk, I presume that's because your system is mpeg2? We have mp4 here & recording [and viewing] multiple programs at once hasn't been a problem.


Yeah, the U.S. and Canada use ATSC which is MPEG2 video encoding and Dolby Digital AC3 audio encoding. From what I've read this is different than everyone else in the world. One of many problems with ATSC is MPEG2 is licensed software requiring a licensing fee for each decoder. Speaking of which, I thought I'd mention that my setup does NOT require the MPEG2 decoder license that can be purchased for the Raspberry Pi. Because the Pi DVR is merely copying the stream and not decoding it, the license is not required. If however you wish to watch these videos from the Pi, the you'll want to buy that decoder license.

freezer
Posts: 11
Joined: Mon Jul 21, 2014 6:17 pm

Re: RPi as a DVR for OTA TV, is it possible?

Mon Oct 27, 2014 3:08 pm

Here's another followup with more details about my problem. As I said, the problem is using wifi the Pi cannot write the video stream fast enough which results in buffering which eventually consumes all the Pi's limited memory.

For North America, all the numbers I've seen say that an hour of ATSC averages 5GB in size. This might be a good average, but doesn't give an indication of upper limits. Recently I recorded an hour of TV, the result of which was a 6.2GB file. Using this larger file as a test, I copied the file to my NAS using the wifi from the Pi located in the garage. The first time this copy took 59 minutes, the second time it took 62 minutes. So for an hour of TV, I'm right at that hairy edge. The Pi needs to stream an hour of TV in less than an hour, else buffers will get consumed.

I was curious so I disconnected the Pi, moved it closer to my wifi router to get 100% wifi signal, and repeated the copy. This time it took 22 minutes. So this tells me it's technically possible to copy a TV video stream faster than it comes in.

My plan of attack is as follows:
  • Continue to play with antenna mounting location in the garage. Clearly there is a direct correlation between wifi signal and data throughput.
  • Experiment with those homemade wifi antenna reflectors (e.g. Windsurfer) as a means of increasing my signal even more.
  • I might try a new wifi adapter. The following has more throughput than my current adapter so it might work better in my setup. [http://www.newegg.com/Product/Product.a ... 6833166074]
As always, my backup plan is to write the video to a USB thumb drive and copy the file to my NAS later on. I'm just trying to avoid that if possible.

gkreidl
Posts: 6139
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: RPi as a DVR for OTA TV, is it possible?

Mon Oct 27, 2014 4:09 pm

Forget WiFi. Invest into cabling or a powerline adapter.

Just a few of my own experiences. I use mumudvb to stream TV using unicast http streams (multicast also works but not with omxplayer). Recording can be simply done using wget.

1) DVB-T: streaming all 4 (SD) channels at the same time. Watching one on the RPi directly and serving two more (different) channels across the network. No problem for an overclocked RPi (and using ethernet, of course).

2) Sat TV: here I use only single streams, not the whole transponder. With up to a dozen streams on one transponder, the RPi is at its limits. But a few (up to 4) SD channels could be streamed at the same time and at least 2 HD channels.

Watching an SD stream on the RPi and streaming it to 2 more computers was no problem at all.

HD: watching a 1080p TV stream on the RPi directly and streaming it to another computer at the same time worked perfectly (as would be recording across the network or on a local HD).
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

HiroProtagonist
Posts: 212
Joined: Sat Jun 29, 2013 9:45 am

Re: RPi as a DVR for OTA TV, is it possible?

Mon Oct 27, 2014 10:12 pm

freezer wrote: Really!?! Well I'd love to know your secret. CPU is never a problem, top reports that tvheadend remains under 20% during active recording. But memory - within a few minutes of recording tvheadend has consumed >90% of the system RAM. How are you saving your video files? To a local USB storage device, over ethernet, or over wifi? I suspect a lot of my memory consumption is from the wifi link.
I'm saving all my files to a local HDD on the server, and using the TVHeadend client to access the server over the network [and NFS to access other stuff on the server]. After playing around with wifi, I went for wired ethernet, using a powerline adapter to one location I couldn't easily get a cable to.

As others have suggested, avoid wifi if you can. There are several problems with wifi, 1) Increased CPU load on the Pi handling the encryption. 2) Higher/variable latency. 3) Shared media [if you can get video streaming to work, you still have to share the available bandwidth with any other wifi usage - if one of them is also streaming video things can get really tight]. Switched wired ethernet is going to perform a lot better.

If you're low on memory, consider adding swap to the Pi. I have 512Mb swap on my Pi, which barely gets used, but if I do use something that consumes a lot of memory, it allows the Pi to swap out some infrequently used processes instead of needing to keep it all in RAM.

Return to “Other projects”