Monday 27 May 2013

Raspberry Pi and the HD PVR.. streaming and recording

Success! sort of...

I've finished rebuilding the C app, to read from the HDPVR and offer the data via a simple HTTP interface, and embedded a little control to toggle recording on & off. With the HDPVR running around 8mbit, I'm able to stream to about 5 clients simultaneously, which is pretty good going.

The downside is dropouts are still present.. (Update: not anymore!!) I'm hoping its just the HDPVR's fault, as these units are known to glitch occasionally & require a reopen.. even so I'm not going to call it a day yet, I'll have a bash at compiling MythTV and seeing how it's recording code gets on with the device.



I've linked the source below, with a bit of luck, you can save it as hdpvr.c on the pi, and compile it using..
   gcc -lpthread -o hdpvr hdpvr.c

Then run it using..
   ./hdpvr

You should get a response of..
   waiting for a connection

Once it's running, fire up VLC (http://www.videolan.org/) and use 'open network stream' and give it the url..
   http://ip.address.of.pi:1101/video

And then you should see the video start playing =) Check my other post if you need to select inputs other than component/stereo.

Once the video is playing, you can start recording by visiting (with a browser)..
   http://ip.address.of.pi:1101/startrec

And stop recording by visiting (with a browser)..
   http://ip.address.of.pi:1101/stoprec

Video is written to the directory you ran hdpvr from.. remember that the video streams will be large!! I've had success writing the data directly to a mounted SMB share =)

Dropouts are still present, the code will close & reopen the device.. usually the VLC client just glitches a little and then resumes playing. The recordings will need streamfixing afterwards to repair the glitches, (which will eventually end up as short cuts to the recording).. I've tried VideoRedo quick streamfix with mixed results so far.. Once I've got the Myth code recording, I'll see if I get better results.

With this code, the CPU load sits around 12% or so, so there's quite a bit of time free to still do stuff yet!!

Source:

5 comments :

  1. Uh, I have literally been looking for something exactly like this program for MONTHS and stumbled upon this page purely by accident. I've tried everything, mythvbackend, streaming from vlc on the command line, even trying windows. Something always works partway, but something else doesn't making it not work. This worked. Note: I had to put the "-lpthread" as the last arguement of the compile string or I got linker errors.

    ReplyDelete
  2. Hi =) glad to hear it's useful for someone else, the version in this post isn't as reliable as the later ones I've put up though, I've written more about those in later posts.. and I really need to get round to finishing up the web UI and posting the updates..

    Anyways.. for now, the latest code is at https://hd-pivr.googlecode.com/svn/hd-pivr/hd-pivr.c I hope to post before the end of the month with more info on that version =)

    ReplyDelete
  3. Are you still working on this? I've tried running this on my pi, and even some of my other debian based devices with a little more power, all with the same issue, being choppy video, and lack of quality. I'm not sure if i'm doing something wrong or what, but if i stream, the quality is less that good, and when recording, its completely unbearable to watch. the pvr works fine with hauppauge capture on windows, but just doesnt work right on linux. any suggestions? or is this project dead?

    ReplyDelete
  4. Its not dead.. Just been a little busy with real life.. Video shouldn't be choppy.. Wonder if your network could be struggling.. Are you on wired or WiFi?

    ReplyDelete
  5. wired on both the pi and laptop, gigabit network here, though the pi is only 100mbps so that doesn't really matter. i've tried a few things and recording seems to be working fine now, but streaming live video is still a bit choppy, when there is motion you can see lines, almost as if a refresh rate is off...

    ReplyDelete