Running MythTV Dual Headed

From MythTV Official Wiki
Jump to: navigation, search

This little 'HowTo' lets you run two instances of Myth on the same machine.

There are many ways of using 2 screens - this just addresses one way - feel free to add more...


I use this because I have a TV and a projector connected to my Myth box. It could work for people who want to play games on an accelerated VGA display and watch TV on a PVR350.

How (Two X servers, one active at a time)

Linux is a multi-user OS - so you simply create a second myth user and use it to run mythfrontend.

I end up with 1 instance of mythfrontend running through my PVR350 to my TV (accessed through Virtual Terminal 7) and another running through my NVidia card to my projector (on VT-8).

(Note: You can have X just clone to both displays at the same time, and just power up the projector when you want to use it, but that is outside the scope of this HowTo)

So first create a new user (I used mythbig)

Logging In

Here's the /etc/init.d/ script I use

#! /bin/sh
# Originally based on:
# Version:      @(#)skeleton  1.8  03-Mar-1998
# Modified for projector David Greaves 12/Jul/04

set -e


case "$1" in
        chvt 8
        nohup su - mythbig /home/mythbig/runx >>/var/log/projector.log 2>&1 &
        echo "Usage: /etc/init.d/projector {start|stop}"
        exit 1

exit 0

(chvt is a fantastic command - possibly worth putting in your .lirc file)

Starting X

You'll notice it calls a script : runx it's only a 2 line script:

 export QT_XFT=1
 xinit  -- :1 -layout Projector

But notice it uses

:1 to create a new X display (as in the DISPLAY variable - the normal one is hostname:0.0 - this one will be hostname:1.0) and
-layout - this corresponds to a LayoutSection in your XF86Config-4 confg (see later)

Now we need an .xinitrc file. This is like a .profile for X and it contains commands that are run when X starts:

 xsetroot -solid black
 xhost +
 nvidia-settings -l --assign="[[Sync To V Blank]]=1"
 mythfrontend -v &

When the last command finishes, X stops. I don't have this set to continually restart but you could easily do so.

Configuring X

OK, the infamous XF86Config-4...

This is a bit more complex but not a lot. You need to realise that this file contains lots of little sections. Not all of them are used all the time. Normally X looks for the first 'ServerLayout' and then looks to see what other sections are referred to. It keeps doing this down through Screens, Monitors, Devices, InputDevices etc etc. So here the first ServerLayout is used by default, the second (which refers to a different screen which in turn refers to the MonitorSection called Projector and the Nvidia Device) is what we specify by name back in runx:

Section "[[Server Layout]]"
       Identifier     "TV"
       Screen      0  "TV"
       [[Input Device]]    "Keyboard0" "[[Core Keyboard]]"
       [[Input Device]]    "PS/2 Mouse" "[[Core Pointer]]"
       Option "Xinerama" "off"
[[End Section]]

Section "[[Server Layout]]"
       Identifier     "Projector"
       Screen      0  "[[Proj Screen]]"
       Option          "Xinerama"      "off"
       Option          "[[Allow Mouse Open Fail]]"
       [[Input Device]]    "PS/2 Mouse" "[[Core Pointer]]"
       [[Input Device]]    "Keyboard0" "[[Core Keyboard]]"
[[End Section]]

Configuring Myth

Myth uses a .myth directory in the users home directory. In there is a file called mysql.txt which tells mythfrontend where to get all it's settings from. Now Myth stores this information on a per-hostname basis - so we need to tell a white lie. Here's what mine looks like:

[[D B Host Name]]=localhost
[[D B User Name]]=mythtv

# Set the following if you want to use something other than the
# machine's real hostname for identifying settings in the database.
# This is useful if your hostname changes often, as otherwise
# you'll need to reconfigure mythtv (or futz with the DB) every time.
[[Local Host Name]]=bao-projector

The 'LocalHostName' value is the one you care about, and as the comment says, it must be unique.

All Done

Now you can easily switch (ctrl-alt-F<x>) between TV and VGA screens.

On word of caution: you may have problems sharing the sound/dsp device if you switch whilst it's in use)

Hope this helps

--David Greaves

Lazy Man Commercial Solution

I run mythfrontend on a Groovix linux system. The main console is used by the family for day to day stuff (email etc.) The secondary console is used for mythtv. I'd say it works quite well and was a lot less work than setting it up myself.

