<?xml version='1.0'?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
    "file:///usr/share/sgml/docbook/dtd/xml/4.2/docbookx.dtd">

<!-- This should be the DOCTYPE URL above but xmlto doesn't like it
    "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
-->

<article>

<title>Linux TV-out HowTo</title>

<articleinfo>
  <!--
  <author>
    <firstname>Tony</firstname> <surname>Houghton</surname>
    <authorblurb><simpara>Please <link linkend="antispam">see below</link>
    to avoid spam trap</simpara></authorblurb>
    <email>thisisspam@realh.co.uk</email>
  </author>
  -->
  <author>
    <firstname>Tony</firstname> <surname>Houghton</surname>
    <email>this.is.a.spam.trap@realh.co.uk</email>
    <personblurb><simpara>Please <link linkend="antispam">see below</link>
    to avoid spam trap</simpara></personblurb>
  </author>
  <copyright><year>2004</year> <holder>Tony Houghton</holder></copyright>
  <date>18 November 2004</date>
  <revhistory>
    <revision>
      <revnumber>1.43</revnumber>
      <date>17 January 2007</date>
      <revremark>Replaced link to unichrome project with openchrome.</revremark>
    </revision>
    <revision>
      <revnumber>1.42</revnumber>
      <date>9 January 2007</date>
      <revremark>Corrected missing &lt; in Voodoo patch recipe.</revremark>
    </revision>
    <revision>
      <revnumber>1.41</revnumber>
      <date>23 July 2006</date>
      <revremark>Fixed link to subdomain. Added link to Martijn Uffing's
      bt869 patches.
      </revremark>
    </revision>
    <revision>
      <revnumber>1.40</revnumber>
      <date>23 July 2006</date>
      <revremark>New location. Interlaced frame syncing in MythTV. Updated
			comment about getting MPlayer to compile with XvMC and nvidia-glx. New
			info about deinterlacing filters and MythTV glsync.
      </revremark>
    </revision>
    <revision>
      <revnumber>1.31</revnumber>
      <date>24 February 2006</date>
      <revremark>Note about relocation to reduce bandwidth. Antispam
		  paragraph more prominent.</revremark>
    </revision>
    <revision>
      <revnumber>1.30</revnumber>
      <date>11 February 2006</date>
      <revremark>Updates for Matrox RGB out and DirectFB kernel patch and
	options.</revremark>
    </revision>
    <revision>
      <revnumber>1.21</revnumber>
      <date>31 October 2005</date>
      <revremark>bt869 patch for kernel 2.6.14.</revremark>
    </revision>
    <revision>
      <revnumber>1.20</revnumber>
      <date>27 July 2005</date>
      <revremark>Added more useful information about NVidia cards and
        tweaked Matrox section.
      </revremark>
    </revision>
    <revision>
      <revnumber>1.15</revnumber>
      <date>27 July 2005</date>
      <revremark>Added new bt869 (Voodoo 3) patch for kernel 2.6.12,
       courtesy of Henrik Persson, and improved various remarks about Voodoo
       3, interlacing and DirectFB.
      </revremark>
    </revision>
    <revision>
      <revnumber>1.14</revnumber>
      <date>4 February 2005</date>
      <revremark>Separate modprobe commands for bt869 and i2c-voodoo3
      </revremark>
    </revision>
    <revision>
      <revnumber>1.13</revnumber>
      <date>4 February 2005</date>
      <revremark>Corrected and updated directions for applying bt869 patches
      </revremark>
    </revision>
    <revision>
      <revnumber>1.12</revnumber>
      <date>4 February 2005</date>
      <revremark>Missing GATOS chip IDs</revremark>
    </revision>
    <revision>
      <revnumber>1.11</revnumber>
      <date>3 February 2005</date>
      <revremark>Need to build xfree86 for GATOS</revremark>
    </revision>
    <revision>
      <revnumber>1.10</revnumber>
      <date>3 February 2005</date>
      <revremark>Results of testing with G200</revremark>
    </revision>
    <revision>
      <revnumber>1.9</revnumber>
      <date>24 January 2005</date>
      <revremark>Unichrome driver for EPIA systems</revremark>
    </revision>
    <revision>
      <revnumber>1.8</revnumber>
      <date>20 January 2005</date>
      <revremark>X.org doesn't support TV-out GATOS-style; update on ATI RGB
      (thanks to Jeremy Wilkins)</revremark>
    </revision>
    <revision>
      <revnumber>1.7</revnumber>
      <date>12 January 2005</date>
      <revremark>X.org possible alternative to GATOS; DXR3 sound quality;
      maybe not all Matroxes support composite sync; new Matrox TV-out
      section; updated bt869 patch; misc small amendments</revremark>
    </revision>
    <revision>
      <revnumber>1.6</revnumber>
      <date>18 November 2004</date>
      <revremark>DXR3 section and other minor changes</revremark>
    </revision>
    <revision>
      <revnumber>1.5</revnumber>
      <date>1 November 2004</date>
      <revremark>More info about Matrox and interlacing</revremark>
    </revision>
    <revision>
      <revnumber>1.4</revnumber>
      <date>1 November 2004</date>
      <revremark>BT869 support not in kernel 2.6.9 after all</revremark>
    </revision>
    <revision>
      <revnumber>1.3</revnumber>
      <date>24 October 2004</date>
      <revremark>BT869 support in kernel 2.6.9</revremark>
    </revision>
    <revision>
      <revnumber>1.2</revnumber>
      <date>6 October 2004</date>
      <revremark>MPlayer deinterlacing with -vsync -vo sdl</revremark>
    </revision>
    <revision>
      <revnumber>1.1</revnumber>
      <date>5 October 2004</date>
      <revremark>Added paragraph about GATOS not supporting recent chips.
      Gave GATOS sections more meaningful titles</revremark>
    </revision>
    <revision>
      <revnumber>1.0</revnumber>
      <date>30 September 2004</date>
      <revremark>First draft</revremark>
    </revision>
  </revhistory>
