Watch Live TV From Anywhere

Posted by JD 01/10/2017 at 18:00

Watch Live OTA TV from your home from anywhere in the world – big deal, right? Well, it could be. Let me explain.

  • No extra service provider needed.
  • 1-time costs for equipment that works at home AND remotely from anywhere
  • Get around sports blackouts with a friend outside the blackout areas. THIS is the biggy.

Great, so what do I need?

To make this work, you’ll need a few things. Today, those things are 1-time costs of about $110, but often these can be found for under $100 or you might already have what is needed.

  • Broadband Internet – needed to stream the video/audio remotely
  • HD-Homerun “Connect” or any DLNA version; basically, this device let’s us capture the TV signals to a disk file.
  • Computer that can transcode video “in-real-time” – this is basically a Core 2 Duo or better. It will read the disk file, convert it to a low bandwidth video for internet streaming.

Details

Setup the HDHR device as you normally would. Get it working on your home network with whatever playback device you want. That could be a computer, raspberry-pi, Android device, Roku, whatever. The great thing about the HDHR4 (and other, newer versions) is that to capture a broadcast channel to a file is really just an HTTP GET. That’s it.

On my network, the HDHR4 device gets the same IP thanks to DHCP reservations. . That means to capture channel 2.1 will always be the same URL. That URL is: http://hdhr4:5004/auto/v2.1 Just the channel number changes at the end of the URL. For channel 69.2, the URL is http://hdhr4:5004/auto/v69.2 Simple. To save the mpeg stream from channel 69.2, use any web-capture program you like. I’ll use wget.
$ wget -qO 69.2.ts http://hdhr4:5004/auto/v69.2

Recording for a set duration is easy too. Use the timeout command. This will wait a specific amount of time, then end a process. To record for 64 seconds,

/usr/bin/timeout 60 \
wget -q -O 69.2.ts http://hdhr4:5004/auto/v69.2

Easy. Simple.

What’s left? We just need to transcode it on-the-fly.

/usr/bin/timeout 64 \
wget -q -O - http://hdhr4:5004/auto/v69.2 | \
ffmpeg -i - -c:v libx264 -crf 24 \
         -vf scale=-1:420 \
         -preset veryfast \
         -c:a libvorbis -q:a 6 "69.2.mkv"

Make sense? I’m transcoding and scaling down to 420p at the same time. Inside your home network, you might not need to transcode at all. Completely up to you. Also, the “24” is a quality factor. IMHO, 19.5 is the highest that is worthwhile. No artifacts seen. Many people use “22” and are happy. To use less bandwidth, make that number higher as you can live with. DVD resolution is 480, which I find sufficient for over-the-internet streaming. Inside my home, we have a nice, wired, GigE network, so there isn’t any need to scale the video or have poor quality.

So the output file is 69.2.mkv. Now you just need a way to access that file – that could be sshfs, over a VPN, using a web server, or a media center server like minidlna or Plex or … whatever you like.

Clearly, the transcoding requires a beefy CPU. It doesn’t need to be anything too drastic, just enough. A raspberry pi doesn’t have enough CPU to transcode at all, but a $50 current generation Pentium does. I use a Pentium G3258. Handles hi-def transcoding just fine.

It only captures 64 seconds. What if we wanted to capture 3 hours, for some sport? 10800 seconds is 3 hrs. Just make the “timeout” that number. On my system, the timeout can be in seconds, minutes, hours, or days. But the math is easy enough. timeout 60m command is the same as timeout 1h command . Easy. The default is seconds.

The hard part is dealing with limited upstream bandwidth. ISPs let us download 5-100x faster than they let us upload. Sometimes the upload bandwidth isn’t stable. This is mostly true for DSL lines where even 1Mbps uplink might not be available to many homes.

It is effectively a DVR too, but most people would prefer to use some other program that works off TV schedule data.

What to remove commercials? There is a tool for that too, but I’ve only seen it used after the recording is completed. comskip is the name. It has many settings and needs slightly different settings for almost every channel. The stations use different methods to make commercial detection fail. RTFM for comskip to see all the different options.

Wrap Up

Of course, you’d want to make the interface nice and may want to transcode different channels with different settings. Dealing with different command line options isn’t hard, but it is a little chore.

I use Plex Media server to access recordings from remote locations using a web interface. Setup an ssh SOCKS proxy to access it. Simple and it works without a plex account. From my client machine:

#!/bin/bash

# Only start SOCKS proxy if necessary
if  [ $(ps -eaf |grep ssh |grep -c 64000) = 0 ] ; then
   # Setup SOCKS proxy through home server
   echo "Starting ssh SOCKS Proxy"
   ssh -f -D 64000 gw.jdpfu.com -NT 
fi 

# Star private firejail with chromium, going through 
# just setup SOCKS proxy
echo "Starting Firejail chromium with private & proxy "
export http_proxy="socks5://localhost:64000"; 
firejail --private chromium-browser \
         --proxy-server="socks5://localhost:64000"&
  • firejail is a container.
  • chromium-browser is the F/LOSS version of the Google-Chrome browser.
  • ssh creates the SOCKS proxy for use.

For interactive scripts like this (only run when I’m there and interacting), I don’t follow all the safe, best-practices for scripting.

Then just visit the URL for the internal plex web server … http://plex:32400/web
Simple.