MythTV

= Introduction =

XBMC Media Center includes a media source that can communicate with a MythTV backend allowing you to:
 * Navigate All Recordings, Movies and TV Shows separately - standard XBMC navigation grouped in a sensible way.
 * Playback recordings with automatic commercial skip - automatic commercial skip during playback that works as you expect with no fuss. Advanced options to help merge poorly flagged commercial breaks as well.
 * Add recorded Movies to the XBMC library - integrate your recorded Movies in MythTV with all your other movies so you can see them all in one place. Standard XBMC functionality with scrapers supported.
 * Watch and pause Live TV with direct channel navigation - change up or down channel with a single button press, or choose a channel number using the remote keypad.
 * Look at electronic program guide (EPG) - to see what is coming up on each channel
 * Delete recorded programs after watching - one place to watch and delete recorded programs

XBMC Media Center is focused on playback of MythTV recordings. You need to schedule recordings using mythfrontend or mythweb.

All versions of MythTV are supported, including 0.22.

The functionality described on this page is for the 9.11 Camelot release of XBMC.

What is MythTV
MythTV is a digital video recorder for watching and recording television. MythTV also contains plugins for viewing other home media, similar to what XBMC Media Center provides. MythTV is like a free open source alternative to Tivo and Windows Media Center.

Some of MythTV's features include:
 * Watch and record analog and/or digital TV, including HDTV.
 * Pause, skip, and rewind live TV shows.
 * Completely automatic commercial detection/skipping, with manual correction via an intuitive cutlist editor.
 * Intelligently schedules recordings to avoid conflicts.
 * Parental controls to keep your kids out of the good shows.
 * Schedule and administer many functions remotely via a web browser.
 * Flexible client/server architecture allows multiple frontend client machines to access content served by one or more backend servers (although the most common installation consists of a single computer running both the client and server together).

This wiki page doesn't contain any information about how to install, setup or configure MythTV. If you need further information about how best to do this, Mythbuntu is a good place to start. Mythbuntu is an community supported add-on for Ubuntu focused upon setting up a standalone MythTV based PVR system.

= Setup =

XBMC communicates with mythbackend using the Myth Protocol and MySQL database queries to the mythconverg database. This requires that the MythTV configuration is checked to ensure XBMC will be able to communicate with MythTV, which depends on whether XBMC is running on the same machine.

Setup in MythTV
If XBMC Media Center and the MythTV backend will NOT be running on the same machine:


 * Check that the IP Address configured in MythTV can be accessed by the XBMC machine. The default IP Address for an installation of MythTV is 127.0.0.1 and must be changed so playback will work
 * 1) Run mythtv-setup
 * 2) Select General
 * 3) Check that the IP Address in Local Backend section is NOT set to localhost or 127.0.0.1. The IP Address must be resolvable from the XBMC Media Center machine, e.g. 192.168.1.3.
 * Check that the MySQL database being used by MythTV has been configured to allow external connections.
 * Generally this means ensuring that the bind-address is not set to localhost or 127.0.0.1 in /etc/mysql/mysql.cnf or one of the *.cnf files in /etc/mysql/conf.d/.
 * Check that the username configured in the myth:// URL has access to the mythconverg database from external locations.

To ensure XBMC has proper access to the MythTV mysql database, run the following commands on the mysql server. Replace PASSWORD or xbmc with whatever you prefer, but keep the single quotes for syntax.

It is very important that the IP Address is set correctly using mythtv-setup. The Myth Protocol used by XBMC Media Center uses the IP Address configured in the Myth TV backend to determine where to stream the recordings from. So, even if the IP address in the myth:// URL points correctly to the MythTV backend, there can still be playback problems if the correct IP Address isn't also set correctly using mythtv-setup.

If you don't intend on using the Guide then the MySQL related configuration can be omitted. Access to the mythconverg MySQL database is only used to view the Guide.

Setup in XBMC
To communicate with a MythTV backend, add a new Source from the Videos section. This URL needs to be specified manually as many skins don't support the ability to configure a MythTV source. The source should have a URL that looks like:

myth://username:password@i.p.address

username and password are the credentials for a user that has access to the MySQL mythconverg database on the MythTV backend. The username and password supplied in the URL are used to obtain EPG information from the MythTV database when using the Guide. If the username and password are not supplied a default of mythtv is used for both. The username and password are not used when watching recordings.

i.p.address is the IP address of the MythTV master server. A hostname can also be used, but it must be resolvable to an IP address on the XBMC Media Center machine.

When you select the newly added MythTV media source five folders will be listed:
 * All Recordings - to watch anything that has been recorded all in one folder.
 * Guide - to view the EPG for a channel
 * Live Channels - to display what is currently being aired
 * Movies - to list the movies that have been recorded
 * TV Shows - to list each series of TV shows that have been recorded



