random findings by wt8008
RSS icon Home icon
  • MythTV and XBMC Integration

    Posted on May 28th, 2012 wt8008 No comments

    MythTV’s main purpose is to function as a DVR. XBMC’s purpose is geared towards functioning as a media player—to interface the TV with all media stored on the computer, network, or even the internet. Both are designed with a 10-foot user interface for an HDTV, but XBMC’s interface is more polished. XBMC is cross-platform and is officially available for Linux, Windows, and OSX/ATV.

    XBMC has the basic photo, music, and video viewer just like MythTV, but XBMC’s strength is in its add-on capability. Add-ons extend the functionality of XBMC. Many add-ons reformat website data online and display it directly in XBMC. Examples of add-ons are YouTube, Hulu, Netflix, and podcasts networks. It is also useful for bringing internet-only content to the TV. Official add-ons can be directly downloaded within XBMC. The large XBMC community also provides unofficial add-ons, these add-ons can be found on the XBMC forums. One unofficial add-on is xbmc-addons-chinese, which provides an interface to Chinese websites with flash video and live streaming TV channels. There are also add-ons for other international communities. Some add-ons are platform dependent, if they relay on external supporting applications.

    An official add-on is MythBox which provides can access a MythTV backend. It can replace the main features MythTV’s frontend for watching videos and recordings. Watching live TV is also available, but the interface for changing channels is clunky requiring the on-screen tv guide.

    MythTV Integration

    Currently, I use a combined MythTV frontend/backend setup with Mythwelcome to automatically turn on and off my HTPC for recordings. I am also using LIRC with a remote control.

    A simple way to integrate XBMC into such a setup is to allow the user to launch XBMC directly from the frontend. You can add an XBMC menu entry in MythTV’s menu xml file.

    I am using the media center menu theme, so the corresponding menu xml file is located in /usr/share/mythtv/themes/mediacentermenu/mainmenu.xml

          <description>Launch XBMC</description>
          <action>EXEC /usr/bin/xbmc</action>

    The advantage of launching XBMC from the frontend is that MythTV will stop responding to LIRC commands until XBMC exits. The LIRC daemon will send the key action to both programs, if you were to open them separately.

    LIRC Setup

    To map the LIRC remote commands to XBMC actions, you edit ~/.xbmc/userdata/Lircmap.xml:

         <remote device="LIRC_Remote_Name">

    Smartphones can also function as a remote control using an app. XBMC system settings need to be modified to enable access.

    Final Words

    With the XBMC add-ons, you do not need to record some network shows, because they are available directly in XBMC over Hulu, although the streaming quality is not as good as free OTA broadcasts. For some shows like news, the lower bitrate is acceptable. There are multiple add-ons with link to different US and international TV networks and sites. With the wide selection of add-ons, XBMC is a great addition to an HTPC.

    There is a PPA available with instructions for Ubuntu users.

  • MythTV with SPDIF Digital Sound Output and Passthrough

    Posted on March 24th, 2011 wt8008 No comments

    Most modern motherboards will include a S/PDIF header, but with a soldering iron, one is easily added. This allows for digital audio output from the onboard sound. The next part shows how to configure and test a setup using ALSA tools and mplayer for Linux. Finally, a custom asoundrc configuration is used for MythTV to allow for analog and digital output for stereo streams and digital passthrough for DTS and Dolby Digital encoded audio.

    S/PDIF Connector

    My MythTV system uses the ECS K8T890-A motherboard, it does not contain a S/PDIF header. Upon closer inspection, near the PCI-e slot, you will find that ECS used a Realtek ALC655 for audio output. The datasheet for the ALC655 is publicly available. From the specifications, the ALC655 supports digital output, but ECS did not include headers for it. With a soldering iron, this is a non-issue. The reference design gives a simple circuit consisting of a few capacitors and resistors to allow the ALC655’s output to be interfaced with a S/PDIF compatible receiver. S/PDIF connectors used are typically RCA or BNC. The decision will be based upon what cables and connectors you have available. Cables with characteristics impedance of 75 Ω should be used for best performance. This value is typically used for video coax. Once you have a RCA or BNC pannel/borad mount connector, you need to secure it to the PC chasis. If you have old, unused PCI cards, you can remove their brackets for use. As an example, with a unused Ethernet card, the hole for the Ethernet jack can allow you to glue in a RCA socket.

    From the `Pin Assignments’ section in the datasheet, pin 48 is named SPDIFO. In the `Pin Description’ section it describes the function as “S/PDIF output” which is what is needed. The dot indicates Pin 1 (see the photo below modified from Japanese Wikipedia.) Pin 48 is on the edge of the device and is not a pin in the center, making it easier to perform soldering. (Warranty likely does not allow for user modifications. ;-)) Solder a thin wire such as 30 AWG to the pin. Make sure the wire is long enough to reach the PC case. Tug on the wire to verify the solder joint; the wire should not break off. Next the wire needs to be secured, as the solder joint cannot handle stress. Glue the wire about 1 inch away from the ALC655 to the motherboard edge; hot glue will work for this application.


    Next, secure with hot glue the RCA socket to the Ethernet back plate. Solder on the circuit from the design guide directly on the back of the RCA socket pins. Finally, solder the glued wire to the input of the circuit. Remember the solder a ground connection, the ground connection is the metal of the back plate itself. Now, connect a 75 Ω cable between the computer and the device.

    Linux Setup

    Now to properly configure the digital output and test it using mplayer.

    In alsamixer(1) verify that IEC958 output is not muted. Use the hotkey `M’ to unmute it. The value should read “MM” when muted, and “00” when enabled. Now lets review what devices are available on the system with:

    aplay -l

    the output is

    [email protected]:~$ aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: V8237 [VIA 8237], device 0: VIA 8237 [VIA 8237]
      Subdevices: 4/4
      Subdevice #0: subdevice #0
      Subdevice #1: subdevice #1
      Subdevice #2: subdevice #2
      Subdevice #3: subdevice #3
    card 0: V8237 [VIA 8237], device 1: VIA 8237 [VIA 8237]
      Subdevices: 1/1
      Subdevice #0: subdevice #0

    With only one sound card, they should be all listed as card 0. Also, note that I have 4 subdevices. Some users will see an analog and digital device here. (I do not so the configuration file in the next section differs.) Next, view the ALSA names for the sound devices on your system with

    aplay -L

    the output is

    [email protected]:~$ aplay -L
        Discard all samples (playback) or generate zero samples (capture)
        Playback/recording through the PulseAudio sound server
        VIA 8237, VIA 8237
        Front speakers
        VIA 8237, VIA 8237
        4.0 Surround output to Front and Rear speakers
        VIA 8237, VIA 8237
        4.1 Surround output to Front, Rear and Subwoofer speakers
        VIA 8237, VIA 8237
        5.0 Surround output to Front, Center and Rear speakers
        VIA 8237, VIA 8237
        5.1 Surround output to Front, Center, Rear and Subwoofer speakers
        VIA 8237, VIA 8237
        IEC958 (S/PDIF) Digital Audio Output

    You should see a iec958 or spdif device here.

    Use mplayer(1) to output via S/PDIF by manually selecting it on the command line with:

    mplayer -vo none -ao alsa:device=iec958 filename

    where -vo is no video out device, -ao alsa:device=iec958 is the audio out device by using the alsa audio driver, and device name is from the ones given in aplay -L. The sound should only output from the digital port. You can test files with encoded DTS audio or Dolby Digital audio by using

    mplayer -vo none -ao alsa:device=iec958 -ac hwdts,hwac3 filename

    This allows for directly passing the encoded audio signal to your receiver, the software will do no decoding. You should be able to get bit perfect surround sound.

    MythTV Audio Settings

    To always use digital output, go to
    Utilities/Setup -> General -> Audio page
    and use the following settings:

     Audio output device:         ALSA:iec958
     Digital Audio Capabilities
         Dolby Digital            check
         DTS                      check

    Digital Output

    Note the name of the device `iec958′ matches the output of aplay -L and mplayer.

    On the next page,

     Use internal volume controls      uncheck

    Internal Mixer Setting

    If this is not unchecked, then the system will decode and re-encode the DTS/Dolby Digital audio as PCM.

    The system is then setup to always output a digital signal.

    MythTV Setup for Dual, Analog and Digital, Outputs

    If the audio source was not DTS or Dolby Digital encoded, then you can output both to the digital and analog outputs with a custom .asoundrc configuration by creating a virtual device that maps the left and right audio channels. If the audio source was DTS or Dolby Digital encoded, only the digital output is available. (MythTV only can output one audio stream.)

    A custom .asoundrc is needed.

    # ~/.asoundrc or /etc/asound.conf
    # ALSA configuration file
    ##### USAGE #####
    # Save this file as "~/.asoundrc" (for user-specific sound configuration) or
    # "/etc/asound.conf" (for system-wide sound configuration) and specify ALSA
    # device names ad described in the next section.
    ##### IMPORTANT #####
    # To make this ALSA configuration file work with your sound card, you will need
    # to define the appropriate card and device information for the "analog-hw" and
    # "digital-hw" devices below.  You can find the card and device information
    # using "aplay -l".
    # Default output device
    pcm.!default {
      type plug
      slave {
        pcm dualout
    ##### Configuration File #####
    # Override the default output used by ALSA.  If you do not override the
    # default, your default device is identical to the (unmixed) "analog" device
    # shown below.  If you prefer mixed and/or digital output, uncomment the
    # appropriate four lines below (only one slave.pcm line).
    # Alias for device names
    # Actual device name usable for applications
    pcm.dualout {
        type plug
        slave.pcm "dual"
        hint {
            show on
            description "Output to analog and digital ports"
    ctl.dualout {
        type hw
        card 0
    # The following devices are not useful by themselves.  They require specific
    # rates, channels, and formats.  Therefore, you probably do not want to use
    # them directly.  Instead use of of the devices defined above.
    # Alias for analog output on the card
    # Do not use this directly--it requires specific rate, channels, and format
    pcm.analog-hw {
      type hw
      card 0     # MODIFY to match your setup
     # The default value for device is 0, so no need to specify
    #  - Uncomment one of the below or create a new "device N" line as appropriate
    #    for your sound card
    #  device 1
    #  device 4
    # Control device (mixer, etc.) for the card
    ctl.analog-hw {
      type hw
      card 0
    # Alias for digital (S/PDIF) output on the card
    # Do not use this directly--it requires specific rate, channels, and format
    pcm.digital-hw {
      type hw
      card 0
      device 0    # MODIFY to match your setup
      subdevice 3 # MODIFY to match your setup
                  #  Remove this if not needed (many won't need this line)
    #  - Comment out "device 1" above and uncomment one of the below or create a
    #    new "device N" line as appropriate for your sound card
    #  device 2
    #  device 4
    # Control device (mixer, etc.) for the card
    ctl.digital-hw {
      type hw
      card 0
    # multi -- a virtual device with four channels. This maps two stero streams
    # from the analog and digital outputs as one 4-channel stream. (Complex format)
    pcm.multi {
      type multi
      slaves.a.pcm "analog-hw"
      slaves.a.channels 2
      slaves.b.pcm "digital-hw"
      slaves.b.channels 2
      bindings.0.slave a
      bindings.0.channel 0
      bindings.1.slave a
      bindings.1.channel 1
      bindings.2.slave b
      bindings.2.channel 0
      bindings.3.slave b
      bindings.3.channel 1
    ctl.multi {
      type hw
      card 0
    # dual -- creates a 4 channel pcm stream based on the multi device. Maps this
    # devices 4 streams to the multi device. (Interleaved format, supported by most
    # applications)
    pcm.dual {
        type route
        slave.pcm "multi"
        slave.channels 4
        ttable.0.0 1
        ttable.1.1 1
        ttable.0.2 1
        ttable.1.3 1
    ctl.dual {
        type hw
        card 0

    This defines a name for the analog and digital output device. Next, it creates a virtual 4 channel device and maps the analog and digital audio channels to it. Finally, an interleaved format device is created for MythTV’s usage.

    The pcm.analog-hw block defines the exact card and device of your analog output. Typically this is card 0 and device 0. Verify the card and device indices with mplayer(1):

    mplayer -ao alsa:device=hw0.0 filename

    The expected output is sound from your speakers connected to the analog outputs. Similarly, for the pcm.digital-hw block, find the exact card and device (and possibly subdevice) with

    mplayer -ao alsa:device=hw0.0.3 filename

    My IEC958 device is located on card: 0, device 0, subdevice 3. Use the process of elimination to determine the exact index of the device. Modify the corresponding section of the configuration file with the card, device, and subdevice index.

    The other pcm.multi, pcm.dualout, and pcm.dual do not need to be modified as they only preform channel mapping. In MythTV, configure the default output device to be ALSA:dualout. (`Scan for audio devices’ feature only detects “type plug”.)

    Analog Digital Output

    Stereo analog and stereo sound should output for 2 channel audio sources. For audio encoded in DTS or Dolby Digital, your receive should receive the raw data and preform the decoding.


  • HDHomerun, Comcast QAM, MythTV

    Posted on September 4th, 2010 wt8008 2 comments

    With my new HDHomeRun, I need to setup MythTV backend to get channels from Comcast unencrypted QAM.Mythbuntu comes preinstalled with the hdhomerun_config command line and GUI tools, under Applications->Multimedia->HDHomeRun Config GUI. If it is plugged in the “Scan” button will discover any tuners on the network. Also, if you plug different sources into HDHomeRun, such as Cable and OTA, note the tuner numbers for later reference. If you have dual tuners you will have two entries. From there, you can flip through the channels and view what streams exist under that channel. With the “View” button VLC will open and play the video stream.

    HDHomeRun Config GUI

    HDHomeRun Config GUI

    The device ID of your HDHomeRun can be found by

    $ hdhomerun_config discover

    The output will look like

    hdhomerun device XXXXXXXX found at Y.Y.Y.Y

    where the XXXXXXXX represents the HDHomeRun ID, and Y.Y.Y.Y is the IP address. You should note the ID for use later on.

    Channel Scanning

    Integrating into Mythtv is not as direct as I hoped. The scanner built into Mythtv 0.23 does not handle the Comcast QAM stream properly. It can scan the channels, but it cannot use the virtual channel numbers from Comcast, and Mythtv will results in many conflicting channel numbers. Follow the guide at http://www.mythtv.org/wiki/Scte65scan to use scte65scan to scan and discover the virtual channel numbers. The rough procedure from the wiki is below:

    1. Run mythtv-setup to configure the backend.
    2. Setup section 1: General, and section 2: Video sources. Do not setup the other sections (or else the database dump of scte65scan will not work, maybe using -f4 as a command line option is a workaround and also default sourceid=1 , not tested or tried yet.)
    3. Download scte65scan source and HDHomerun libraries, follow the instructions to compile and for editing the HDHomrun Makefile.
    4. The VCT_ID for my area is 3065 (0x0bf9), after following the instructions on the wiki to discover them (the scan takes a few minutes):

    $ ./scte65scan -H FFFFFFFF us-Cable-Standard-center-frequencies-QAM256

    5. Now the SQL script will be generated to be used to import into Mythtv.

    $ ./scte65scan -H XXXXXXXX,0 -p -f3 -V 3065 us-Cable-Standard-center-frequencies-QAM256 > vct.sql

    Recall XXXXXXXX is the HDHomeRun ID, the 0 after it represents the tuner number, -p option is needed for the local PSIP channels in the cable stream, -f3 for SQL install script, -V 3065 where 3065 is my local areas VCT_ID, us-Cable-Standard…. is a file containing the channel frequencies that will be scanned, and finally vct.sql is the output SQL script. Read

    $ scte65scan --help

    for more details.

    6. Next import the output to the SQL database

    $ mysql -u mythtv -p mythconverg < vct.sql

    This allows you to access the mythconverg database as the mythtv user, but remember to lookup the database password in the Mythtv frontend before you proceed. The other method is to logon as -u root, if you remember the initial password you setup for it. If you get an error regarding

    ERROR 1062 (2300) at line 4: Duplicate entry '1' for key 'PRIMARY'

    it is due already having video sources defined, you can either delete them, or try different -f options in

    $ scte65scan --help

    7. The channel information entered is viewable in the backend setup under 5. Channel Editor. Continue with the setup by adding the 3. Video Source, and the channels should populate without a scan. Also setup the 4. Input connections.

    The channel scanner for OTA signals works fine, so you can use the internal scanner for that purpose.

    Inferred Sensor

    Using the inferred sensor on the HDHomeRun requires telling the device to forwards the signals to the backend, using lircd on the backend to process the signals into keys, and having mythtv map the remote key presses to keyboard shortcuts.

    The HDHomeRun site has a guide for setting up the HDHomeRun.

    $ hdhomerun_config  <device id> set /ir/target "<backend-ip>:5000 store"

    The store command saves the setting into flash, so on reboot of the tuner, it will continue to foward the IR commands. Next, use irrecord to let the computer learn each key of the remote.

    $ irrecord -H udp -d 5000 "<name of remote>"

    Attempt to give generic/general key names, since later a parser will be used to generate the key maps to Mythtv. Copy the resulting file,

    # sudo mv "<name of remote>" /etc/lirc/lircd.conf

    Now to start up lircd the first time, I recommend using verbose mode to watch what happens.

    # sudo lircd -n -H udp -d 5000

    Use irw to test the setup. With irw running press remotes on the key and it will print out the corresponding key that is pressed. If all is well then configure the /etc/lirc/hardware.conf file. Some recommended settings


    Now, setup the key mapping between lirc and MythTV, Mythbuntu users can use

    $ mythbuntu-lirc-generator

    This will parse the keynames in /etc/lirc/lircd.conf and guess a corresponding key/function in MythTV. Next, manually edit the generated file

    $ vim ~/.lirc/mythtv

    Custom mappings or unmaps keys needs to be manually added in. The format is

      remote = "<name of remote>"
      prog = mythtv
      button = CHUP
      config = Page Up  
      delay = 0
      repeat = 0
  • Mythtv Remote udev Rules

    Posted on March 22nd, 2009 wt8008 No comments

    I was looking at setting some udev rules for my remote for mythtv, so that if I change the input devices (i.e. add or remove a mouse/keyboard), I want the name of the device to be constant so that I do not need to modify my lirc configuration files.

    I tried to setup this before, when I first setup mythtv (see my earlier mythtv post), but I never got it to work. There were two issues, one is that the filename for the rules was wrong, and also I had issues with the rules themselves. Anyways here is how you do it…

    This is my complete /etc/udev/rules.d/10-localremote.rules file

    KERNEL=="event*",ATTRS{name}=="saa7134 IR (Avermedia AVerTV GO",SYMLINK="input/irremote"

    This will link /dev/input/irremote to the device that is associated with my tv tuner’s IR receiver.

    [email protected]:/dev/input$ ls -l irremote
    lrwxrwxrwx 1 root root 6 2009-03-22 15:06 irremote -> event3

    Right now, it points to event3, but if I plug in my mouse and keyboard irremote will then point to event5.

    The associated file /etc/lirc/hardware.conf should also have the REMOTE_DEVICE field point to the new device.

    There is some way to setup the remote using hal, but I will give that a try another day. See http://www.doctort.org/adam/general/update-on-twinhan-remote-for-mythbuntu-810.html I will give that a try another day.

  • Mythtv Box with HDTV Support

    Posted on October 5th, 2008 wt8008 No comments

    Last month, I completed building a Mythbuntu box with HDTV support. I also have analog support, but who would want to watch TV on that, so I didn’t bother setting that part up. Anyway here is the hardware setup:

    • CPU: Athlon XP 3000+ (from the top of my head Runs at 2.25 GHz)
    • RAM: 1GB
    • HD: 750GB
    • Video card: PNY Geforce 6600gt
    • TV Tuner
      • HDTV: Air2PC rev 2
      • NTSC: Avermedia AverTV Go 007 FM Plus

    The CPU recommended for single core processors are P4 3.0GHz or equivalent for HDTV playback. With only using the CPU alone my computer was able to play back HDTV video, but it was not smooth. A way around this (but not recommended by the community because of issues with using this) is with XvMC, which allows X to use the video card’s processor to accelerate playback. Only the 5000-7000 series close source drivers from Nvidia have the support for XvMC, and also only the 5000 series support color OSD during playback. The menus are in color, but any item that displays on top of the video is in grayscale with XvMC.

    My system was used as as frontend and backend. For HDTV the backend just writes a digital stream to the HD so this does not strain the system. For analog TV, if the tuner did not have hardware encoding the CPU would have to do the lifting, thus the CPU would have to do more work. A seperate backend would help for commercial tagging.

    The video card has S-video, composite, and component video out, along with the standard DVI and VGA (via an adaptor). The HDTV we have that the HTPC is hooked to does not contain any other HD inputs besides component video. My xorg.conf file is located at the end of the post for 1080i output.

    The video settings I have is to have video above 720p and 1080i to play back using XvMC, and for lower resolutions to use ffmpeg. This allows me to smoothly playback HDTV (but there is still another issue), and have color OSD for lower resolutions.

    If I were to use the Avermedia tuner, it is will be detected by the kernel automatically. My Avermedia card came with a remote, so I am using the remote that came with that tv tuner to control Mythtv and mplayer. The infered port should be detected and be under /dev/input/event*. By using the command `cat /proc/bus/input/devices’, you can find the module that goes with the remote. Note that when mice, keyboards, or other input devices are added to the system, the device location may change without udev rules. I have generated a lircd.conf file for my remote. By using the mythbuntu-control-centre, you can setup the remote to use the devinput driver, proper device, and link to the lircd.conf file. Under the users home folder in ~/.lirc/mythtv, the file maps the buttons from the remote file (lircd.conf) to mythtv commands. Both files will be located at the end of this post.

    The Air2PC card requires a firmware file (dvb-fe-bcm3510-01.fw) to be downloaded and placed in /lib/firmware for the kernel to properly use the card. In dmesg output, you will see that the firmware is sucessfully loaded upon boot.


    • Using XvMC with OSD is in grayscale and causes the video playback to shutter. When the OSD timesout video playback resumes smoothly.
    • EIT: The electronic programming guide transmitted through the air by the TV stations, sometimes stop over each other. For example, Channel’s 5 programming data will also appear in Channel’s 4 slot. I later found out there is a setting for each channel to allow EIT programming to be disabled on each channel.

    Testing ATSC Card via Commandline

    The dvb-utils package in Ubuntu has utlities for scanning for channels. This will install the scan utilty which will look for channels, it is ran by

    scan /usr/share/dvb/atsc/us-ATSC-center-frequencies-8VSB > channels.conf

    It will save the results of the scan in channels.conf. Some programs, like mplayer use this file for viewing tv. Run mplayer to view TV

    mplayer dvb://

    Now with the tv verfied to be working.

    Setup Mythtv Backend

    1. General Settings
    2. Capture Card
      1. Card Type: DVB DTV capture card for ATSC tuner; NTSC card is Analog V4L capture card – audio alsa:1,0 (or /dev/dsp1) audio sampling limit maybe 32000
    3. Video Source – setup scanning frequncies, and listing grabbers
    4. Input Connections – map a capture card to a video source, also scan for channels in here
    5. Channel Editor – easier to edit with the Mythweb plugin http://mythtvboxhostname/mythweb
    6. Storage Directory – for recordings

    Setup Mythtv Frontend
    Utilities/Setup -> Setup


    • output and mixer device ALSA:default
    • mixer control PCM, so that i can have the master volume at 95%


    • Screen Settings – my tv requires
      • GUI width: 1730
      • GUI height: 1025
      • GUI X offset: 80
      • GUI Y offset: 35
    • Font sizes: Small – 12, Mediu – 16, Big – 25

    TV Settings

    1. General
    2. Program Guide: Eco – Transparent
    3. Playback
    4. Playback OSD
    5. Playback Groups
      • Live TV for v4l can support up to 640 x 480
      • Enable realtime priority threads – need to edit the RTC of the kernel
      • Enable extra audio buffering – without this causes studdering issues on HDTV
      • Disable OpenGL vertical sync for timing – does not properly work for me
    6. Playback profiles:
      • if rez >= 1280 720 -> XvMC-opengl
        • Deinterlace: None or Box (2x) (if a patched is applied and complied in)
      • if rez > 0 0 -> ffmpeg & Xvideo
        • Deinterlace: Kernel
      • Sticky keys and smart fast forwarding settings located here
      • Commerical Skip settings
      • Recording Priorities

    Other settings are for Mythvideo, which is not as complex as setting up the tv part, so that has been omitted.


    • hardware.conf – goes under /etc/lirc/ remote dev
    • lircd.conf – goes under /etc/lirc/ remote control keys
    • mplayer – goes under ~/.lirc matches remote keys to mplayer options
    • mythtv – goes under ~/.lirc maps remote keys to mythtv options
    • xorg.conf