Introduction to MythTV

Notes initially written in conjunction with a presentation for the BYU Unix Users Group and subsequently updated.

What is MythTV

MythTV is an all-around media and entertainment program for Linux. It features a TV-friendly user interface and supports recording, scheduling, and viewing of television programs. It also includes many optional plugin modules. My complete MythTV system includes web-based recording scheduling management (with MythWeb), DVD playing, Nintendo emulation (with FCE Ultra), web browsing (with Mozilla Firefox), weather forecasting (with Mythweather), and miscellaneous Linux games such as Tuxracer. TV shows, both live and recorded, can be viewed from any computer on my network.

That whole paragraph can be reduced to a single sentence: "Cool." It really is nice to be able to watch what I'm in the mood for and to have commercials skipped.

Note that MythTV is currently at version 0.19. This number reflects the attitude of the developers: MythTV is a work-in-progress. Although the project is relatively stable, new bugs are created almost as quickly as old ones are squashed. The true geek feels satisfied because new features are constantly being added to the project, and because the system is so configurable. From personal experience, MythTV is definitely stable enough (and intuitive enough) that technophobe roommates and family members can use your system. However, setting up a system for someone else will include committing to provide them technical assistance anywhere between once a week and once a month, depending on their abilities. Be a little careful.

Features and Plugins

Recording Schedules and Conflict Resolution

When you select a show for recording, you specify whether to record it once at that exact time, at that time every day, at that time every week, every time it's on that channel, every time it's on any channel, or one time on that channel at any time. For one-time recordings, I like the last option because MythTV can automatically minimize the number of conflicts.

In general, MythTV is great at resolving conflicts. You configure a default priority for all shows. Then, when you request that a show be recorded, you can add or subtract a number from the priority. The system is pretty configurable--my system knows that a show that gets recorded every day is lower priority than a show that only gets recorded one time.

MythTV also provides a listing of current conflicts and allows you to make adjustments to ensure that particular shows win out. I have put very little effort into tuning priority levels but have been very pleased with the results.

MythWeb (standard plugin)

MythWeb lets you manage your recording schedule with a web browser. It's simply a PHP frontend to the database. It's actually more convenient than the on-screen scheduling system since you can see more on the screen, open tabs, and use a mouse and the back button. As long as PHP is installed properly, MythWeb is easy to get going.

Even if you don't want to schedule recordings from a web browser (which I definitely recommend), you should still install MythWeb. The Settings page in MythWeb is currently the only way to modify key bindings in MythTV. Note that you must select which computer to apply the settings for--a different configuration state is stored for each hostname.

Commercial Autoskip

Commercial Autoskip is a great feature. Though it's not perfect, it's improved tremendously since I first started using MythTV. I can't stand watching "normal" (lame) TV--every time I see a commercial I subconsciously search for the remote control.

Autoskip uses strategies such as looking for blank frames and paying attention to the length of scenes. Usually it works well, but some stations and shows are better than others. Sometimes it will skip part of a show (especially darker shows), and other times it will let an ad in. Keep your hand near the remote, just in case.

Multiple Frontends and Backends

Myth runs a background server process (the Backend), and several computers--each running a Frontend--can play back TV shows at the same time. Depending on exact conditions, it is even possible to watch a show over a wireless connection. In fact, there can even be multiple Backends, each recording a different show at any given time. Note that a Windows Frontend is currently in development.

Timestretching

MythTV version 0.17 introduced timestretching, which allows you to accelerate or decelerate playback without changing the pitch (i.e. without the chipmunk effect). It's especially good for watching talks, lectures, or History Channel-type shows. You'll note some slight sound distortion with music, but for most shows it's not distracting.

Exporting Video

To export video from MythTV, you'll probably want to use Nuvexport. It's a simple wrapper that uses mythtranscode and ffmpeg to export to various formats, namely SVCD, .nuv/.sql, DivX, WMV, VCD, DVD, MP3, and XviD. It uses a simple text-based menu interface.

If you have a video iPod, or if you use iTunes, you can set up MythTV to automatically export shows as a Podcast (using Myth2ipod, a script that runs ffmpeg and creates xml files).

