MythTV with IPTV

(Last updated on December 16th, 2020 at 08:05 pm)

I’ve been running MythTV for many, many years now.

Up until about a year ago, it used a Hauppauge DVB tuner card but the antenna connector / socket broke off it and attempts to repair it were futile.

So in the meantime, I used Myth for the usual videos and music, but watched TV via the different broadcasters’ web sites.

I’d been thinking for quite a while about setting Myth up to use IPTV streams instead of OTA broadcasts, but documentation, etc, is sketchy at best so I kept putting it off.

A couple of weeks ago, however, I decided to make a real effort – update the entire system (it was still running a 32-bit Ubuntu – a relic from when the main system / backend + loungeroom frontend ran an older AMD CPU) and finally get all TV coming in via IPTV.

It wasn’t easy…

To begin with, I backed up important files and the Myth database – just in case I needed to refer to previous setup stuff (like the custom Harmony remote bindings, etc).

Next, I did a fresh install of Xubuntu 20.04 (64-bit, finally :-)). Once installed, I removed all unnecessary software – this machine is a dedicated Myth backend and loungeroom frontend.

Then I spent days (seriously – a lot of them) reading up on all sorts of stuff to establish how I was going to plumb all of this together.

I had, by now, found Matt Huisman’s stuff very helpful stuff – in particular, https://www.matthuisman.nz/2017/07/australia-iptv-epg-files.html

I originally tried making up my own M3U file and feeding it to Myth’s IPTV Recorder capture “card”. This didn’t work (Myth versions below 31 can’t handle URL redirections, and no version seems to be able to handle HTTP custom headers which are required for a lot of IPTV streams).

By the way – I should point out that I’m in Brisbane, Australia, so am targeting TV local to here.

Anyways, I then tried using VLC to grab the streams and then pass them through to Myth’s External (“black box”) Recorder. This worked – sorta – but frequently the streams would lock up. Myth would give up on them after 10-ish seconds of no data and the only way out was to exit the view on the front end and re-enter it. Clearly, not acceptable…

Sooo, to cut a long story short, I decided to try Tvheadend (feeding into Myth’s IPTV Recorder “card”). Originally I installed TVH 4.2.8 from their official repo, but for some reason Myth kept telling me it couldn’t find the generated M3U playlist. Frustrated, and feeling basically out of options by now, I built TVH 4.3 (4.3-1886~g51a4c5bec to be exact). And yay! It worked!

So here’s a somewhat brief recipe to get it all happening…

Ingredients

  • X/Ubuntu 20.04 (Xubuntu is a lot lighter than regular Ubuntu)
  • MythTV 31+fixes
  • Tvheadend 4.3
  • Matt Huisman’s TVH M3U playlist file
  • Shepherd

You might well get away with different versions of the above. But I couldn’t.

Foreword

I’m not going to provide any great detail here – honestly, if you can’t handle steps involved then this probably isn’t for you. With that said, though, I’ll happily take some of your money to put it all together for you πŸ™‚

Install X/Ubuntu

Obviously, first you’ll need to install X/Ubuntu – if it’s a fresh install and you’re dedicating the machine to the purpose I’d recommend Xubuntu as it doesn’t include even nearly the amount of crud a usual Ubuntu install does.

In case you want to work with your system / network as I do (remotely, from my desk), you’ll want to set up SSH (openssh-server) and VNC for remote desktop. For the latter, I install x11vncserver then set up an SSH tunnel to the box with:

ssh -t -L 5900:localhost:5900 timberwolf 'x11vnc -localhost -display :0'

Note that, in the above command, “timberwolf” is the hostname of my Myth master backend. My desktop PC can find it using the name as I have an entry for it in my /etc/hosts file. Otherwise, just use it’s IP address.

Once that’s connected, you just need to VNC (on Ubuntu, Remmina is as good a VNC client as any) to localhost πŸ™‚

Install MythTV

Anyways… then install MythTV from the Mythbuntu PPA – see https://www.mythtv.org/wiki/Installing_MythTV_on_Ubuntu

Install Tvheadend

Then install ffmpeg (apt install ffmpeg). TVH will use this to pipe IPTV streams through.

Next, install Tvheadend – you’ll need (as of today) to build it from source to get the requisite version 4.3. See https://tvheadend.org/projects/tvheadend/wiki/Building – you can test it first by running it directly from the build folder, but then make sure you build a package (deb) to install. In other words, DO NOT run “make install” at the end of the build process, as this can make a mess down the track…

Alternatively, you can use the deb I built but I can’t guarantee it will install / work for you. If you’re using all of the same OS / software versions I am, though, it should. Install it with:

dpkg -i tvheadend_4.3-1886~g51a4c5bec~focal_amd64.deb

Configure Tvheadend

Once TVH is installed and running, you can access it by browsing to http://<hostname or IP>:9981

IN TVH configuration, add a new Network (type IPTV Automatic Network), and set it’s M3U URL to the appropriate one from https://www.matthuisman.nz/2017/07/australia-iptv-epg-files.html (you’ll find Networks in Configuration | DVB Inputs). Also, set “Maximum # input streams” to something appropriate for your usage (ie: max number of simultaneous recordings + live viewing). 6 works for me.

Then go to Muxes. Set any unwanted channels to Ignore (in the Enabled column – just double click the cell you want to change, then set it to Ignore from the drop-down). Ensure all other (wanted) channels have scanned as OK – for any that Fail, highlight the row and click Edit from the toolbar and then set “Scan status” to ACTIVE and Save. You may need to do this several times for some channels before they scan as OK.

Once all channels have scanned as OK, move to Services. Click “Map services” in the toolbar, then select “Map all services”. Then move to Channel / EPG and click the refresh icon on the bottom toolbar to verify all channels got mapped. Don’t bother setting the channel numbers here – they won’t “take” in Myth anyways…