</articleinfo>

<sect1> <title>Introduction</title>

<para>This article is a guide to getting a good TV picture (PAL or NTSC as
opposed to HDTV) from a PC running Linux without an expensive external
converter. The emphasis is on using the PC as some sort of video player,
although some of the options are probably well-suited to playing games.
Trying to do any sort of "work" using a TV screen instead of a monitor is
not recommended. Some familiarity with terms such as VGA, RGB and S-Video is
assumed as well as the ability to configure XFree86, compile the kernel and
other software, and set boot-time module configurations.</para>

<sect2> <title>Location</title>
<para>I can not guarantee the exact location of this document due to
vagaries of whatever domain hosting package I'm using at any given
time, but you should always be able to find it by going to
<ulink url="http://www.realh.co.uk/">http://www.realh.co.uk</ulink> and
following the link. I will also try to make it available directly at
either <ulink url="http://www.realh.co.uk/tvhowto">
http://www.realh.co.uk/tvhowto</ulink> or
<ulink url="http://tvhowto.realh.co.uk/">
http://tvhowto.realh.co.uk/</ulink>.</para>
</sect2>

<sect2 id="antispam"> <title>Anti spam</title>
<para>The email address above is fake to foil spammers. Please
replace <literal><replaceable>thisisaspamtrap</replaceable></literal> with
<literal><replaceable>h</replaceable></literal> and accept my apologies for
the inconvenience.</para>
</sect2>

</sect1>

<sect1 id="vgatorgb"> <title>Using the RGB signal</title>

<para>Most video cards should be programmable with suitable modelines for TV
compatibility. However, not all have a composite sync option, so they need
an external circuit to combine the horizontal and vertical sync
signals. People have reported success with this technique using NVidia
cards.</para>

<para>A suitable circuit is detailed at <ulink
url="http://www.hut.fi/Misc/Electronics/circuits/vga2tv/cindex.html">
http://www.hut.fi/Misc/Electronics/circuits/vga2tv/cindex.html</ulink>. The
article has several <link linkend="modelines">XFree86 modelines</link> with
comments for various video cards.  There is an alternative description of
the same circuit at <ulink
url="http://tacashi.tripod.com/elctrncs/vga2tv/vga2tv.htm">
http://tacashi.tripod.com/elctrncs/vga2tv/vga2tv.htm</ulink>.</para>

<para><ulink url="http://www.nexusuk.org/projects/vga2scart/circuit">
http://www.nexusuk.org/projects/vga2scart/circuit</ulink> details a simpler
circuit with links to an RGB to S-Video converter.</para>

<para><ulink url="http://www.linuxnetmag.com/en/issue7/m7tvout1.html">
http://www.linuxnetmag.com/en/issue7/m7tvout1.html</ulink> has another very
simple circuit diagram and also a large table of <link
linkend="modelines">modelines</link>.</para>

<para>
<ulink url="http://www.epanorama.net/circuits/vga2tv/vga2palntsc.html">
http://www.epanorama.net/circuits/vga2tv/vga2palntsc.html</ulink> details a
more complicated cicrcuit to convert from VGA to S-Video and
composite.</para>

<sect2> <title>Cards with composite sync</title>

<para>Some cards have an option to generate composite sync signals with no
  extra circuitry. Certain Matrox cards and most cards based on ATI chips
  are thought to be capable of this. I've had success with a Radeon 9200SE,
  but failure with a Radeon 7000 and a Matrox G200 because their clocks
  wouldn't run at such a low frequency. Some Matrox cards can output
  TV-compatible signals on their second head, but only with specialised
  drivers instead of the mga X driver. See the <link
  linkend="matrox_tv">Matrox TV out</link> section, which includes a <link
  linkend="matrox_rgb">paragraph about RGB</link>.</para>

<para id="rgb_lead"><ulink url="http://ryoandr.free.fr/">http://ryoandr.free.fr</ulink>
has a simple wiring guide for ATI cards. There is similar information at
<ulink url="http://www.idiots.org.uk/vga_rgb_scart/">
http://www.idiots.org.uk/vga_rgb_scart/</ulink>, but it claims to be no
longer under development and superseded by the French site. For the Radeon
cards the composite sync signal is present on the VGA connector's horizontal
sync pin. I do not know whether the signal is also present on the vertical
sync pin or whether Matrox cards are the same, but I should think they are,
and it can easily be corrected by swapping the wire from pin 13 to 14 if
not.</para>

<para>Pin 9 on a VGA connector is officially unused, but on some cards it
provides 5V, which should be suitable for the control signals described in
the above article, although the 16:9 selection did not appear to work for me
with my Radeon, so maybe the voltage dropped too far below 5V. This pin also
carried 5V on my Matrox G200, but that was not capable of low enough
frequencies for a TV.</para>

<para>You may also like to know that pins 2, 6 and 4 on a SCART lead are
audio right and left in, and audio ground respectively, so you can wire
these up to a jack plug for your sound card too.</para>

</sect2>

<sect2 id="modelines"> <title>Modelines</title>

<para>All the above solutions require specific modes to generate frequencies
correct for PAL. XFree86 modelines are sprinkled throughout the articles
referenced. Unfortunately, finding one that works tends to depend
on what sort of card you're using. I tried several with my Radeon 9200SE
unsuccessfully until I generated one by looking at the screenshot of
Powerstrip, a Windows utility, at www.idiots.org.uk and converting the
numbers to an X modeline, using the conversion guide at <ulink
url="http://www.knowplace.org/timings.html">
http://www.knowplace.org/timings.html</ulink>:</para>