One great feature to use when exporting video is the MythTV Editor. It's a simple interface for editing cutlists. You can use it to permanently remove commercials. Just import and fine-tune the commercial autoskip list, add additional cuts, and hit 'X' to transcode the video, removing all cuts from the file. MythTV 0.19 introduced the ability to strip commercials without re-encoding the video.

Calling External Programs

MythTV's menu structure is largely defined by XML files, and MythTV is perfectly happy to call external programs. Many standard plugins call helper apps, such as Xine, Mplayer, FCE-Ultra, etc., but you can easily add your own menu items anywhere in the menu structure. I highly recommend adding Firefox to the menu.

MythDVD (standard plugin)

I have a DVD-ROM drive in my computer. The MythDVD plugin provides an interface for Xine, which I use for watching DVDs. Xine passes the digital audio through to an external amplifier for surround sound. MythDVD can also rip DVDs to disk, allowing you to watch movies without wearing down the physical media. Recent versions of MythTV have a built-in DVD player, which I haven't tried yet.

There is also a separately available plugin called MythBurn, which will probably never be included in the official MythTV distribution. MythBurn is the inverse of MythDVD--it lets you burn TV shows to a standard movie DVD that can be played back on any DVD player.

MythVideo (standard plugin)

MythVideo lets you display video files in a predefined directory. All of my funny commercials, Steve Ballmer clips, and other video files are accessible by MythVideo.

MythGame (standard plugin)

If you like games, you can do Nintendo emulation, etc on your media system. When it's on a TV, an innocent bystander could never tell you don't have a real Nintendo, especially if you have a USB Nintendo controller. I use FCE-Ultra for Nintendo emulation.

If you want to do external programs like TuxRacer, you need to setup a gamelist.xml file. Here's my gamelist.xml. Note that you'll have to go to the Game Setup menu and Rescan for Games every time you make any change at all to gamelist.xml.

Other Plugins

MythWeather is a cool little plugin. It downloads the current weather, the forecast, and the Doppler radar (stationary only) for your configured city.

MythMusic is a music player module, with playlists, etc. Unfortunately, its interface is gay. It's a cool idea, but I don't like it much. Hopefully it will see progress in the future.

MythGallery is an image slideshow program. I haven't used it much because I don't have all that many pictures.

MythNews is an RSS feed module for MythTV. I don't find it horribly useful, but it's a cool idea.

Required and Optional Hardware

Don't feel like you need to go out and spend hundreds of dollars on hardware. Everything is optional. If you just want to watch your DVDs that you've ripped to the computer, you don't need to buy any hardware. If you want to record television shows, all you really need is a tuner card. Buy one component at a time as you decide what you want to do with your system.

TV Tuner Card

The most essential purchase, for you cheapskates out there like me, is a TV tuner card. This is a card with a coax plug for plugging in cable TV (or connecting to a satellite receiver with a little extra work). There are tons of different tuner cards out there, which fall into three basic categories:

Cheap ($30 to $50): software-encoding tuner cards
Cheap cards just give you a string of images. Some have a built-in sound digitizer, which looks to the OS like a sound card, while others have a sound-out jack that plugs into your existing sound card. If you already have a software encoder, use it, but if you're buying a new card, get a hardware encoder card instead. A software encoder will require a faster computer than a hardware encoder card will.
Average Price ($60 to $180): MPEG encoder cards
Hardware encoder cards produce encoded MPEG video streams. They demand much less of your CPU than cheap cards. If you can afford it, get one of these. Hauppauge is the best supported manufacturer in Linux. It took me a while to figure out the difference between the WinTV PVR 150, PVR 250, and PVR 350. The WinTV PVR 250 is the tried-and-true hardware tuner card and is solidly supported. The WinTV PVR 150 is basically a newer, lower-priced 250; originally it wasn't well supported, but those days are gone. The WinTV PVR 350 is like a 150, but it can also do TV-out, if you put enough work into it (although getting a video card with TV-out might be cheaper in the end). The WinTV PVR 500 is two 150s on the same card, so you can record two different shows at the same time (it's awesome, though there are still some little bugs in the driver). If a card has "MCE" in the model name, it usually means that it supports component video input, which I think is a good feature. "MCE" also means that it won't come with a remote.
Expensive ($170 to $200): HDTV cards
HDTV cards are MPEG encoder cards that support high-definition TV. The pcHDTV 3000 card was designed to work with Linux, but I have no personal experience with it. I've never used HDTV, but it's getting more and more popular.