= Watching Recorded Programs =

All Recordings
After choosing All Recordings a list of all recorded programs is presented. Standard XBMC functionality can be used to sort by date to see the most recent recordings, or sort by name to get all the shows from a given series grouped together.



Movies
After choosing Movies a list of all the recorded movies is shown.



If not all of the movies are shown, e.g. some still display in the TV Shows section, the Electronic Program Guide (EPG) being used by MythTV might not be very accurate. The EPG describes which programs are Movies and which are TV Shows. Use the  advanced setting to help with this problem. 85 minutes seems to work well.

TV Shows
After choosing TV Shows a list of all the recorded TV shows grouped by title is shown. This makes it easy to see what TV series or one-off programs have been recorded.

TODO: Update image.

After choosing a title, the list of recorded programs with that title is shown.

TODO: Update image.

= Watching Live TV =

After choosing Live Channels a listing of the channels used by MythTV is displayed.

When a channel is chosen, the currently playing TV show on that channel is shown.

It is possible to pause Live TV, but it is not possible to skip. files To move up or down a channel when playing Live TV press the PageUp or PageDown button. Note that channel changes can take some time depending on the tuner hardware and configuration being used by MythTV.

= Viewing the Electronic Program Guide (EPG) =

After choosing Guide a listing of channels used by MythTV is shown.



When a channel is chosen, the listing of upcoming programs on that channel is displayed.



There is a future project to be able to schedule programs to record from the EPG similar to the functionality available in the MythTV frontend.

= Adding Recorded Movies to the Video Library =

Recorded movies can be added to the XBMC Video Library by setting the Content Type on the Movies directory and then choosing the appropriate Movie scraper.

Once the recorded Movies have been scanned to the Library, you can see and play them via the XBMC Video Library.

= Automatic Commercial Skipping =

Commercial breaks that have been flagged in MythTV are automatically skipped as of the 9.11 release (note that the option to turn EDL support on/off has now been removed). Prior to 9.11, automatic commercial skipping can be enabled by turning on Edit Decision List (EDL) support in XBMC Media Center through Settings -> Video -> Player -> Enable edit decision lists.

Each commercial break is only skipped once so it's possible to go back into any incorrectly flagged commercial break. Scene markers are also put in at the beginning and end of the flagged commercial breaks to further support navigation.

If an incorrectly flagged commercial break is skipped, pressing "Left" (small skip backwards) or "Down" (big skip backwards) within 10 seconds will jump back to the start of the commercial break. Additionally, if a commercial break isn't flagged early enough, pressing "Right" (small skip forward) or "Up" (big skip forward) will go to the end of the next flagged commercial break (technically the skip should land in the commercial break and is then automatically skipped).

When you press "o" (to display the information OSD) the "edl: c4s8" portion identifies how many commercial breaks were flagged. "edl: c4s8" means there are 4 commercial breaks and 8 scene markers. If "edl: -" is displayed there were no commercial breaks flagged.

The advanced settings can be used to merge commercial breaks that haven't been detected accurately, and to remove commercial breaks that are identified outside of a likely set of commercial breaks.

= Deleting Recorded Programs =

The ability to delete recorded programs can be enabled through Settings -> Appearance -> View Options -> Allow file renaming and deletion.

= Known Problems =


 * Need to delete a recording twice for it to be removed if using a MythTV 0.20 backend. Deleting works as expected using a MythTV 0.21 backend.
 * Channel changes can take some time when using LiveTV.

= Trouble Shooting =

Recordings Don't Play
For the myth:// protocol to play recordings, XBMC must be able to access the IP Address configured in the MythTV backend using mythtv-setup. This is necessary because of the way the Myth Protocol works. The Myth API gets the IP Address configured in the MythTV backend and uses that to stream recordings.

If a hostname was used in the IP Address configuration for the MythTV Local Backend, either the DNS server on the network needs to be able to resolve the hostname to an IP address, or a static hostname to IP address entry is needed on the XBMC machine. A static IP address mapping can be set in the /etc/hosts file in Linux or Mac OSX, or in the AdvancedSettings.xml file for the original XBox.

Double check that the Local Backend IP Address configured in the MythTV backend is not set to localhost or 127.0.0.1 if the MythTV backend is running on a different machine to XBMC Media Center.

Guide Doesn't Display Anything
Check that the username and password supplied in the myth:// URL are a username and password that have access to the mythconverg MySQL database. The guide information is obtained directly from the database.

If a username and password have not been supplied in the myth:// URL then the default of 'mythtv' will be used for both.

See Setup in XBMC for more information.

Live TV Doesn't Play
The libcmyth library used for to connect to MythTV from XBMC only enumerates the first 16 tuner devices when looking for available tuners. Trac - CMyth only enumerates 17 tuners