<para><computeroutput>
Modeline "720x540PAL" 15.101 720 770 842 968 540 565 570 624 Composite Interlace
</computeroutput></para>

<para>A Radeon 9200 user reports that the 720x576 modeline at
http://ryoandr.free.fr works, but was slightly off-centre, so he modified it
to:</para>

<para><computeroutput>
ModeLine "720x576PAL" 15.125 720 770 842 968 576 579 607 625 Composite Interlace
</computeroutput></para>

<para>720x576 is preferable to 720x540, being a match for PAL DVD
resolution.</para>

<para>The format of a modeline is described in the man page for XF86Config,
and explained in the
<ulink url="http://en.tldp.org/HOWTO/XFree86-Video-Timings-HOWTO/">XFree86
Video Timings HOWTO</ulink>. If you just want a quick hint, the second and
sixth numbers in the line are the horizontal and vertical resolution
respectively.</para>

<para>TVs use unusually low frequencies compared to monitors, so you will
need to change the <option>HorizSync</option> and
<option>VertRefresh</option> parameters. Try these values:</para>

<para><literallayout><computeroutput>    HorizSync       15-20
    VertRefresh     50-60</computeroutput></literallayout></para>

</sect2>

<sect2> <title>Additional option for ATI cards</title>

<para>Additionally, ATI cards often do not admit they can display such low
frequencies when interrogated by the driver, so they need this option in the
<option>Device</option> section to override it - the value in MHz
corresponds to the 15.101 in the modeline above:</para>

<para><computeroutput>
Option "ForceMinDotClock" "15MHz"
</computeroutput></para>

</sect2>

</sect1>

<sect1 id="interlacing"><title>Interlacing problems</title>

<para>Many TV programs are interlaced ie each frame is split into two fields
	of alternate lines and displayed sequentially. This historically gave
	smoother pictures, but leads to problems when trying to display it. The
	interlacing looks fairly unpleasant on the desktop, and few video card and
	software combinations are able to sync fields correctly when playing back
	interlaced video streams. This leads to a shearing effect on a computer
	monitor, and juddery motion on a TV.</para>

<sect2 id="deint"><title>Deinterlacing filters in video players</title>

<sect3 id="xine"><title>Xine</title>

	<para>Fortunately <ulink url="http://xine.sourceforge.net/">xine</ulink>
		has a deinterlace option (<option>-D</option> or
		<option>--deinterlace</option> on the command line) which corrects this
		problem, but it does increase CPU usage and can cause motion blurring.
		You may need as much as 2GHz/XP2000+ of CPU performance to play DVB
		properly with deinterlacing, although the new
		<function>Greedy</function> deinterlacer is said to have considerably
		more modest requirements.</para>
</sect3>
	
<sect3 id="tvtime"><title>tvtime</title>

	<para>I believe the <function>Greedy</function> filter appeared first in
		<ulink url="http://tvtime.sourceforge.net">tvtime</ulink>, a player
		designed for playing video from analogue capture cards, but
		unfortunately not optimised for displaying on a TV screen.</para>
</sect3>
		
<sect3 id="mplayer"><title>MPlayer</title>

	<para><ulink url="http://mplayerhq.hu">MPlayer</ulink> also has
		deinterlace filters.  Alternatively, <link linkend="dfbmga">using a
			Matrox card with DirectFB</link> allows the programme's interlacing to
		be synchronised with the TV out, providing a "perfect" solution.</para>
</sect3>

<sect3 id="vlc"><title>VLC (VideoLan Client)</title>

	<para><ulink url="http://www.videolan.org/vlc/">VLC</ulink> is another
		popular video player, optimised for networked video streams. I have not
		tried it, but it claims to include a deinterlacing filter.</para>
</sect3>

<sect3 id="mythtv"><title>MythTV</title>

	<para><ulink url="http://www.mythtv.org/">MythTV</ulink> is not really a
		video player, but a <acronym>PVR</acronym> with integrated video player.
		I mention it here because it's said to be able to use
		<literal>vsync</literal> interrupts provided by OpenGL or DRI to
		synchronise interlaced fields between a video and TV in a similar manner
		to MPlayer's <link linkend="dfbmga">dfbmga</link> driver with Matrox
		cards. This requires the framebuffer to be running at the same speed as
		the video (50Hz or 60Hz) so would usually be used in conjunction with X
		through a VGA to RGB SCART adaptor as described
		<link linkend="vgatorgb">above</link>, or could
		potentially be used with a <link linkend="voodoo3">Voodoo 3</link>.</para>
</sect3>

</sect2>

</sect1>

<sect1> <title>Introduction to S-Video</title>

<para>TV-out is a very common feature on graphics cards now. Most commonly
they have an S-Video mini-DIN socket, which can also be used as composite
with a simple hardware adapter, usually provided, and a configuration
option. The advantage of S-Video over RGB is that ready-made leads are far
easier to find and usually included. Some cards have a phono composite video
socket instead, which is much the same as far as drivers and software are
concerned. I recommend using S-Video if your TV supports it, because the
quality is visibly superior to composite.</para>

<para>There are two disadvantages of using this feature instead of RGB. The
first is that most of the cards on the market now have rather poor quality
TV-out. The second is that TV-out is an area that is neglected by the
XFree86 developers, mostly leaving it up to third parties to provide extra
drivers etc.</para>

</sect1>

<sect1> <title>ATI TV-out</title>