Note that it is much easier to use these tuner cards for cable television than for satellite. Satellite systems only work with a receiver, and getting MythTV to be able to change the channel on the receiver is an extra layer of complexity. Some receivers have firewire connections, removing the need for a tuner card entirely, and some have a serial port which can be used for changing channels, but most frequently an IR transmitter sends signals from the Linux box to the satellite receiver.

Many tuner cards come with a remote control. You can usually get them to work (remember, Google is your friend), but I prefer using a learning remote as described later.

Video Card

If you want to watch TV on your TV (definitely recommended), your video card must support it. Many nVidia and ATI cards have RCA output jacks. Configuration is dependent on your video card, which usually isn't very hard. I've been really happy with my nVidia card, though it's not completely without problems.

Hard Drive

No matter what the size of your hard drive, make sure that if you have a software encoder that you auto-transcode your files. Likewise, if you have a hardware encoder, make sure that you reduce the capture quality settings. If you do this you can store two to five times more.

In any case, I would recommend that you dedicate a minimum of 50 GB of disk space to MythTV (I've seen 250 GB SATA disks by Seagate for about $100). I started out with about 50 GB for MythTV and have slowly upgraded to about 500 GB. Since my apartment has four guys (several of which have strange taste), we use a lot more space than most normal people would.

Remote Control

There are a number of types of remote controls that can work with MythTV. When you're first setting up a TV system, the remote shouldn't be the main focus of your efforts. However, when you buy a tuner card, you may have a choice between one with a remote and one without a remote. My favorite approach is to have an infrared keyboard and a learning remote, because the keyboard makes the system incredibly versatile.

One way to get a remote control working with MythTV is the do-it-yourself method of LIRC, the other is by using a learning remote. LIRC lets you have an IR receiver that works with almost any remote control out there, but it can be tricky to set up. A learning remote can cost a bit more, but is easy to set up. In any case, a wireless keyboard can come in very handy. If you plan on using a learning remote, you should get a keyboard that using IR for wireless (not RF).

For using a learning remote you'll need an IR wireless keyboard. Then you need to purchase a learning remote. A number of universal remotes market themselves as "learning", when they only have a few trainable buttons, and some learning remotes have a limit on how many commands they can learn. Remote Central has good reviews and information to help you know if you're getting what you expect. After getting the keyboard and remote, you simply train the remote with the keyboard's keystokes.

MythTV with Satellite Receivers

If you have to use a external tuner box, as with some cable, and both Dish Network and DirecTV, you'll need to have myth take control of changing the channel. The MythTV FAQ has some basic guidelines for doing this. Basically you're going to tell myth in mythtv-setup that it needs to use an external program to change channels. MythTV comes with some examples of these in the <source_dir>/contrib/channel_changers. Depending on your box, there are a number of different ways to control it: Serial Port, or USB, or if you're in a bind you can get an IR transmitter, and fake the remote control. Google and the mythtv mailing list are your friend in this situation. There is also an option to use firewire to capture video =66rom your cable/satelite box, but it looks like channel changing still is done externally. All of this requires more work on your end to get it working, but can be done.

Architecture

MythTV is very network-aware (I would say network-friendly, but then there are bandwidth issues). There is a server program and a client program, which are called respectively mythbackend and mythfrontend. MythTV allows for multiple frontends and multiple backends. Any number of programs can be played on different frontends at any time. If there are multiple backends, one of them is designated the master backend, and the others are slave backends. The master backend coordinates the recording schedule.

The primary, underlying natural limitation is the simple principle that any given tuner card can only be tuned to one channel at a time. If you want to record two shows at once (and watching live TV counts as recording a show), you must have two or more tuner cards in one or more backends. For example, if you only have one tuner, you can't watch live TV while you are recording a show, and you can't record two shows at the same time. However, you can watch an already recorded show while you are recording a show if you wish. Alternatively, you can watch live TV and seventy-three recorded shows at the same time, as long as you have a fast enough hard disk, CPU, and network. Understand this principle before attempting to install or use MythTV.

MythTV is very dependent on MySQL. It uses it for everything--even for configuration. Here's where it gets just a little weird: the client configuration is actually stored on the backend server. Every machine running a backend server must be running MySQL, but a machine that is only a frontend has no need to run MySQL. When a frontend starts, the first thing it does is to go to the SQL server (on the master backend) and figure out what's going on. The MySQL database on the backend server stores the configuration for each frontend, with a separate configuration for each hostname. One consequence of this is that by default, all users on the same machine will share the same frontend configuration, although you can override this by manually specifying a "hostname" in mysql.txt. Another consequence is that a Myth Frontend works really well on a read-only system like KnoppMyth.

Installation

Which Distro?

It really doesn't matter which distro you use, as far as Myth TV is concerned. If you like Fedora, use Fedora. If you like Debian, use Debian. If you don't know what you want, continue reading for some suggestions. However, if you don't know what a distro is, or if you aren't familiar with any of them, MythTV might still be a little more work to set up than you are prepared to face.

KnoppMyth

If you consider yourself inexperienced, you should strongly consider KnoppMyth, built on the Debian-based Knoppix distribution. KnoppMyth is a prebuilt MythTV system on a CD. It can boot directly into a frontend without installation, and it includes a backend installer. It is the closest you will get to "working right out of the box." However, experienced Linux users who have a favorite/preferred distro or who already have a running system will most likely be happier installing MythTV from a package or from source.

NOTE: If you are reading this in February, 2006, please note that KnoppMyth still uses MythTV 0.18.2 instead of 0.19, which is a huge change. Version 0.19 probably won't be available for KnoppMyth until mid-March.

KnoppMythWiki
Documentation
KnoppMyth
Official Site and Downloads

Fedora Core

Fedora Core (Redhat) is a very popular distro, and there are some excellent resources for using MythTV with it. If you prefer Fedora Core over other distros, don't hesitate to stick with it. If a less experienced Linux user is trying to learn and wants to be able to get help from local Linux users, Fedora is a great choice for MythTV. Note that Fedora Core 4 is generally very up to date when it comes to IVTV and MythTV, thanks to ATrpms.net.

To install Myth TV on Fedora Core, go to Jarod's Fedora MythTV HOWTO. In general, follow his instructions step-by-step. Note for users of IVTV (i.e. Hauppauge 150, 250, 350, 500): his driver installation instructions are a bit outdated, so search the web if things aren't working after you've followed his instructions.

Debian

I personally use Debian on my MythTV box, and it works really well. With Debian, you have two choices. You can either use Debian packages, which tend to be outdated and flaky, or you can install from source, which is actually really easy. In fact, if you are a Debian user, you may well enjoy using revisions of MythTV that are more recent than the latest release.

If you install from source, you'll need to add to your /etc/apt/sources.list "deb ftp://ftp.nerim.net/debian-marillat/ sid main" (assuming you're using sid). This source is necessary for LAME and possibly other prerequisites. Install the following packages with apt: "subversion liblame-dev libasound2-dev libdvdnav-dev libqt3-mt-dev libqt3-mt-mysql qt3-dev-tools libxxf86vm-dev" (please let me know if I'm missing any here).

Grab the MythTV source code from svn.mythtv.org. The development branch (trunk) is generally stable enough to use, and if you're running a recent release, you'll have more luck submitting bug reports. Note that MythTV developers all run recent SVN revisions on their own Myth boxes. If you're a bit paranoid (which is fair enough), use the release-fixes branch, available from the same site. A "./configure --help" will show you the configure options you need, and a "make; make install" will work as expected.

Ubuntu

Apparently the universe repository has MythTV packages.

Temporary: Check out deb.thehunter.ws for a Ubuntu MythTV repository for MythTV 0.19. Use this repository if the universe repository doesn't have 0.19 yet. The sources are listed on the web page and will need to be added to /etc/apt/sources.list.

SuSE

The MythTV Wiki has a page about how to install MythTV on SuSE. In general, there seem to be fewer MythTV users running SuSE than some of the other distros.

Gentoo and Other Distros

You know who you are. :) You're on your own.