-- Matt Welland

One X server, two displays (non-xinerama method)

I have a similar setup with TV and projector, but instead of running two X servers I run one X server with two displays. I only run one instance of mythfrontend at once and so don't need to create another user.

This has the advantage that both displays can be used at the same time - one will show myth's gui or video whilst the other can be used for other X applications at the same time. My usual scripts start up a cpu-temperature monitor (xsensors) and an xterm from which I can launch vncviewer, firefox etc. whilst mythtv is still doing its business on the other screen.
The mouse pointer moves across the two screens - although it can be hidden in myth's GUI so it doesn't get in the way.

This is done by specifying multiple screens in the ServerLayout section of the X config. I don't use xinerama (or 'twinview' as nVidia likes to call it) as I want two distinct displays - :0 and :1 - so that I can select which screen any application (myth, mplayer, xine, xterm etc) will appear on using the DISPLAY environment variable.

I have scripts set up to loop and toggle which display myth appears on - I can switch displays by using a button on the remote which LIRC picks up or a 'swap display' item I added to myth's main menu by editing the XML. The remote option is useful as the display can be switched without turning on the other device just to navigate to the 'swap display' GUI entry.

As a special bonus problem the TV and projector are different ratios - 4:3 vs 16:9. MPlayer needs to be told what the aspect ratio is (-monitoraspect) - this is done by setting an environment variable in the switching script and then using it on the commandline configured inside mythvideo - eg:

mplayer -monitoraspect $MONITORASPECT %S

-- Mamoulian

Well, is this just bragging? You do not specify the changes needed. I simply can not make this work because configuring X is such a black art. Little chance of succeeding without seeing your xorg.conf. Oh thank goodness, the post further down has the vital info, and works well. (PIP Display)

Using a Console Monitor and an HDTV Set

A practical arrangement for some situations is to have MythTV running on a TV set while a separate monitor can be used simultaneously for other computer operations. This requires that the devices be operated as separate displays on one X session without Xinerama. MythTV knows about Xinerama and, if it Xinerama is in use, MythTV will add a configuration field which lets you specify which screen it should run on. The problem is that MythTV will be associated with the virtual desktop on which it is opened. If a different desktop is selected on the primary monitor, MythTV will disappear from the TV screen. Without Xinerama, the DISPLAY environment variable can be used to specify which display will be used for an application when the application is invoked. The application is then not associated with a virtual desktop and will remain on the specified display no matter what is done with the desktop environment on the primary monitor. If the mouse cursor is run off the right edge of the main monitor screen, it will appear on the TV set. If MythTV is running on that display, it will get the keyboard input if the mouse cursor is on its window.

With an NVIDIA Video Controller

The exact setup for this will be hardware and distribution dependent. If an NVIDIA controller is used with the NVIDIA proprietary drivers, the setup is very easy. The “nvidia-settings” program provides a nice graphic interface for configuring the displays and it will build or modify the /etc/X11/xorg.conf file automatically (it must be run as “root” to do this). If the “Detect Displays” button is clicked, it should determine the displays present and add them to a pull-down menu so that they can be configured independently. They should be configured as “Separate X Displays” and the check-box for Xinerama should be cleared to disable this option. With modern hardware, the program can usually determine the base resolution of the displays and it can detect the difference between a computer monitor and an HDTV set (with an HDMI port) and make some adjustments for this. The computer monitor should be defined as “Display 0” so that it will be used as the default by the desktop environment. The TV set will then be “Display 1”. The “Save Changes to xorg.conf” button needs to be clicked and the X server restarted by logging out of the session.

Using the DISPLAY Environment Variable

The value of the DISPLAY environment variable has the form, Host:DisplayGroup.Screen where Host will default to the local system if not specified. DisplayGroup is basically a workstation which is associated with a keyboard. On a standard desktop PC, it will always be zero. It could have another value is there is more than one workstation connected to the system. Screen will be zero for the default console screen while the second display will be 1. Run the command, echo $DISPLAY to see what you have on your console. It will normally return “:0.0” and the TV set will then be “:0.1”. A small shell script can be used to launch the program:

# Run MythTV front end on display 1
export DISPLAY=:0.1

Create this with a text editor and save it. Execute it with a command of the form, sh Path/FileName (which can be entered for a launch button “command” field) or use the file manager's right-click/Properties function to give it execute permission which will allow it to be run directly without the sh command.

