May 28 2008

XvMC

I bought an MSI NX6200AX-TD256H D2 video card (It’s an NVIDIA GeForce 6200 256MB 8x AGP card) to drive the MythTV frontend, since MythTV can’t manage to play even the most modest content using my trusty old Radeon 7000 (MythTV doesn’t support VIDIX, only XVideo). I hoped that the upgrade would allow me to watch live HD television, which means XvMC.

Before I go any further, the other relevant stats: the computer I’m using (for the purposes of this post, anyway) is an 64-bit AMD Athlon 2800+ running 32-bit Ubuntu 8.04. The motherboard is a VIA K8T800. I’m actually using TwinView to share the Desktop computer with MythTV, but I tested everything with a single-screen (the CRT) to avoid confounding, and using TwinView doesn’t seem to make a difference one way or the other.

All the normal stuff works great, but XvMC does not though it should. Whenever I try to use XvMC, the client (mythfrontend or mplayer, for example) freezes up and must be killed. I tried all the standard tweaks that Google could suggest: enable/disable sync on vblank, enable/disable OpenGL vsync, various xorg.conf settings. I tried just about everything I could think of and then some, and the only thing to make any difference at all is this setting in xorg.conf:

Option "NVAGP" "0"

That is, I disabled AGP. When I do this, XvMC works as it should. After a little research, it perhaps shouldn’t be too surprising that AGP is the problem on a VIA motherboard. At least it’s a lead.

Interestingly, when I downgraded the driver from the latest (173.14.05) to the newer legacy driver (96.43.05), XvMC works fine with AGP enabled. As one would expect, it outperforms the newer driver with AGP disabled. Here’s a performance table:

               (% CPU when playing SD/HD in MythTV)
Driver                       Xv     Xv+linear    XvMC+bob
173.14.05 (AGP disabled)  20/100+    30/100+      12/60+ (OSD is too much)
96.43.05                  20/100+    30/100+       8/45

There’s a few caveats to XvMC, either way I get it to work. When deinterlacing is on, the OSD gets deinterlaced too. This isn’t a pretty sight, though it’s functional. The OSD is always grayscale, in spite of setting XvmcUsesTextures to false in xorg.conf and choosing chromakey. But that doesn’t bother me much, I don’t much like the color schemes of the OSD themes I’ve seen.

I have one more straw to grasp before I consign myself to using the legacy
driver (which I may do if it runs FlightGear and X-Plane ok) or crossing my
fingers for a fixed driver before the Olympics (I intend to submit a bug
report). I’m going to try poking around with AGP driving strength settings in
the BIOS. I tried 0xEA and X wouldn’t start at all, but with the same symptoms
I get with XvMC. That hints at the same cause, so maybe with some kind of
binary search I can stumble on a compatible setting.

So in conclusion, I’m going to try using the legacy driver even though my card is supported by the newer driver, and for OSD reasons only use XvMC for HD.


Feb 5 2007

Help! My MPlayer VIDIX output stopped working!

If when you upgrade MPlayer the wonderful VIDIX output mysteriously stops working (I have a Radeon card, but I don’t think it matters), Don’t Panic.

It’s probably just that you forgot to chmod +s /usr/bin/mplayer (or run
mplayer as root, you decide which is the lesser evil). Incidentally, if you
know the device file to change permissions on so that you can run mplayer as
user without the setuid bit, I’m theoretically interested in acquiring that bit of knowledge.


Dec 24 2006

Authoring DVDs

Scenario: you have a bunch of avi files (or whatever) that you want to make into a DVD. They may be episodes of your favorite comedy that you recorded with MythTV and want to keep around but not on your hard disk. They may be home videos. Whatever.

There are commercial programs to do this, and they are either expensive or inflexible and for any of a million reasons they don’t meet your need. What do you do? There’s a lot of good information about the details out there, with the exception of how to transcode your video, so I will give the overview, some links, and details on how to transcode.