Depending on what was done when the MythTV backend was setup, it's possible that some Tuner ID's are > 17 in the mythconverg database (especially if tuners were added and deleted several times, or if multiplexing is being used for digital terrestrial tuners).

If this is the case, you may be able to see the Guide and all the stations displayed in XBMC, but XBMC may not be able to select a tuner for live TV playback.

This can be resolved by removing all the tuners through mythtv-setup (so they start at 0 when re-added), and then re-adding them, or reducing the number of multiplexed virtual tuners that are created for each physical digital terrestrial tuner.

If a only a green screen displayed but the audio is working fine. Use mythtv's frontend to change the encoder to mpeg4. The settings can be found in "Utilites/Setup- Setup - TV Settings - Recording Profiles - Software Encoders. Select Live TV, and change it's encoder from rtjpeg to mpeg4.

Audio Plays Out of Sync
If CPU utilization is close to 100% on any of the CPU cores then there could be audio sync problems.

Depending on the video card and driver being used, there could be significant CPU utilized when playing H264 video content. The advanced setting can be used to reduce the CPU utilization by reducing the quality of the output H264 video. Try setting it to 48.

= History of MythTV support in XBMC =

MythTV support in XBMC has been available since ~2004. It started life as a Python script for the original XBox that had functionality added by willing developers over the following years. Eventually the script moved to the current home at Sourceforge, and is now called xbmcmythtv. In late 2008 another script based solution arrived called MythBox.

In 2007 support for communicating with the MythTV backend was added directly to XBMC via a Source using the myth:// protocol. This project uses the cmyth library, which was built to use the network based Myth Protocol supported by MythTV.

In 2009 it is hoped that the Google Summer of Code - Unified PVR Frontend project will be available and provide added functionality to the existing myth:// protocol support. More information about the PVR project can be found in the very large MythTV frontend client built into XBMC forum thread.

myth:// Source
The myth:// source was released in early 2007. This project uses the network based Myth Protocol to communicate with the MythTV backend. It also accesses the MySQL database directly to get Guide information.

Although the myth:// source doesn't support all the functionality that the xbmcmythtv script supported, it is possible to play recordings, which is all many XBMC frontend systems need to support.

The native MythTV frontend client needs to be used to schedule recordings.

MythTV Python Scripts for XBMC
MythTV Python Scripts for XBMC that provide a python coded GUI for MythTV interface.

MythBox Script (Linux/Mac/Windows)
MythBox was released in late 2008 and is a XBMC script for MythTV that supports:
 * Watching recordings with commercial skipping
 * Watching Live TV
 * Scheduling recordings (create and edit)
 * TV Guide
 * MythTV 0.21 and 0.22 (trunk) backends

The code for MythBox was initially forked from the xbmcmythtv script.

Myth2XBMC Script (Xbox)
Myth2XBMC heavily based on the original xbmcmythtv script and is only tested on the Xbox.

xbmcmythtv Script (Xbox)
Support for MythTV in XBMC started with this xbmcmythtv python script for XBMC on the Xbox. This project communicated with the MythTV mythconverg MySQL database to get information, and played recordings via a Samba share on the MythTV backend.

The last official release of the Python script was in May 2007 and supported version 0.20 of MythTV and protocol 34. Various unofficial releases were made available by some of the developers of xbmcmythtv, but appears to no longer be supported on an ongoing basis.

MythicalLibrarian and MythSExx
MythicalLibrarian and MythSExx are bash scripts which can be run on the MythTV server to create symlinks to the recorded files. The symlinks use the supported XBMC naming conventions so the standard filesystem scrapers can be used to scan recorded MythTV content into the XBMC Movie and TV Show libraries. They also generate the required EDL files to support commercial skip during playback.

MythicalLibrarian handles both TV episodes and Movies whereas MythSExx only handles TV episodes.

Unified PVR Frontend
The future for integrated MythTV support in XBMC is based on the unified PVR frontend support that is envisaged for XBMC Media Center.

Much more information can be found in the Google Summer of Code - Unified PVR Frontend wiki page. MythTV is being used as one of the first PVR backends that will be supported, with the intention of XBMC being able to communicate with any PVR backend through clients for the new PVR addons API.

Note that the vision does not include XBMC providing native support for digital video recorder (DVR) capabilities. Rather the vision is to leverage the significant amount of existing open source effort that has been put into this area by providing a slick frontend interface.

= External Links =


 * mythtv.org - MythTV official website
 * http://en.wikipedia.org/wiki/MythTV
 * mythbuntu.org - Mythbuntu official website, a Linux distro with MythTV preconfigured
 * http://en.wikipedia.org/wiki/Mythbuntu
 * Walkthrough on how to configure XBMC for MythTV support, including skin modification for episode information, and EventGhost remote control support.