Tuesday, November 29, 2005

Watching "Dirty Jobs" from my bathroom!

That's right, I'm so excited about MythTV that I'm blogging from the crapper, and am damn proud of it. Right now, I'm on the toilet, running MythTV frontend on my laptop which is wirelessly connected to my MythTV backend. And yes, the bathroom door is shut :D

I wasn't able to get this working well with my last MythTV setup, so I figured that with 1 hour shows being 1.1GB, that it must have been a network problem. Well, it's working great with my new backend server, so as it turns out, the poor performance must have come from the backend machine itself.

My Hardware:
My last backend box was a 733MHz P3; my new one is a 2.4GHz P4. My laptop frontend is a 1.73GHz Centrino with plenty of power.

My Network:
802.11g WPA. I'm upstairs from my DLink wireless router (I used to use a LinkSys, but found it had awful range) with the door closed.

My Performance:
I'm a code monkey Linux geek, and honestly, I have no idea how I'm getting this kind of performance over a wireless network. This 1-hour-long show I'm watching is takes up more than 1GB of disk space, and I'm able to start watching the video, and jump through it quickly. The menus are a little sluggish, and it takes about 2-3 seconds to start up a recording, but once it starts up, the video is running really well. Even FFWD/RWD is responsive, only giving me about a 1 second lag.

To compare, I tried running a mplayer on this file through a remote X ssh shell. I was able to see about 1 frame a second. Again - it's amazing how great the MythTV frontend/backend connection works.

Conclusion:
I'm super-impressed - it looks like I won't have to run CAT5 cables throughout my house afterall. In fact, it might be a fun project to try to setup diskless computers around the house to network-boot linux and act as MythTV fronends. Of course if I get around to it, I'll post my results!

Way to go, MythTV team -- the client/server architecture holds up across a WPA wireless network!

Monday, November 21, 2005

What to Expect in Future Posts...

I have so much I need to post here, and wanted to give you a heads up so you know what to expect. I'm planning on posting the following (and then some):

* A description and schematic of the wiring for my setup. It includes 2 TV cards and three TV inputs

* My mplayer setup in MythVideo and how I'm dealing with audio/video sync problems

* Information on how I'm using Samba to dump videos and mp3s from other boxes into MythVideo and MythMusic

* A re-hash of my IRBlaster script that changes the channels on my Comcast Digital TV

* An explanation of my script that generates an iTunes-ready XML RSS Podcast for mp3s I drop in a specific directory -- useful for podcasts you need to manually grab

* The script I modified/wrote that transcodes tv shows to mpeg4 videos that are viewable by my "iPod with Video"

* Photos of my setup, and hopefully a video screenshot of my mythbox in action (if I can figure out how to do that)

* A loving and persuasive write-up about Ubuntu Linux

* The problems that my recent upgrade has overcome from my build a year ago

*** Answers to questions anyone might have for me -- please posts comments and I'll respond as soon as I can. This isn't an easy project, but once completed, you'll feel bad for your friends with Tivos!

Please offer feedback!

If this site was at all helpful, please let me know by leaving comments or emailing me at: "blake (NO SPACE) caldwell **AT** gmail DOT com"

Please also let me know if anything here was inaccurrate or if you'd like to elaborate on something I skimmed by quickly.

LIRC (Continued some more)

Create your lircd startup script:

#------------------------------------------------------
# /etc/init.d/lircd
echo "Setting up and starting LIRC"
modprobe lirc_i2c lirc_dev
/usr/local/sbin/lircd --device=/dev/lirc0
#------------------------------------------------------


Then set it to start automatically:
ln -s /etc/init.d/lircd /etc/rc5.d/S99lircd


Now, to test your lirc setup, first start the daemon by running "/etc/init.d/lircd start". Then, test it by running the command "irw". If you get "connection refused" or similar, then nope, this didn't work. If not, try hitting some buttons on the remote. If you see key codes printed out to your console, then you're in business and can stop reading this post.

Okay, you're still having problems? Assuminig you have more than one Hauppauge TV card in your box, try this for your /etc/init.d/lircd and repeat the above paragraph