<para>Despite having earned a better reputation for picture quality on
monitors than rivals NVidia in the past, <ulink
url="http://www.ati.com">ATI</ulink> cards now seem to have the worst
quality S-Video output. They work by scaling standard 800x600 or 640x480
resolutions to fit a PAL screen, which they do quite well; it's just a pity
the overall quality is rather poor, with dull colours and some noise.  You
may find a genuine ATI or a good brand such as Hercules better than a cheap
clone, and a short lead helps prevent any further degradation of the weak
signal.</para>

<para>For Radeon 8500 and newer cards, ATI's proprietary drivers may be
slightly easier to set up than GATOS, especially if you also want to play 3D
games, but GATOS is the only option for older cards.To configure the
proprietary driver, use the provided <command>fglrxconfig</command> utility
and answer the questions appropriately. Appropriate resolutions are 800x600
(recommended) and 640x480.</para>

<para>GATOS is lagging behind XFree86 in its support for the latest
chipsets:- at the time of writing it does not support 9200, 9600, 9800 or
x800 series Radeons. However, I found that my 9200SE worked when I patched
in the necessary chip ID etc from the driver source in the main XFree86
tree. However, I also had to comment out all references to R200_Qh through
to R200Ql (note case) in the GATOS source because these chip IDs seemed to
be missing.</para>

<sect2> <title>Installing GATOS</title>

<para>GATOS is lagging behind XFree86 in its support for the latest
chipsets:- at the time of writing it does not support 9200, 9600, 9800 or
x800 series Radeons. However, I found that my 9200SE worked when I patched
in the necessary chip ID etc from the driver source in the main XFree86
tree.</para>

<para><ulink url="http://gatos.sourceforge.net">GATOS</ulink> is a project
to provide extra drivers for XFree86 to make use of the multimedia
functionality of ATI cards. Getting it installed, especially for TV-out,
looks a little daunting, but is simple enough given a recipe.</para>

<para>The first thing you will need is the source code for the version of
XFree86 you are currently using, eg download and install the SRPM for
RPM-based distributions, or use <command>apt-get source</command> in the
case of Debian. You will need to at least partially build it to generate the
Makefiles etc needed by GATOS.</para>

<para>TV-out is only available in one of GATOS' CVS branches, so make sure
you also have CVS installed and run these commands:

<literallayout><computeroutput>cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/gatos login
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/gatos co -r tv_output ati.2 </computeroutput> </literallayout>

Just press Return when the first command asks for a password. To build
it when it's finished downloading run:

<literallayout><computeroutput>xmkmf <replaceable>/path/to/your/xfree86/tree</replaceable>
make
make install </computeroutput> </literallayout>

where <literal>/path/to/your/xfree86/tree</literal> is the path to the
top-level directory of the XFree86 source (directory name
<filename>xc</filename>). <computeroutput>make install</computeroutput> must
be run as root.</para>

<sect3 id="gatosconf"> <title>Configuring XFree86 for GATOS</title>

<para>To configure GATOS' TV-out in <filename>XF86Config</filename> or
<filename>XF86Config-4</filename>, use the <option>ati</option> driver in
the <option>Device</option> section as usual, but add this line:

<literallayout><computeroutput>Option "TVOutput" "PAL" </computeroutput></literallayout></para>

<para>Other valid settings in place of <computeroutput>PAL</computeroutput>
are <computeroutput>NTSC</computeroutput>,
<computeroutput>NTSC-J</computeroutput>,
<computeroutput>PAL-CN</computeroutput>,
<computeroutput>PAL-M</computeroutput>,
<computeroutput>PAL-N</computeroutput> or
<computeroutput>PAL-60</computeroutput>.</para>

<para>Use a resolution of 800x600 (recommended) and/or 640x480 in the
<option>Screen</option> section.</para>

</sect3>

</sect2>

<sect2> <title>X.org</title>

<para><ulink url="http://www.x.org">X.org</ulink> is the successor to
XFree86 for some distributions. Some of the GATOS code has been folded in,
but not the TV out support. Apparently the developers are considering adding
support, but maybe based on BeOS code rather than GATOS. In the meantime, I
don't know whether GATOS can be installed with X.org.</para>

</sect2>

</sect1>

<sect1> <title>NVidia TV-out</title>

<para>NVidia's proprietary driver (see <ulink
  url="http://www.nvidia.com/object/linux.html">
  http://www.nvidia.com/object/linux.html</ulink>) supports TV out with X at
 800x600 and 640x480 resolutions and is easy to configure, thanks in part to
 the good documentation (README) it is supplied with. It has some useful
 features such as support for displaying different pictures on a TV and
 monitor simultaneously, and being able to configure the size of the
 picture. Subjectively, with the cheap examples of each card I have tried, I
 felt that the quality of NVidia's scaler was worse than ATI's, but the
 NVidia had better brightness and colour balance. The latter bears out what
 I once read in a Usenet post by someone who had measured the signal
 strength of some cards and found NVidia to be stronger than ATI.</para>

<para>I will not cover the details of setting it up, because that's covered
 very well in NVidia's README, but I will offer some tips and
 observations.</para>

<para>I found that using X with TV out disabled the console (this could be
  because I was using a framebuffer console instead of plain VGA), so if
  using the card connected to a monitor and TV simultaneously (a good idea
  if not networked to another PC because text is barely readable on the TV)
  the best way to configure it is to combine the instructions for setting up
  the TV with those for setting up multiple X screens on one card. Currently
  these are appendixes J and R respectively. If the TV is set up as the
  secondary display (Screen 1), you can make a video player use it by
  setting <computeroutput>DISPLAY=:0.1</computeroutput>. TwinView (Appendix
  I) might be a viable alternative, but it may be more tricky to ensure a
  video player uses the TV in full-screen mode unless it's the primary
  device.</para>