Configuration

Configuring the First Backend

Make sure MySQL is running and will run again after reboot (check the init scripts and runlevels). Then load the mysql database file, which at least on Gentoo is installed at "/usr/share/mythtv/database/mc.sql". If that's the location, just do "mysql </usr/share/mythtv/database/mc.sql", adding -u and -p parameters as needed.

Run the mythsetup program. If you're going to have more than one frontend or backend, make sure to replace the backend server IP address from 127.0.0.1 to your FQDN or routable IP address. Actually, just do it, even if you aren't going to have a second frontend or backend.

Configuring the Frontend on the Same Box as the Backend

Run the mythfrontend program and select Setup. There's all kinds of good stuff there. A lot of it is described well on the MythTV documentation website and in on-screen help. My recommendation is to start out with the defaults and to make modifications one at a time.

Configuring a Second Frontend

By default the MySQL server on the backend won't let you connect as the "mythtv" user from anywhere other than localhost. Go in and add a new "mythtv" user for the second frontend host, for a subnet wildcard host, or for the % host if you're firewalled off. Remember to "flush privileges." Test that you can connect as the mysql user by running "mysql -u mythtv -h [backend-server] -p" from the new host(s). If none of that made sense, read the MySQL documentation, particularly the MySQL Privileges section, until it does (it's really good documentation).

Finally, modify the /usr/share/mythtv/mysql.txt file on the frontend computer to have the correct DBHostName, DBUserName, DBPassword, etc. Then mythfrontend should magically work, and you're off to client configuration, as described for the first frontend.

Program Listings and Zap2it

Setting up an account with Zap2it is free and easy. Configure MythTV via mythfrontend with the Zap2it account name and password. Add a crontab entry to run mythfilldatabase every night. It should be able to do this automatically, but there's a bug or something, so I just have cron do it.

Themes

I personally recommend ProjectGrayhem and Gray-OSD, neither of which is yet in the main MythTV release.

Miscellaneous Problems and Solutions

Nuvexport hangs while transcoding from NUV to some other format

On some systems Nuvexport hangs right away when it starts transcoding from NUV to some other format. Its output looks like this:

frame=    3 q=2.0 size=      52kB time=0.1 bitrate=4240.2kbits/s

The problem is apparently a bug in ffmpeg. I had the problem with ffmpeg 0.4.7, but everything works fine with ffmpeg 0.4.9_pre1. I'm not sure how 0.4.8 is, but it's worth a try.

Time Synchronization

Make sure that you have NTP running. MythTV works best when the clock is properly synchronized. However, there will always be problems with retarded stations, such as Fox, which like to start shows several minutes early for no reason. MythTV has options for a "begin early" and "end late" amount on a show by show basis. It usually works really well, but it takes some paying attention to.

FCE-Ultra Thinks You Have a Joystick

I've had problems with FCE Ultra sometimes thinking I have a joystick. As a game starts up, it flashes "Joystick 2 Selected" at the bottom of the screen. It seems that the problem is that Caps Lock is set.

External Programs Have No Sound

I had a very annoying problem for a while in which Flash (in a web browser) was silent. I use MythGame and MythVideo to start Firefox, and I would frequently want to watch a Flash video like Homestar Runner, only to find that Flash wouldn't play any sound. It turns out that the problem was that both MythTV and Flash were both using OSS audio, but only one of them (MythTV) could have the sound device open at once, due to limitations in OSS. The solution is to use ALSA for MythTV (preferably with dmix enabled).

After Watching One Recording, Watching a Second Recording Causes a Frontend Crash

The almost constant crashing of Mythfrontend was extremely annoying. It would always crash right as a playback of a recording was beginning. The frontend would never die on the first playback, but it would almost die on the second one. After experiencing several dozen crashes a week, it got to be really annoying. A backtrace revealed that the crash was happening in the function _nv000833gl in libGLcore.so.1 in the nVidia driver (version 6629). Unfortunately, I still haven't seen a fix, and I'm not certain whether it's an nVidia problem or a MythTV problem. In any case, I am currently avoiding the problem by using a Mythfrontend with OpenGL disabled.

The Backend Frequently Crashes When Two or More Frontends are Connected

Backend crashes are very annoying. I still haven't found a perfect solution, but I've found that the system is much more stable if all frontends have the exact same version of MythTV as the backend. Never let an old frontend connect to your system. Fortunately, it appears that from about version 0.19, the frontend and backend are implementing version checking.

For More Information