#------------------------------------------------------
# /etc/init.d/lircd
echo "Setting up and starting LIRC"
modprobe lirc_i2c lirc_dev
/usr/local/sbin/lircd --device=/dev/lirc1
#------------------------------------------------------

Set your MySQL Password for mythconverg database

I believe mythbackend will create the mythconverg database and mythtv user, but I'm not sure the password it'll create for that user. Come up with a password, change it (I like to use webmin to do simple database stuff -- if you do too, remember to install it using Synaptic), then save the password in your /usr/share/mythtv/mysql.txt file so mythbackend knows what to use for the password:

#-------------------------------------------
# /usr/share/mythtv/mysql.txt
DBHostName=localhost
DBUserName=mythtv
DBName=mythconverg
DBPassword=mythtvpassword

Start MythTV-Frontend on login

You'll have to set mythfrontend to start automatically when you login as user mythtv, you'll need to add it to your startup session. I did it graphically, but I think you can do it by editing /home/mythtv/.gnome2/session-manual:

#--------------------------------------------------
# /home/mythtv/.gnome2/session-manual

[Default]
num_clients=1
0,RestartStyleHint=3
0,Priority=50
0,RestartCommand=mythfrontend
0,Program=mythfrontend

Set user mythtv to automatically log on after boot

You'll probably want to avoid the annoying login step every time you reboot your mythbox, so edit /etc/gdm/gdm.conf to do so. Look for your Automatic Login section, and make sure it looks like this:

[daemon]
# Automatic login, if true the first local screen
# will automatically logged
# in as user as set with AutomaticLogin key.
AutomaticLoginEnable=true
AutomaticLogin=mythtv

LIRC (Continued)

Here's my lirc config file for the user mythtv, located in /home/mythtv/.lircrc

#------------------------------------------------------
# ~/.mythtv/lircrc
#
# MythTV native LIRC config file for
# the grey Hauppauge remote
#
# By Jarod Wilson, 2003/12/21
# Amalgamated from Jeff Campbell's,
# .lircrc, the mythtv.org docs, and
# a few touches of my own. :)
#

# Channel Up
begin
prog = mythtv
button = CH+
repeat = 3
config = Up
end

# Channel Down
begin
prog = mythtv
button = CH-
repeat = 3
config = Down
end

# OK/Select
begin
prog = mythtv
button = OK
config = Space
end

# Play
begin
prog = mythtv
button = PLAY
config = Return
end

# Stop
begin
prog = mythtv
button = STOP
config = Esc
end

# Escape/Exit/Back
begin
prog = mythtv
button = BACK/EXIT
config = Esc
end

# Power Off/Exit
begin
prog = mythtv
button = OFF
config = Esc
end

# Red means stop!
begin
prog = mythtv
button = RED
config = Esc
end

# Pause
begin
prog = mythtv
button = PAUSE
repeat = 3
config = P
end

# Mute
begin
prog = mythtv
button = MUTE
repeat = 3
config = F9
end

# Fast forward (30 sec default)
begin
prog = mythtv
button = Rewind
repeat = 3
config = Left
end

# Rewind (10 sec default)
begin
prog = mythtv
button = Forward
repeat = 3
config = Right
end

# Skip forward (10 min default)
begin
prog = mythtv
button = SKIP
repeat = 3
config = PgDown
end

# Skip backward (10 min default)
begin
prog = mythtv
button = REPLAY
repeat = 3
config = PgUp
end

# Record
begin
prog = mythtv
button = RECORD
repeat = 3
config = R
end

# Delete
begin
prog = mythtv
button = BLANK
repeat = 3
config = D
end

# OSD browse
begin
prog = mythtv
button = GREEN
repeat = 3
config = O
end

# Display EPG while in live TV,
# View selected show while in EPG
begin
prog = mythtv
button = MENU
repeat = 3
config = M
end

# Scroll up
begin
prog = mythtv
button = VOL+
repeat = 3
config = Right
end

# Scroll down
begin
prog = mythtv
button = VOL-
repeat = 3
config = Left
end

# Bring up OSD info
begin
prog = mythtv
button = GO
repeat = 3
config = I
end

# Change display aspect ratio
begin
prog = mythtv
button = FULL
repeat = 3
config = W
end