It is worth having two launch buttons for MythTV on the tool bar, one of which launches it directly so that it appears on the desktop while the other runs the script to launch it on the TV set. Running it on the desktop may be more convenient for setting up recordings or maintenance operations.

Hardware Connections

An adapter cable can be used to connect a DVI (digital computer monitor) port on a video card to an HDMI port on a TV set. PC's which are intended to be used as multi-media systems may come with HDMI ports. The Shuttle SN78H7 box has an NVIDIA GeForce 8200 chip on the system board with VGA (analog) and HDMI (digital) connectors on the back panel. The chip is a dual-display controller which treats the analog and digital ports as separate devices. The VGA port can be connected to the console monitor and the HDMI port connected to a TV set.

PVR-350 scripts

I run a similar setup, however one of my displays is going through a PVR-350 which requires changes to the settings to enable the 350 and setup the screen size & offsets. Here is a .sql file I use to set it up:

use mythconverg;
update settings set data="1" where hostname="mythtv" and value="PVR350OutputEnable";
update settings set data="635" where hostname="mythtv" and value="GuiWidth";
update settings set data="445" where hostname="mythtv" and value="GuiHeight";
update settings set data="40" where hostname="mythtv" and value="GuiOffsetX";
update settings set data="15" where hostname="mythtv" and value="GuiOffsetY";

And here's how I switch it back to using my nVidia output:

use mythconverg;
update settings set data="0" where hostname="mythtv" and value="PVR350OutputEnable";
update settings set data="0" where hostname="mythtv" and value="GuiWidth";
update settings set data="0" where hostname="mythtv" and value="GuiHeight";
update settings set data="0" where hostname="mythtv" and value="GuiOffsetX";
update settings set data="0" where hostname="mythtv" and value="GuiOffsetY";

I setup a small shell script to write out dummy files to a "swap" directory to store which configuration is active. It's a quick & dirty solution but it works. Feel free to improve it:

killall mythfrontend
if [ -e "$HOME/swap/pvr350" ]; then
  rm $HOME/swap/pvr350
  touch $HOME/swap/nvidia
  export DISPLAY=:0.0
  mysql -umythtv -pmythtv < $HOME/swap/nvidia.sql
elif [ -e "$HOME/swap/nvidia" ]; then
  rm $HOME/swap/nvidia
  touch $HOME/swap/pvr350
  export DISPLAY=:0.1
  mysql -umythtv -pmythtv < $HOME/swap/pvr350.sql
# Note this is specific to the MythDora distro...

Xinerama (One X server, two displays)

Since is pushing xinerama for multidisplay setups with the new xrandr, I chose to make a dual screen setup using xinerama.

Using xinerama means you'll have one big, rectangular virtual screen, and each display will show a subsection of this big virtual screen. I chose to set the two displays next to each other, but you might as well place them above one another or something completely different, just make sure that your physical displays doesn't overlap eachother (see xrandr for how to create a xinerama setup)

When using xinerama, each physical display is assigned a number and this can be used like the old $DISPLAY variable to determine where applications start.

To make mythfrontend start on the same xinerama screen every time, go to: "Setup->Apperance" and set the correct xinerama screen (mythtv may need to be compiled with xinerama support).

To make mplayer show videos on the correct screen as well when using mythvideo, go to: "Setup->Media Settings->Videos Settings->Player Settings" and append "-xineramascreen 1" if your mythfrontend is running on xineramascreen 1.

mplayer -xineramascreen 1 %S

Mplayer has to be compiled with xinerama support as well.

This solution has the following disadvantages:

  • The mouse moves over the entire virtual screen as in the non-xinerama method.
  • The focus is shared between mythfrontend/mplayer and the rest of the desktop. A possible solution to this is to use Xephyr to run another xserver on the second display, and run mythfrontend inside that xserver, but XV is not supported yet, so expect poor video performance.

PIP Display (One X Server, One display, Dual head video card with a desktop on each)

I created this xorg.conf from various bits on the internet to be able to view Mythtv in PIP while using my desktop to browse the web, etc on my Vizio GV42L LCD TV.

My video card is an onboard GeForce 7050 with both VGA and DVI outputs that go into the RGB and HDMI inputs on my TV respectively.