<para>When using MPlayer in full-screen mode I found that it reset the
 TVOverScan option if I used the SDL driver, but it was OK with Xv.</para>

<para>Playing an interlaced video looked OK in terms of shearing, but this
	could have been partially obscured by the general blurriness, and the
	playback was not very smooth, as if the frame rate had been adjusted
	rather crudely. XvMC may help here, but at the time of trying I could not
	get MPlayer to compile with that enabled; I also had to disable MPlayer's
	OpenGL support. Newer versions of MPlayer seem to be free of those
	problems, but I have not had an NVidia card connected to a TV since.</para>

</sect1>

<sect1> <title id="matrox_tv">Matrox TV-out</title>

<para>Certain Matrox cards are capable of S-Video/composite TV-out. They use
  a framebuffer of PAL or NTSC resolution with interlacing to avoid scaling,
  and allow field synchronisation of interlaced video with the output, so
  quality is very high without the need for a particularly powerful CPU. The
  disadvantages are overscan (picture too large so that the edges can't be
	seen) and that to make good use of it requires
	<ulink url="http://www.directfb.org">DirectFB</ulink> instead of X,
  which can make setting up the software more difficult. MPlayer supports it
  very well; VDR's softdevice plugin works well with it too, albeit with
  some A/V sync issues, and Freevo can make use of it provided the SDL
  library has been compiled with the DirectFB driver.</para>

<para>The Parhelia and newer cards are probably best avoided for Linux, due
  to Matrox not releasing programmers' information for them. I am not sure
  about the G200 and G400, but it appears that the G400's TV-out is
  compatible with Linux and at <ulink
    url="http://www.gossamer-threads.com/lists/mythtv/dev/2993?do=post_view_threaded">http://www.gossamer-threads.com/lists/mythtv/dev/2993?do=post_view_threaded</ulink>
  there is a discussion about how to get a similar facility with a G200. The
  best bet though is with a G450 or G550. They can be bought cheaply from
  eBay etc and their second head connected to a TV via an adaptor. You can
  make your own adaptor using the schematic at <ulink
    url="http://forum.matrox.com/mga/viewtopic.php?t=4385">http://forum.matrox.com/mga/viewtopic.php?t=4385</ulink>
  or order a ready-made one from Matrox's online shop. The price of the item
  itself is reasonable, it's good quality, and although the delivery cost is
  high, I found them to be prompt, at least in the UK, and I think you would
  have to be fairly frugal to be willing to take on such a fiddly soldering
  job. It's also difficult to buy lengths of "raw" double-screened cable
  suitable for S-Video, so if you must make one yourself it's probably more
  practical to sacrifice a ready-made S-Video lead.</para>

<para id="matrox_rgb">There is also a schematic for making an RGB SCART lead
  for a G450 at <ulink
    url="http://forum.matrox.com/mga/viewtopic.php?t=4383">http://forum.matrox.com/mga/viewtopic.php?t=4383</ulink>.
  DirectFB users have reported success with this; my understanding is that
  it works on the second head in the same way as S-Video, but higher picture
  quality may be expected. The wiring is fairly similar to that for <link
    linkend="rgb_lead">ATI cards</link>, the composite sync connection being
  the biggest difference. I don't know whether it works on other models
  besides the G450.</para>

<para id="dfbmga">There are two main HOWTOs for setting up one of these
cards with Linux. <ulink
url="http://www.bglug.ca/matrox_tvout/g450_tvout_howto.html">http://www.bglug.ca/matrox_tvout/g450_tvout_howto.html</ulink>
is mainly concerned with using a TV to display an X desktop, while <ulink
url="http://www.sci.fi/~syrjala/directfb/matrox-tv-out-howto">http://www.sci.fi/~syrjala/directfb/matrox-tv-out-howto</ulink>
is for using DirectFB for viewing TV and video etc via the DirectFB library.
The latter is a more practical use for TV-out, and Matrox cards have the
advantages of supporting several acceleration functions and allowing
interlaced TV programmes (<link linkend="interlacing">see above</link>) to
be shown correctly (for example with MPlayer's
<option>fieldparity=top</option> sub-option).</para>

<para><ulink url="http://www.directfb.org">DirectFB</ulink>'s source tree
	includes some kernel patches. Most of them are not applicable for 2.6
	kernels, but you may find that the matroxfb-full-memory patch (the 2.6
	version is currently only available in DirectFB CVS) helps. I find that
	DirectFBCreate fails intermittently, and that the patch reduces the
	frequency of the failures.</para>

<para>I don't think any of the kernel patches in either HOWTO are applicable
  to recent 2.6 kernels, although the fusion patches for DirectFB are
  optional (use of fusion is discouraged for certain applications such as
  VDR). Pekka Tiittanen and Ville Syrjala's HOWTO is a little outdated: the
  latest release of DirectFB is now 0.9.24 and the major number for the
  fusion devices has changed from 253 to 252.</para>

<para>There are some additional <filename>directfb</filename> options you
  may need if you're using the PC without a console and don't want to have
  to run DirectFB applications as root:</para>

<literallayout><computeroutput>no-graphics-vt
no-vt-switching
no-vt-switch
</computeroutput></literallayout>

<para>and/or</para>

<literallayout><computeroutput>no-vt</computeroutput></literallayout>

<para>Additionally, MPlayer may need the <option>noinput</option> sub-option
  to <option>-vo</option> eg:
  <computeroutput>-vo&nbsp;dfbmga:frameparity=top:noinput</computeroutput>
  if you are not using the host machine's keyboard. See also the
  <varname>disable-module</varname> options in
  <filename>directfbrc</filename>.</para>