# Seek to previous commercial cut point
begin
prog = mythtv
button = YELLOW
repeat = 3
config = Q
end

# Seek to next commercial cut point
begin
prog = mythtv
button = BLUE
repeat = 3
config = Z
end

# Numbers 0-9

begin
prog = mythtv
button = 0
repeat = 3
config = 0
end

begin
prog = mythtv
button = 1
repeat = 3
config = 1
end

begin
prog = mythtv
button = 2
repeat = 3
config = 2
end

begin
prog = mythtv
button = 3
repeat = 3
config = 3
end

begin
prog = mythtv
button = 4
repeat = 3
config = 4
end

begin
prog = mythtv
button = 5
repeat = 3
config = 5
end

begin
prog = mythtv
button = 6
repeat = 3
config = 6
end

begin
prog = mythtv
button = 7
repeat = 3
config = 7
end

begin
prog = mythtv
button = 8
repeat = 3
config = 8
end

begin
prog = mythtv
button = 9
repeat = 3
config = 9
end


### MPlayer lirc setup

# Show OSD
begin
prog = mplayer
button = MENU
repeat = 3
config = osd
end

# Pause playback
begin
prog = mplayer
button = PAUSE
repeat = 3
config = pause
end

# Skip ahead a minute if playing
# If paused, resume playing
begin
prog = mplayer
button = PLAY
repeat = 3
config = seek +1
end

# Stop playback and exit
begin
prog = mplayer
button = STOP
repeat = 3
config = quit
end

# Mute
begin
prog = mplayer
button = MUTE
repeat = 3
config = mute
end

# Seek back 10 seconds
begin
prog = mplayer
button = Rewind
repeat = 3
config = seek -10
end

# Seek forward 30 seconds
begin
prog = mplayer
button = Forward
repeat = 3
config = seek +30
end

# Quit
begin
prog = mplayer
button = BACK/EXIT
repeat = 3
config = quit
end

# Seek forward 10 minutes
begin
prog = mplayer
button = SKIP
repeat = 3
config = seek +600
end

# Seek backward 10 minutes
begin
prog = mplayer
button = REPLAY
repeat = 3
config = seek -600
end

# Toggle full-screen
begin
prog = mplayer
button = FULL
repeat = 3
config = vo_fullscreen
end

### Xine lirc setup

begin
prog = xine
button = PLAY
repeat = 3
config = Play
end

begin
prog = xine
button = STOP
repeat = 3
config = Stop
end

begin
prog = xine
button = OFF
repeat = 3
config = Quit
end

begin
prog = xine
button = PAUSE
repeat = 3
config = Pause
end

begin
prog = xine
button = CH+
repeat = 3
config = EventUp
end

begin
prog = xine
button = CH-
repeat = 3
config = EventDown
end

begin
prog = xine
button = VOL-
repeat = 3
config = EventLeft
end

begin
prog = xine
button = VOL+
repeat = 3
config = EventRight
end

begin
prog = xine
button = OK
repeat = 3
config = EventSelect
end

begin
prog = xine
button = BACK/EXIT
repeat = 3
config = Menu
end

begin
prog = xine
button = FFW
repeat = 3
#config = SpeedFaster
config = SeekRelative+60
end

begin
prog = xine
button = REW
repeat = 3
#config = SpeedSlower
config = SeekRelative-60
end

begin
prog = xine
button = FULL
repeat = 3
config = Volume+
end

begin
prog = xine
button = BLANK
repeat = 3
config = Volume-
end

begin
prog = xine
button = MUTE
repeat = 3
config = Mute
end

begin
prog = xine
button = MENU
repeat = 3
config = RootMenu
end

begin
prog = xine
button = SKIP
repeat = 3
config = EventNext
end

begin
prog = xine
button = REPLAY
repeat = 3
config = EventPrior
end

begin
prog = xine
button = GO
repeat = 3
config = OSDStreamInfos
end

begin
prog = xine
button = RED
repeat = 3
config = Quit
end

begin
prog = xine
button = RED
repeat = 3
config = Quit
end

Setting up Lircd remote control for your Hauppauge 350's TV Remote