Section "ServerLayout"
        Identifier     "Multi-Head"
        Screen          0  "Desktop" 0 0
        Screen          1  "MythTV" RightOf "Desktop"
        InputDevice    "Keyboard"       "CoreKeyboard"
        InputDevice    "Mouse"          "CorePointer"

Section "Files"
        ModulePath   "/usr/lib64/xorg/modules/extensions/nvidia"
        ModulePath   "/usr/lib64/xorg/modules/extensions"
        ModulePath   "/usr/lib64/xorg/modules"

Section "Module"
        Load    "dbe"
        Load    "extmod"
        Load    "fbdevhw"
        Load    "glx"
        Load    "record"
        Load    "freetype"
        Load    "type1"
        Load    "v4l"

Section "InputDevice"
        Identifier      "Keyboard"
        Driver          "kbd"
        Option          "XkbModel" "pc105"
        Option          "XkbLayout" "us+inet"

Section "InputDevice"
        Identifier      "Mouse"
        Driver          "mouse"

Section "ServerFlags"
        Option          "Xinerama" "0"

Section "Device"
        Identifier      "GF7050_RGB"
        Driver          "nvidia"
        VendorName      "NVIDIA Corporation"
        BoardName       "GeForce 7050 PV / NVIDIA nForce 630a"
        BusID           "PCI:0:18:0"
        Option          "NvAGP"                 "2"
        Option          "UseEvents"             "True"
        Option          "AddARGBGLXVisuals"     "True"
        Option          "ModeValidation"        "NoWidthAlignmentCheck"  # Important!!! need this option to use nvidia card at 1366 x 768
        Option          "ExactModeTimingsDVI"   "True"
        Option          "ModeValidation"        "NoDFPNativeResolutionCheck"
        Screen          0

Section "Device"
        Identifier      "GF7050_DFP"
        Driver          "nvidia"
        VendorName      "NVIDIA Corporation"
        BoardName       "GeForce 7050 PV / NVIDIA nForce 630a"
        BusID           "PCI:0:18:0"
        Option          "NvAGP"                 "2"
        Option          "UseEvents"             "True"
        Option          "AddARGBGLXVisuals"     "True"
        Option          "ModeValidation"        "NoWidthAlignmentCheck"  # Important!!! need this option to use nvidia card at 1366 x 768
        Option          "ExactModeTimingsDVI"   "True"
        Option          "ModeValidation"        "NoDFPNativeResolutionCheck"
        Screen          1

Section "Monitor"
       Identifier       "GV42L"
       VendorName       "VIZIO"
       ModelName        "GV42L"

       HorizSync        31-70
       VertRefresh      50-85

       Modeline "1366x768@60.00"  85.5  1366 1494 1624 1798  768 770 776 795  -HSync +Vsync Interlace
       Modeline "768p@60.00"  85.5  1366 1494 1624 1798  768 770 776 795  -HSync +Vsync

Section "Screen"
        Identifier      "Desktop"
        Device          "GF7050_RGB"
        Monitor         "GV42L"
        Option          "ConnectedMonitor"      "CRT-0,DFP-0" #Force the connected monitor since only one can be active at a time
        Option          "UseDisplayDevice"      "CRT-0"
        DefaultDepth    24
        SubSection "Display"
                Viewport        0 0
                Depth           24
                Modes           "1366x768@60.00"

Section "Screen"
        Identifier      "MythTV"
        Device          "GF7050_DFP"
        Monitor         "GV42L"
        Option          "ConnectedMonitor"      "CRT-0,DFP-0" #Force the connected monitor since only one can be active at a time
        Option          "UseDisplayDevice"      "DFP-0"
        DefaultDepth    24
        SubSection "Display"
                Viewport        0 0
                Depth           24
                Modes           "768p@60.00"

The advantage to this setup is that beyond having to configure mythtv to startup in the :0.1 display there is very little else to do. I use a program called Mouse Jail to lock my mouse cursor in the Desktop Screen.

Here is the script I use to start mythfrontend on the second screen:

#Lock cursor in main display
/usr/local/bin/Jail > /dev/null 2>&1 &
# Kill the kicker
kill -9 `ps -ef | grep kicker | grep -v grep | head -1 | awk '{print $2}'`
export DISPLAY=:0.1
mythfrontend > ~/mythfrontend.log &