First, what a DVD is. It’s an ISO9660 filesystem following a certain convention. That convention is that stuff has certain names in a certain filesystem layout, and that stuff is encoded in certain ways. But it’s just a regular filesystem underneath. If you look at a DVD in the shell you can see what I mean.

Assuming you want to play video DVD on your Wal-Mart-purchased consumer electronics, you need to get your video into an MPEG-2 video with AC3 or PCM audio at 48khz, with the appropriate frame rate for your TV and the correct size and aspect ratio. The mencoder docs have a nifty table showing what you need to decide. Once you’ve decided, use ffmpeg to transcode. It’s not hard: ffmpeg -i in.avi -target ntsc-dvd -acodec ac3 out.mpg. You can change the bitrate with the -b option (see the myriad bitrate calculators online if you’re trying to squeeze things. I’ve found the bitrate calculator in ffmpegX to be the best to use, if you have OS X). You can change the audio bitrate, e.g. -ab 192. You can change the size from “full DVD” to “half DVD” with -s 352x480. You could play with lots of options. What’s important is that you see something like this:

Output #0, dvd, to 'out.mpg':
Stream #0.0: Video: mpeg2video, yuv420p, 352x480, q=2-31, 1703 kb/s, 29.97 fps(c)
Stream #0.1: Audio: ac3, 48000 Hz, stereo, 256 kb/s

If it doesn’t look right, it’s time to double check the options and the order of the options. That one bit me, but it’s right there in the manpage:

ffmpeg [[infile options][-i infile]]... {[outfile options] outfile}...

If it looks right, but mplayer doesn’t seem to grok the output, then get a new ffmpeg. I had one (ffmpeg from darwinports) that would seem to do everything right but somehow leave out or corrupt the audio, so my transcoded videos had no audio. So I compiled my own from SVN.

Once you have transcoded the videos, it’s time to use dvdauthor to make menus and create the DVD filesystem. It’ll take a little work and XMLing, but it’s well-documented online. Then you need to burn your image to a DVD.

But before you burn, try it out in-place with your favorite DVD watching program. Pointing it at the VIDEO_TS directory or perhaps VIDEO_TS/.. should do the trick. If it loads and plays, you’re probably good to go. Burn and test. Get out that sharpie and decorate. Enjoy your newfound sense of accomplishment!


Jun 24 2006

IR Receiver

I’ve always been a software guy. I’m doing good if I can keep up with what good
computer hardware is. But a combination of needing a way to control mplayer
from the couch, poverty, and a desire to learn the useful skill of soldering
drove me to create my own serial IR receiver for use with
lirc.

I was afraid my first soldering project would be a disaster, but it really has
turned out quite nice. At least, it’s nice if you don’t look at the back. :-)
Check out the pictures on
flickr
.

IR Receiver

I followed the instructions from the Linux Journal
article
, with some modifications. I
didn’t want it inside a DB9 case, I wanted to show off my geeky creation so I
didn’t cut up the perf board. I didn’t want a DB9 connector, I wanted to use
cat5 cable and an RJ45 to DB9 adapter
that I had made previously. I used the IR Receiver from Radio Shack, model
276-640
.
The electronics store didn’t have the precise voltage regulator called for but
had one with the same output that could handle higher voltage so I got that
instead.

If I were to start fresh, I would wish I had found these
instructions

instead. The LJ instructions are good, but these ones are better. I think I’d
still use perfboard anyway, since I’m not encasing it in a DB9 hood.

The version of lirc-modules-source in Debian testing at the moment didn’t
work for some reason but the version from unstable works fine. I had a hard
time finding out what model my universal remote is, but I was able to create a
lircd config file for my DVD remote easy enough, and irw recognizes it
fine.

I still have to configure mplayer but there should be nothing special to that.
So I declare my IR receiver a success! Many thanks to Von for teaching me to
solder, Jared for helping me in the initial research, and Erin for not putting
up too much resistance to the idea.


Apr 13 2006

ATI Radeon 7000 VE TV Out