Get the latest stable version of LIRC (Linux Infrared Remote Control) here. At the time of this writing, it is 0.7.2. Do the usual to install it: "./configure; make; make install"


Here's my /etc/lircd.conf:


#----------------------------------------------------------
#/etc/lircd.conf

#
# this config file was automatically generated
# using lirc-0.5.5pre8 on Sun Apr 18 11:43:45 1999
#
# contributed by Jens Leuschner
#
# brand: Hauppauge
# model:
# supported devices: WinTV primo; WinTV pci; WinTV radio
#
# This config file will work with both homebrew receivers and
# original Hauppauge TV cards !!!
#

begin remote

name Hauppauge
bits 13
flags SHIFT_ENC
eps 30
aeps 100

one 950 830
zero 950 830
plead 960
gap 89584
repeat_bit 2

begin codes
TV 0x000000000000100F
RADIO 0x000000000000100C
FULL_SCREEN 0x000000000000102E
CH+ 0x0000000000001020
CH- 0x0000000000001021
VOL- 0x0000000000001011
VOL+ 0x0000000000001010
MUTE 0x000000000000100D
SOURCE 0x0000000000001022
1 0x0000000000001001
2 0x0000000000001002
3 0x0000000000001003
4 0x0000000000001004
5 0x0000000000001005
6 0x0000000000001006
7 0x0000000000001007
8 0x0000000000001008
9 0x0000000000001009
0 0x0000000000001000
RESERVED 0x000000000000101E
MINIMIZE 0x0000000000001026
end codes

end remote


#
# this config file was automatically generated
# using lirc-0.6.6(animax) on Tue Apr 15 19:50:27 2003
#
# contributed by
#
# brand: Hauppauge
# model no. of remote control:
# devices being controlled by this remote: PVR 2/350
#

begin remote

name hauppauge_pvr
bits 13
flags RC5|CONST_LENGTH
eps 30
aeps 100

one 969 811
zero 969 811
plead 1097
gap 114605
toggle_bit 2


begin codes
Power 0x00000000000017FD
Go 0x00000000000017FB
1 0x00000000000017C1
2 0x00000000000017C2
3 0x00000000000017C3
4 0x00000000000017C4
5 0x00000000000017C5
6 0x00000000000017C6
7 0x00000000000017C7
8 0x00000000000017C8
9 0x00000000000017C9
Back/Exit 0x00000000000017DF
0 0x00000000000017C0
Menu 0x00000000000017CD
Red 0x00000000000017CB
Green 0x00000000000017EE
Yellow 0x00000000000017F8
Blue 0x00000000000017E9
Ch+ 0x00000000000017E0
Ch- 0x00000000000017E1
Vol- 0x00000000000017D1
Vol+ 0x00000000000017D0
Ok 0x00000000000017E5
Mute 0x00000000000017CF
Blank 0x00000000000017CC
Full 0x00000000000017FC
Rewind 0x00000000000017F2
Play 0x00000000000017F5
Forward 0x00000000000017F4
Record 0x00000000000017F7
Stop 0x00000000000017F6
Pause 0x00000000000017F0
Replay 0x00000000000017E4
Skip 0x00000000000017DE
end codes

end remote


#
# this config file was automatically generated
# using lirc-0.7.0(any) on Sun Nov 28 20:25:09 2004
#
# contributed by
#
# brand: Hauppauge 350
# Created: G.J. Werler (The Netherlands)
# Project: Mythtv Fedora Pundit-R www.mythtvportal.com
# Date: 2004/11/28
# model no. of remote control: Hauppauge A415-HPG
# devices being controlled by this remote: PVR-350
#

begin remote

name Hauppauge_350
bits 13
flags RC5|CONST_LENGTH
eps 30
aeps 100

one 969 811
zero 969 811
plead 1097
gap 114605
toggle_bit 2