</sect1>

<sect1 id="voodoo3"> <title>Voodoo 3 TV-out (BT869)</title>

<para>Some models of 3Dfx's Voodoo 3 series were equipped with TV-out using
a Brooktree BT869 chip. The quality is very good at a native PAL resolution
of 720x576, and presumably also at 720x480 NTSC, but there is some overscan
(edges of picture missing); this is fairly common with most TV picture
sources, so should not be a problem for watching TV and video files.  It can
also display 800x600 and 640x480, but loses a lot of quality in the scaling
and introduces large borders. For the interlaced native PAL (and NTSC?)
modes see the <link linkend="interlacing">interlacing section</link>.</para>

<para>These cards are readily available on eBay for about &#163;10, and are
widely compatible with video software due to being able to display X on
the TV output, so they are a good choice when putting together a HTPC,
provided you have enough CPU power for software deinterlacing if
necessary.</para>

<sect2> <title>So you thought AGP was <quote>a standard</quote></title>

<para>Do check that your motherboard is compatible, because several
different flavours of AGP have evolved over the years, and Voodoo 3s are
quite old now. See <ulink
url="http://www.ertyu.org/~steven_nikkel/agpcompatibility.html">
http://www.ertyu.org/~steven_nikkel/agpcompatibility.html</ulink>. The
connector on mine indicates that it's a 1.5V card. The vast majority of
motherboards should be OK with this.</para>

</sect2>

<sect2> <title>Activating the TV-out</title>

<para>Most of the information in this section came from <ulink
url="http://www.linuxnetmag.com/en/issue7/printm7tvout2.html">
http://www.linuxnetmag.com/en/issue7/printm7tvout2.html</ulink> and the
documentation for
<ulink url="http://secure.netroedge.com/~lm78/">lm_sensors</ulink>' bt869
driver.</para>

<para>In common with many cards the TV-out is activated automatically when
the PC boots, but loses sync when you change mode eg by starting X. Unlike
most of the other cards, reenabling it is not done by the XFree86 driver,
but via the card's I2C interface, and requires specialised modelines
detailed in the bt869 driver documentation. It requires the Voodoo 3 and
Brooktree BT869 I2C drivers.</para>

<sect3> <title>Installing the I2C modules for 2.4 kernels</title>

<para>Download the latest versions of lm_sensors and i2c from
<ulink url="http://secure.netroedge.com/~lm78/">
http://secure.netroedge.com/~lm78/</ulink>. Installation is basically a case
of making sure the kernel's own I2C support is disabled, then running:

<literallayout><computeroutput>make
make install </computeroutput> </literallayout>

for the i2c and lm_sensors source trees in turn.</para>

<para>Also make sure your kernel supports the <systemitem>/proc</systemitem>
filesystem and that it's mounted in <filename>/etc/fstab</filename>. This is
nearly always essential anyway, so you can probably take it for granted that
it's already working.</para>

</sect3>

<sect3> <title>Installing the I2C modules for 2.6 kernels</title>

<sect4><title>Downloading and applying a patch</title>

<para>The bt869 driver is not supported in kernel 2.6, but you can add the
driver as a patch. I originally found a suitable patch by Toby Reed at
<ulink url="http://archives.andrew.net.au/lm-sensors/msg18457.html">
 http://archives.andrew.net.au/lm-sensors/msg18457.html</ulink> and have
been sent updated versions since.</para>

<para>Martijn Uffing has undertaken to keep the driver up to date for recent
kernels (2.6.14 and later) and to host his patches at
<ulink url="http://sarijopen.student.utwente.nl/caligula/kernel/patches/">
http://sarijopen.student.utwente.nl/caligula/kernel/patches/</ulink>. He
also provides versions with the flicker filter enabled.</para>

<para>To apply one of these patches:

<literallayout><computeroutput>cd /usr/src/linux/
patch -p1 &lt; <replaceable>/path/to/downloaded/patch</replaceable></computeroutput> </literallayout>

You can now skip to <link linkend="v3kerncfg">Configuring the kernel</link>.
</para>

<para>For kernel 2.6.12 Henrik Persson sent me a patch which you can
<ulink url="bt869-2.6.12.patch.gz">download from here</ulink>.</para>

<para>To apply this:

<literallayout><computeroutput>cd /usr/src/linux/
zcat <replaceable>/path/to/downloaded/patch</replaceable> | patch -p1</computeroutput> </literallayout>

You can now skip to <link linkend="v3kerncfg">Configuring the kernel</link>.</para>

<para>The original patch was
for kernel 2.6.8.1 and also works up to kernel 2.6.9. If you have one of these
kernel versions download <ulink url="kernel-2.6.8.1-bt869.patch.gz">
kernel-2.6.8.1-bt869.patch.gz</ulink> and apply it thus:

<literallayout><computeroutput>cd /usr/src/linux/drivers/i2c
zcat <replaceable>/path/to/downloaded/patch</replaceable> | patch -p0</computeroutput>
</literallayout></para>

<para>If you have kernel 2.6.10, apply the 2.6.8/9 patch above, followed by
<ulink
url="bt869-2.6.9-to-2.6.10.patch.gz">bt869-2.6.9-to-2.6.10.patch.gz</ulink>,
also supplied by Toby Reed. <computeroutput>cd</computeroutput> into
the <filename>chips</filename> subdirectory and apply it as above.</para>

<para>Unfortunately I do not know which patches work, if any, with kernels
  2.6.11 and 2.6.13. If you have one of these versions and can nout upgrade
  you will have to try the patches for the nearest version. If you find a
  patch only partially works and you need to undo the changes it made, use
  the same command as you used to apply it but add the
  <computeroutput>-R</computeroutput> option.</para>