Once upon a time, I was a cheapskate without a 3D-accelerated video card. I
couldn’t play BZFlag, Scorched Earth, or Flightgear. I was deprived. Then one
day I broke down and bought a 3D-accelerated card. I got a Radeon 7000 VE which
was anything but top of the line, but it has perfectly sufficed my needs. It
also has TV out, a fact I don’t remember knowing until a couple of months ago
when I was crawling around behind my desk.

We don’t watch TV. We don’t have dish or cable, and the reception is almost as
bad as the programming. But we do like to watch a few choice shows, e.g. Good
Eats, Smallville, Doctor Who (old and new), and whatever other interesting
things turn up online, like the Pancake
Mountain
theme
or _why’s
FOSCON and other conference videos.
We also like to get movies from the library or Blockbuster, but that’s beside
the point.

So when we got our tax money we had enough cash to throw at an adapter
cable
(although
we spent half as much as that listed price). I had done a little research that
indicated it was possible but hairy to get TV out working with this card. I
enjoy a good challenge, so I ordered the cable.

The cable came yesterday. I got everything working peachily last night. I’m
good at wrangling Linux, but I think that it’s safe to say this card is not
hard to get going. It will be even easier if you found this post.

First things first. Plug in the cable so you’re hooked up to the TV and restart
your computer. You should see the console (boot screen, grub, etc.) on the TV.
That will give you a jolt of excitement; capture it in a cup for later.

Now, when you’ve booted, switch to virtual console 1 (i.e. get out of X) and run:

mplayer -vo vesa:vidix /av/video/pancakemountain.mov

You should see a guy in a cape on both your PC screen and your TV screen. So
you see, it works great. Now, when the movie ends, or you quit, you’ll have a
blank screen and not be able to see what you type. Or maybe you will be able
to. In any case, if you can’t see, just switch virtual consoles, the you can
switch back.

Now, even I spend most of my time in X, so we want to get it working from X. X
runs at a higher resolution and probably different refresh rates than your TV,
so what you see on the TV will be just junk. No big deal, until you want to
watch something. I tried xrandr -s 640x480 and got nothing but a messed up
gnome toolbar to show for it, so let’s steer clear of switching resolution in
X. I tried to figure out how to get mplayer to switch video modes with -vo
xvidix
, but without luck. So I tried -vo vesa:vidix again and it didn’t work
so well. Well, it did work, although the brightness was sky-high. What didn’t
work so well was getting back to X. After running mplayer -vo vesa:vidix ...
from X my USB keyboard stopped working, and I was stuck in limbo. Luckily you
can ssh in and do sudo chvt 8 to get back to normal, as I found after a few
frustrating reboots.

To make a long story less long, I ended up writing a script to do the following

#!/bin/sh
opts="-vo vesa:vidix -ao alsa:device=hw=0.1"
sudo chvt 1
mplayer $opts "$@"
sudo chvt 8

That works excellent. The -ao bit is to use alsa device hw:0,1 which is my
rear output, where the audio part of the adapter cable is plugged in. If you’ve got sudo configured to ask you for your password, you might prefer to jump through lots of fun hoops as explained in the Linux Quake HOWTO.

The only other thing I could hope for is to somehow watch something with
mplayer on the TV, and still be able to use the computer for other things. I
don’t have much hope (without getting another video card, anyway) but if you
know how let me know.

Update

The above solution has a problem: I can’t control mplayer with the keyboard. I can control mplayer from my laptop when I start it over ssh, which is why I didn’t notice that before, but it’s nice to be able to run it from the desktop too.

This is a much nicer script:

#!/bin/sh
opts="-vo vesa:vidix -ao alsa:device=hw=0.1"
sudo openvt -sw -- mplayer $opts "$@"

If you don’t like the idea of running mplayer as root (it’s probably suid anyway), you’re going to have a fun time figuring out how to get "$@" inside of another set of quotes for the su -c command. If you figure that one out I want to hear about it!