begin codes
Go 0x00000000000017BB
Power 0x00000000000017BD
TV 0x000000000000179C
Videos 0x0000000000001798
Music 0x0000000000001799
Pictures 0x000000000000179A
Guide 0x000000000000179B
Radio 0x000000000000178C
Up 0x0000000000001794
Left 0x0000000000001796
Right 0x0000000000001797
Down 0x0000000000001795
OK 0x00000000000017A5
Back/Exit 0x000000000000179F
Menu/i 0x000000000000178D
Vol+ 0x0000000000001790
Vol- 0x0000000000001791
Prev.Ch 0x0000000000001792
Mute 0x000000000000178F
Ch+ 0x00000000000017A0
Ch- 0x00000000000017A1
Record 0x00000000000017B7
Stop 0x00000000000017B6
Rewind 0x00000000000017B2
Play 0x00000000000017B5
Forward 0x00000000000017B4
Replay/SkipBackward 0x00000000000017A4
Pause 0x00000000000017B0
SkipForward 0x000000000000179E
1 0x0000000000001781
2 0x0000000000001782
3 0x0000000000001783
4 0x0000000000001784
5 0x0000000000001785
6 0x0000000000001786
7 0x0000000000001787
8 0x0000000000001788
9 0x0000000000001789
Asterix 0x000000000000178A
0 0x0000000000001780
# 0x000000000000178E
Red 0x000000000000178B
Green 0x00000000000017AE
Yellow 0x00000000000017B8
Blue 0x00000000000017A9
end codes

end remote



#----------------------------------------------------------

Using your Hauppauge 350 TV OUT in X Windows

After you're all done installing IVTV and you've rebooted, it's time to setup your X server to use your Hauppauge 350 card's TV out as your video card. To do this, you first need to find out which PCI bus the card is on. Do this by running the command: "lspci -v" from the command prompt (xterm). Scroll up through the output with SHIFT-PGUP until you see a section like this:

0000:02:01.0 Multimedia video controller: Internext Compression Inc iTVC15 MPEG-2 Encoder (rev 01)
Subsystem: Hauppauge computer works Inc. WinTV PVR-350
Flags: bus master, medium devsel, latency 64, IRQ 21
Memory at f0000000 (32-bit, prefetchable) [size=64M]
Capabilities: [44] Power Management version 2

This shows me that the PCI card is at address "0000:02:01.0". As far as X Windows is concerned, we're going to call this "PCI:02:01". Below is the contents of my /etc/X11/xorg.conf. Notice in the "Device" section the line:

BusID "PCI:02:01"

You'll need to format your 350's bus id in this line according to the results you got earlier by the "lspci -v" command.



#-----------------------------------------------------------
# /etc/X11/xorg.conf
Section "Files"
FontPath "/usr/share/X11/fonts/misc"
FontPath "/usr/share/X11/fonts/cyrillic"
FontPath "/usr/share/X11/fonts/100dpi/:unscaled"
FontPath "/usr/share/X11/fonts/75dpi/:unscaled"
FontPath "/usr/share/X11/fonts/Type1"
FontPath "/usr/share/X11/fonts/CID"
FontPath "/usr/share/X11/fonts/100dpi"
FontPath "/usr/share/X11/fonts/75dpi"
# paths to defoma fonts
FontPath "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType"
FontPath "/var/lib/defoma/x-ttcidfont-conf.d/dirs/CID"
EndSection

Section "Module"
Load "GLcore"
Load "i2c"
Load "bitmap"
Load "ddc"
Load "dri"
Load "extmod"
Load "freetype"
Load "glx"
Load "int10"
Load "type1"
Load "vbe"
EndSection

# Your keyboard
Section "InputDevice"
Identifier "Generic Keyboard"
Driver "kbd"
Option "CoreKeyboard"
Option "XkbRules" "xorg"
Option "XkbModel" "pc104"
Option "XkbLayout" "us"
EndSection

# Your mouse
Section "InputDevice"
Identifier "Configured Mouse"
Driver "mouse"
Option "CorePointer"
Option "Device" "/dev/input/mice"
Option "Protocol" "ImPS/2"
Option "Emulate3Buttons" "true"
Option "ZAxisMapping" "4 5"
EndSection

# Your TV
Section "Monitor"
Identifier "Sony TV"
HorizSync 30-50
VertRefresh 60

Mode "720x480"
DotClock 34.564
HTimings 720 752 840 928
VTimings 480 484 488 504
Flags "-HSync" "-VSync"
EndMode
EndSection