Testing

If you have VLC installed (on the machine you’re configuring TVH with), you can now click the Play icon in the leftmost column of each channel to test it’s working.

MythTV setup

Now you want to start Myth’s backend setup. Once it’s running, the very first thing you want to do is set up Storage Groups. At the very least, you MUST configure the Default group – if you don’t, recordings will fail. The only clue as to why will be in the Myth backend log – something to do with no group being configured / found, so some other default directly will be used (but isn’t). It’s a good idea to allocate a dedicated drive partition to recordings, else they’ll happily chew up almost all available space on the drive / partition they’re stored in…

Then go to Capture Cards. Create a “card” of type IPTV Recorder. Set it’s URL to http://localhost:9981/playlist. Repeat this procedure (ie: create more “cards”) as many times as the number of input streams you configured earlier in TVH (so, for me, I created six identical IPTV Recorder instances).

Then go to Video Sources. Set up a single source – I called mine IPTV – and set it’s “Listings grabber” to none (Shepherd will reset this correctly later).

Then on to Input Connections. Create the first connection. Set the “Display name” to something descriptive and unique – I used IPTV1. Set the “Video source” to the source you created in the previous step. Then perform a “Scan for channels”.

Now create another new input connection for each of the “cards” you created. Set the display name of each one to something unique – I used IPTV2, IPTV3, etc. You don’t need to perform channel scans on these inputs. Of course, set their video sources to the one you created.

Now off to the Channel Editor. Set your preferred channel number for each channel. I used the same ones that regular OTA TV would use (ie: 70 for Seven, 96 for 9Rush, 24 for ABC News, etc).

At this point, I’d check that all’s gone well. Fire up a Myth frontend (could be on the machine you’re installing all of this on, or a remote one) and go to Watch Live TV (or whatever your theme calls it). Check that all channels lock and work and that the channel numbers are what you expect / want.

Guide data

If that’s all good, time to install Shepherd for guide data. Log into the backend machine as the user that runs the frontend (this could be “mythtv”, or in my case it’s me “mattt”. Open a terminal window. Follow the directions here. Once you’re done, note that the initial guide data grab will take at least a couple of hours. You can check if it’s done using Mythweb (http://<hostname-or-IP-of-backend>/mythweb) | Listings.

Channel icons

Finally, install some channel icons. I used https://www.xmlepg.net. Download the icons you want, renaming them to something simple and descriptive (I used seven.png, nine-rush.png, etc). Then copy them all to /home/mythtv/.mythtv/channels/. Then start the backend setup again, go to the Channel Editor and set the icon for each channel not the name (not the full path) of the file you download for that channel.

Database optimisation

I found database stuff to be ridiculously slow using the default MySQL configuration. So (begin to, at least) optimise it using the config at https://www.mythtv.org/wiki/Tune_MySQL. Note, however, that I excluded the “bind-address” line (as it already appears in the existing config file, which I modified rather than replacing as advised in the mentioned URL) and also the two lines mentioned (with three asterisks at the end) which are deprecated in MySQL v8 which is the version included in X/Ubuntu 20.04. Although not mentioned, the same (deprecated) applies to the “innodb_file_format” and “innodb_additional_mem_pool_size” lines. The database won’t start with these lines in the config.

I also commented out the logging lines, as I’ll not likely use them.

Then, as suggested, restart MySQL. Or just reboot.

Update: I’m not sure this has helped at all. Could well be a MySQL v8 thing. I’ll update this as I learn more…

Extra stuff

Create a default recording profile – the “record early / late” settings in the backend settings apparently don’t “take” in MythWeb, so (in any frontend) go to Manage Recordings | Recording Rules. Then hit “m” (for Menu), then press the Up key once to highlight New Template. Call the template “Default” and edit as appropriate for you (I choose to start recordings two minutes early and end them 10 minutes late). All new recordings set up in MythWeb from now will use this template’s settings as default.

Of course, there’s a bunch of other settings and stuff you’ll want to customise for your own install – the above is only what you need to get IPTV running and usable.

Have an appropriate amount of fun πŸ™‚

6 comments

  1. Hey Matt,
    Excellent, excellent tutorial. You saved me heaps of time researching how to use TVHeadEnd as an IPTV tuner and helped me move my MythTV backend to VMware in my study where there are no antenna points.
    Job Well Done! A BILLION Thank You’s

    1. Hey Arnie,

      Glad you could make use of it πŸ™‚

      I’m trying hard to allocate some more time to this site. There’s a few minor updates to add here, but nothing much – all still running solidly here (outside of channel changes, etc, which are to be expected)…

  2. Hi Matt,

    Thanks for your write up. I got TVH working and can watch all channels but when I enter the localhost URL into MythTV (31 fixes) I get ‘Downloading Playlist Error’, am I missing something?

  3. @Barry
    Make sure TVHeadEnd has a user called “*” with a blank password. You should be able to browse to “http://localhost:9981/playlist” without it asking for a password.

  4. Long time myth user here since 0.18/0.19 days. Currently just using hdhomeruns and myth 0.30 is inside a jail on freenas. I have got mythtv working in Kubernetes on a rPI cluster, but a trial run using a USB tuner was far from successful. I only just today setup tvheadend as a trial and it seems to be coping better. But the idea of feeding IPTV streams into myth hmmm….

    Also I just discovered after all these years for live tv the protocol for myth embeds the IP address of the backend which contains the tuner to use into the response for the client to use. It may also do this for recordings where the files are no accessible from the master backend.

    Still deciding as currently we only use Kodi/MrMC for playback and haven’t used mythfrontend for years.

    Also a long time shepherd user.

Leave a Reply to Arnie Delavigne Cancel reply

Your email address will not be published. Required fields are marked *