</sect4>

<sect4 id="v3kerncfg"><title>Configuring the kernel</title>

<para>Configure the kernel in your favourite manner, and go to the I2C
section in Device Drivers. You will probably want to enable the drivers as
modules rather than built into the kernel. Enable at least <option>I2C
support</option>, <option>I2C bit-banging interfaces</option> (in
<option>I2C Algorithms</option>), <option>Voodoo 3</option> (in <option>I2C
Hardware Bus Support</option>) and <option>Brooktree BT869</option> (the one
we added with the patch, in <option>I2C Hardware Sensors Chip
Support</option>). You may also need to enable <option>EXPERIMENTAL</option>
ie <option>Code maturity level options</option> =&gt; <option>Prompt for
development and/or incomplete code/drivers</option> to access all of these,
especially if you added the bt869 driver as a patch. Compile and install as
usual.</para>

<para>It may be worth your while to download lm_sensors even though it isn't
necessary, so you can read the documentation for the bt869 module.</para>

</sect4></sect3>

<sect3> <title>Using the I2C drivers to configure Voodoo TV-out</title>

<para>Make sure both drivers are loaded with 

<literallayout><computeroutput>modprobe bt869</computeroutput>
<computeroutput>modprobe i2c-voodoo3</computeroutput></literallayout>

Some pseudo-files will be created under
<filename>/proc</filename> or <filename>/sys</filename> depending on whether
you have a 2.4 or 2.6 kernel respectively. The directory containing them is
fairly easy to find in <filename>/proc</filename>: it is called
<filename>/proc/sys/dev/sensors/bt869<replaceable>*</replaceable></filename>
where <filename><replaceable>*</replaceable></filename> will look something
like <filename>-i2c-0-44</filename> but varies slightly from system to
system. In 2.6's <filename>/sys</filename> it's somewhat more obscure. I use
this script fragment to find it:

<literallayout><computeroutput>DEVDIR=/sys/devices/</computeroutput> # for 2.6 kernels, or
<computeroutput>DEVDIR=/proc/sys/dev/sensors/</computeroutput> # for 2.4 kernels
<computeroutput>DEVDIR="$(dirname $(find $DEVDIR -name svideo))"</computeroutput></literallayout>

or, to work on either kernel version (until something newer than 2.6 comes
along):

<literallayout><computeroutput>if `uname -r | grep -q 2.6` ; then
    DEVDIR=/sys/devices/
else
    DEVDIR=/proc/sys/dev/sensors/
fi
DEVDIR="$(dirname $(find $DEVDIR -name svideo))"</computeroutput></literallayout></para>

<para>The useful files are: <filename>res</filename>,
<filename>depth</filename>, <filename>ntsc</filename>,
<filename>svideo</filename> and <filename>colorbars</filename>.</para>

<para>To select the resolution, echo it to the <filename>res</filename> file
eg:

<literallayout><computeroutput>echo 720 576 &gt; $DEVDIR/res</computeroutput></literallayout></para>

<para>Similarly for colour depth:

<literallayout><computeroutput>echo 24 &gt; $DEVDIR/depth</computeroutput></literallayout>

although some people seem to find it only works at the default of 16-bit.
Make sure it matches your X configuration.</para>

<para>Select PAL instead of NTSC by echoing 0 to <filename>ntsc</filename>
(1 if you want to use NTSC after all). I presume 1 to
<filename>svideo</filename> confirms you want the default of S-Video while 0
selects Composite.</para>

<para>The above commands should be run when starting X, so I run them from
.xinitrc or .xsession. However, you will need root access so I put them in a
separate script and call it with <command>sudo</command>. They also tend not
to work first time at each startup of X. One solution offered by the bt869
documentation is to turn colorbars on and off (echo 1 and 0 respectively)
after applying the other settings, or simply read the
<filename>colorbars</filename> file with <command>cat</command>. Or you can
try applying the other settings again after a short delay eg, if they're in
a script <filename>/usr/local/sbin/voodootv</filename>:

<literallayout><computeroutput>sudo /usr/local/sbin/voodootv
(sleep 2 &amp;&amp; sudo /usr/local/sbin/voodootv) &amp;</computeroutput></literallayout></para>

</sect3>

</sect2>

<sect2> <title>XFree86 modelines for the BT869</title>

<para>The BT869 is compatible with these modes:

<literallayout><computeroutput>ModeLine "640x480PAL"  29.50  640 675 678 944  480 530 535 625
ModeLine "720x576PAL"  27.50  720 744 800 880  576 581 583 625
ModeLine "800x600PAL"  36.00  800 818 820 960  600 653 655 750
ModeLine "640x480NTSC"  28.195793  640 656 658 784  480 520 525 600
ModeLine "720x480NTSC"  27.5  720 744 800 872  480 483 485 525
ModeLine "800x600NTSC"  38.769241  800 812 814 880  600 646 649 735</computeroutput></literallayout></para>

<para>You will need to select a mode that matches the one passed to the i2c
driver. I recommend using 720x576PAL or 720x480NTSC to avoid the somewhat
ropey scaling.</para>

</sect2>

</sect1>

<sect1> <title>VIA EPIA integrated motherboards</title>

<para>These mini-ITX boards deserve a mention. Their very small form factor
and low power consumption makes them popular. The TV-out works automatically
without any special intervention, provided you stick to a standard mode such
as 800x600; however, I've heard a rumour that recent drivers may support PAL
resolutions natively. The signal is reported to be a little weak, but
quality is OK with a short cable. Some models also have an on-board MPEG
decoder, which should make them good for playing digital TV and DVDs. Best
support currently appears to be available with the openChrome drivers from
<ulink url="http://openchrome.org/">http://openchrome.org</ulink>.</para>