# Your Hauppauge 350 TV Card
Section "Device"
Identifier "ivtv"
Driver "ivtvdev"
Option "fbdev" "/dev/fb1"
# Make sure to fill in your PCI bus id for the Hauppauge 350 here
BusID "PCI:02:01"
EndSection

Section "Screen"
Identifier "Screen TV ivtv"
Device "ivtv"
Monitor "Sony TV"
DefaultDepth 24
DefaultFbBpp 32

SubSection "Display"
Depth 24
FbBpp 32
Modes "720x480"
ViewPort 0 0
EndSubSection
EndSection

Section "ServerLayout"
Identifier "Default Layout"
Screen "Screen TV ivtv"
InputDevice "Generic Keyboard"
InputDevice "Configured Mouse"
EndSection

Section "DRI"
Mode 0666
EndSection
#-----------------------------------------------------------

Installing the IVTV driver for the Hauppauge 250 and 350

First, go get the latest IVTV driver. At the time of this writing, it is 0.4.0 - get it here. My last MythTV install used version 0.2.0, which may have been the cause of a lot of my problems -- so make sure you're using the current stable version that's available.

Thanks to Rachel's Knowledge Base Blog for the great advice on how to compile and install IVTV. Make sure to read the "Gotcha" at the bottom.

The one change I made was, I have the following in my /etc/modutils/ivtv file:

#-----------------------------------------------------
# /etc/modutils/ivtv

alias char-major-81 videodev
alias char-major-81-0 ivtv
alias char-major-61 lirc_i2c
options ivtv ivtv-debug=0 mpg_buffers=90
options saa7127 enable_output=1 output_select=0 options tuner type=2
options msp3400 once=1 simple=1 debug=0
add below ivtv msp3400 saa7115 tuner saa7127
add above ivtv lirc_dev lirc_i2c ivtv-fb

#-----------------------------------------------------

Installing MythTV 0.18.1

Fortunately, I could install MythTV by using Synaptic, the graphical apt-get installer in Ubuntu. Installing MythTV installs all the prerequisites, such as MySQL, and a bunch of other goodies.

I'm writing this blog from memory -- I'm sure I'm forgetting a few things I had to install - you'll figure it out :)

Ubuntu Linux 5.1 "Breezy Badger"

I replaced my 733MHz CPU with a 2.4GHz Pentium 4 chip, and decided to get away from Fedora Core 3 and use Ubuntu 5.1 "Breezy Badger", which has been really good to me on my laptop.

Make sure to create the user with the login "mythtv" -- this is the user that MythTV expects will be there, so this will save you some time in the next few steps.

As soon as I installed the base system, I replaced /etc/apt/sources.list with the following contents, so that I could install apps from outside the distribution

#----------------------------------------------------------------
#/etc/apt/sources.list

deb http://archive.ubuntu.com/ubuntu breezy main restricted

deb-src http://archive.ubuntu.com/ubuntu breezy main restricted

deb http://archive.ubuntu.com/ubuntu breezy-updates main restricted
deb-src http://archive.ubuntu.com/ubuntu breezy-updates main restricted

deb http://archive.ubuntu.com/ubuntu breezy universe
deb-src http://archive.ubuntu.com/ubuntu breezy universe

deb http://security.ubuntu.com/ubuntu breezy-security main restricted
deb-src http://security.ubuntu.com/ubuntu breezy-security main restricted

deb http://security.ubuntu.com/ubuntu breezy-security universe
deb-src http://security.ubuntu.com/ubuntu breezy-security universe

deb http://archive.ubuntu.com/ubuntu breezy multiverse
deb-src http://archive.ubuntu.com/ubuntu breezy multiverse
#----------------------------------------------------------------

New posts coming soon!

I recently rebuilt my MythTV box, swapping out my 733MHz cpu with a 2.4GHz, upgrading MythTV 0.17 to 0.18.1, ivtv from 0.2.0 to 0.4.0, and the distribution from FC3 to Ubuntu 5.1 -- and, OMG it's 10 times better... Even my wife says so!

I'll update this site soon to reflect my new adventure and the great rewards I've earned through the efforts.