</sect1>

<sect1> <title>Creative DXR3 and Hollywood Plus</title>

<para>Creative's DXR3 and Sigma's REALmagic Hollywood Plus cards are very
similar pieces of hardware. They were designed for viewing DVDs back when
most PCs did not have enough processing power to decode the MPEG. They can
either superimpose video on the desktop and output to a monitor with a VGA
socket, using a passthrough cable (notorious for degrading quality) from the
PC's main graphics card, or output the video to TV (S-Video or composite).
It also has its own sound output (SPDIF and stereo jack) which is useful if,
like me, you are rather short of PCI slots and your motherboard lacks
onboard sound, or its onboard sound is too quiet when connected to a TV.
However, I found the stereo output on my DXR3 a little weak compared to even
my &#163;5 CrystalMedia-based soundcard. The SPDIF is probably much
better.</para>

<para>The availability of fast, cheap CPUs etc has largely obsoleted these
MPEG decoders, but they are very useful for HTPCs because of the high
quality TV out and their ability to display interlaced material correctly
(<link linkend="interlacing">see the section on interlacing</link>), and
play MPEG (1 &amp; 2) much more efficiently than a CPU. They can be bought
second-hand, eg on eBay, for about &#163;10, but they are not as common as
old graphics cards such as Voodoo 3s. Although the hardware is really only
capable of playing MPEG 1 or 2 material, some applications, most notably
<ulink url="http://mplayerhq.hu">MPlayer</ulink>, can display other formats
by using a filter to convert to MPEG 1. Although there must be some
conversion losses, the result on a TV is probably better than most graphics
cards due to the respective quality of the TV output. You will need a
reasonably fast processor. Most people say you need at least 1GHz; my 1.2GHz
Celeron seems to cope well with reasonably high quality MPEG 4 without
dropping frames and plenty of headroom in the CPU load.</para>

<para>The downside of these cards is that they tend to lose synchronisation
between sound and picture, at least with current Linux applications, but
this can be worked around with MPlayer's A/V delay controls, and the
developer of the DXR3 plugin for <ulink
url="http://www.cadsoft.de/vdr/">VDR</ulink> is working on the problem
too.</para>

<sect2 id="em8300"><title>The Linux driver</title>

<para>The driver is available from <ulink
url="http://dxr3.sourceforge.net">http://dxr3.sourceforge.net</ulink>. At
present you need to use CVS if you want to use it with kernel 2.6:

<literallayout><computeroutput>cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/dxr3 login
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/dxr3 co em8300</computeroutput> </literallayout>

(Just press Enter when prompted for a password). The driver is called em8300
after the main chip on the card.</para>

<sect3><title>Compiling em8300</title>

<para>There is a <ulink
url="http://dxr3.sourceforge.net/hwoto.html">Howto</ulink> on the <ulink
url="http://dxr3.sourceforge.net">website</ulink> but it tends to get bogged
down in detail rather than provide a straightforward guide.</para>

<para>If there is a configure script in the version you downloaded, skip to
the next paragraph. But if you downloaded from CVS, you need to create it by
running <command>bootstrap</command>. You will need libtool, automake and
autoconf for this.</para>

<para>You can build the tools in the usual way:

<literallayout><computeroutput>./configure
make
make install</computeroutput> </literallayout>

but the modules have to be built separately. Go into the
<filename>modules</filename> directory and run <command>make</command> and
<command>make install</command> there. Also run <command>make
devices</command> to create the device nodes in
<filename>/dev</filename>.</para>

</sect3>

<sect3><title>Loading the em8300 modules</title>

<para>There are three modules altogether, <filename>em8300</filename>,
<filename>adv717x</filename> and <filename>bt865</filename>. You need the
em8300 module and one of the other two depending on your particular card.
The Howto suggests that DXR3s use bt865 and Hollywood+'s use adv717x, which
may require some options depending on revision.</para>

<para>The Howto lists some module options and loader scripts, but I did not
find this information particularly useful and simply added
<computeroutput>em8300</computeroutput> and
<computeroutput>bt865</computeroutput> to
<filename>/etc/modules</filename>.</para>

</sect3>

<sect3><title>EM8300 microcode</title>

<para>Microcode is included in current versions of the em8300 module so you
do not need to worry about it in normal use. If you want to reload it with
<command>em8300setup</command> the file is available as
<filename>modules/em8300.uc</filename> in the source tree.</para>

</sect3>

<sect3><title>em8300setup</title>

<para>Applications such as MPlayer and VDR should not need this, but it
still has its uses. Run <command>em8300setup -h</command> to see a list of
options. One point to note is that for use on a 16:9 TV the -o and -w
options seem to be the wrong way round. Therefore you may need to run
<command>em8300setup -o</command> after starting playback.</para>

</sect3>

</sect2>

<sect2><title>MPlayer and DXR3/Hollywood+</title>

<para>To enable DXR3/H+ support in MPlayer you need to install the library
from the <link linkend="em8300">em8300 driver</link> before compiling
MPlayer, then it should be auto-detected.</para>

<para>MPlayer has some very good HTML documentation, including details of
how to use it with a DXR3 or Hollywood+, so there is no need to add much
here. However, one point it does miss is what quality setting to use for the
lavc filter (conversion to MPEG). A value of 0 uses the best quality
possible; if you have problems with dropped frames try 10000 and keep
reducing it until you find a suitable value. If there are still problems at
5000 you may unfortunately not have enough CPU power to do it
justice.</para>

</sect2>

</sect1>

</article>
