The televised revolution
Leigh Dyer
|
Jun 28, 2007 11:57 AM
Leigh Dyer lets rip on digital TV, video conversion tools, aspect ratios and video formats.
Digital TV is great: the quality is great, the hardware is cheap and it’s not too tricky to get running on your Linux box. With some time and effort you can even turn a Linux box into a full on-demand digital video recorder using MythTV, but for today, we’ll focus on getting a digital tuner working and recording on your desktop. If you’ve got the processing power, you can even go HD – the tuner doesn’t care what resolution the signal is.
Most digital TV tuners work under Linux, but it’s safest and easiest to stick with a known, good model. I picked up my Leadtek DTV1000T card for about $80. It uses the Conexant CX2388 chipset, which uses the cx88_dvb driver module, but I didn’t even need to know that: Ubuntu, like all good distributions, found the card at boot and inserted the proper module automatically. If you use an unknown card with a similar chipset, you should be able to get it working, but you may have to load the driver manually.
Either way, if the driver has loaded successfully, you should have a ‘/dev/video0’ file, and a ‘/dev/dvb’ directory with various bits in it. The next step is to scan for channels with the ‘scan’ command, which is in the ‘dvb-utils’ package. It needs a base frequency file to work with, but these should be in the package as well – use the one that matches your region:
scan /usr/share/doc/dvb-utils/examples/scan/dvb-t/au-Melbourne >~/channels.conf
Once that’s finished, the channels.conf file should have a line for each channel detected. You can then feed these in to a video player like MPlayer: copy the channels.conf file in to your ~/.mplayer/ folder and open a channel, using the names listed in the file:
mplayer dvb://”SBS DIGITAL 1”
With any luck, SBS will be up and running for you. MPlayer works well in a pinch, but for a more complete digital TV experience, check out a front-end like Klear, which lets you play and record TV with ease.
Video conversion and DVD ripping
Linux has some great general-purpose video conversion tools, including MEncoder, FFMPEG and Transcode. You can rip straight from a DVD to a nice XviD-encoded AVI file with a single MEncoder command, but there are a lot of fiddly bits to learn before you can pull that off well. A better option is to use
dvd::rip, a very neat GUI frontend to the low-level conversion tools.
dvd::rip can be a hassle to install manually, because it depends on so many external tools to do the heavy lifting, but it’s mature enough that your distribution probably has packages – Ubuntu has one in the multiverse repository. It requires a little bit of setting up on the first run, but after that it’s very straightforward, with a series of tabs that you can click through step-by-step to configure the rip.
There are some other good special-purpose frontends like PSP Video Converter and Simple iPod Video Encoder as well, but I haven’t yet found a great general-purpose video encoding frontend. Basic usage of MEncoder from the command-line isn’t too tricky though, and again, most distributions will probably have it packaged.
Because MEncoder is based on MPlayer, it accepts just about anything as an input file, and it takes just a few options to select the basic encoding settings. Here we convert the input file to an AVI file with XviD video and MP3 audio:
mencoder input.mpg -ovc xvid -xvidencopts bitrate=800:autoaspect -oac mp3lame -lameopts cbr=128 -o output.avi
You can build on this base with extra video filters, using the ‘-vf’ option. For instance, you may want to resize the video, particularly if it’s widescreen – many widescreen videos have non-square pixels, and while the ‘autoaspect’ option above lets you record the aspect ratio in to the file, many players ignore it. It’s much safer to resize the video to a nice 16:9 resolution, like 640x360 pixels, using the ‘scale’ filter:
mencoder input.mpg -ovc xvid -xvidencopts bitrate=800 -oac mp3lame -lameopts cbr=128 -vf scale=640:360 -o output.avi
To improve video quality at the expense of processing time, you can tweak the XviD encoding options significantly. I find that the options ‘vhq=2:bvhq=1:chroma_opt:quant_type=mpeg’, added to the end of the ‘-xvidencopts’ section, work well. You can also enable two-pass encoding which, as the name suggests, encodes the file twice: the first works out how complex each bit of the video is to compress, and the second uses that information to adjust the bitrate as it goes. This saves data from simple sections and uses it to boost quality on the tricky bits. To enable this, add ‘pass=1’ to the above options on the first run, and ‘pass=2’ to the second.
 |
| Klear is a great digital TV recorder/player. |
Working with fancy displays
A PC stacked full of video isn’t much good without a big display to play it on, which is why my lounge room PC is permanently connected to a 101cm Sony Bravia LCD TV. Like a lot of big shiny TVs, my LCD has a VGA input, which makes hooking up a PC basically no different from any other monitor.
However, your may need to do some tweaking to get the TV running at its native resolution. On my 1366x768 Bravia, this was just a case of adding an appropriate mode to my /etc/X11/xorg.conf file, and changing the display configuration to use that new mode. I’d like to take credit for this, but to be honest, I Googled my TV and found someone else that had already worked out the details. I placed this line in the ‘Monitor’ section of my xorg.conf:
ModeLine “1360x768” 85.500 1360 1424 1536 1792 768 771 777 795 +Hsync +Vsync
Then, I modified the ‘Modes’ line in the ‘Screen’ section to use the new mode:
Modes “1360x768”
Because X likes things to be divisible by 16, 1360 is about as close as you’ll get to the 1366 pixel native width, but the TV just blanks those extra columns, so the pixels still match up 1:1 with the display.
If your TV doesn’t have VGA or DVI inputs, you’ll have to rely on a video card with more TV-compatible outputs: composite, S-video or component. The best advice I can give you on this is to stick with an NVIDIA card, and the proprietary NVIDIA drivers. Most NVIDIA cards from the Geforce 4 models onwards have TV outputs, with the FX5200 and the 6200 being great, affordable choices if you’re buying new. The proprietary drivers from ATI/AMD also offer TV-out support for most Radeon cards.
Some older cards can be made to work, but the time and cost involved in tracking one down and setting it up is quite daunting. A less neat, though more practical solution is to throw hardware at the problem, in the form of an external VGA transcoder box. These convert a VGA input in to a TV-compatible output, and should work perfectly with any video card.
To configure an NVIDIA card, all you should need to do is add two options to the ‘Monitor’ section of your xorg.conf file:
Option “TVStandard” “PAL-B”
Option “ConnectedMonitor” “TV”
The ‘ConnectedMonitor’ option forces output to the TV, even if you still have a monitor attached, which is handy when you’re first setting it up. The driver will automatically work out which display modes will work on the TV-out, so you should get an image up without having to fiddle with the modes. However, a mode like 1024x768 is wasted on a low-resolution device like a normal TV, so it’s best to use a mode like 640x480 or 800x600.
If you’re using a card with component outputs, you may need to change the ‘TVStandard’ option to ‘HD576i’. You can use higher modes as well, like ‘HD720p’ or ‘HD1080i’ if you’re working with a high-definition TV.
If you’re running a widescreen display, your videos may appear squashed or stretched during playback because X doesn’t know the aspect ratio of your display. Like most widescreen TVs, my Bravia has a 16:9 aspect ratio, while my widescreen LCD monitor uses a 16:10 ratio. You can tell X about the aspect ratio of your display by using the ‘DisplaySize’ option, which takes the width and height of your display in millimetres. This goes in the ‘Monitor’ section, and on my Bravia it looks like this:
DisplaySize 880 500
Most players, including Xine, pick up on this automatically, but for some reason MPlayer, which I prefer to use, needs its own configuration. In the
.mplayer/config file in your home directory (just create it if it doesn’t exist), add the ‘monitoraspect’ option:
monitoraspect=16:9
Of course, on my desktop I use ‘16:10’ as the value, to match the display.
Video formats
Just as with compressing audio, there’s a range of codecs available for video compression. Xvid encodes to the MPEG-4 Advanced Simple Profile (ASP), like the commercial DivX codec, but it’s free and open source. Because it’s a compliant MPEG-4 encoder, Xvid files can be played on a wide range of players and devices. Along with its good balance between performance and quality, this makes Xvid a great choice for most needs.
If you really want to minimise your file sizes, you can try the more modern H.264 codec, otherwise known as MPEG-4 Advanced Video Coding (AVC). MEncoder and other tools support H.264 through the x264 encoder. You can get smaller files and better quality than Xvid but at the cost of longer encoding times and greater CPU usage during playback.
However, both MPEG-4 variants are, like MP3, covered by software patents, which puts these codecs in a legal grey area even though the software is free. The patent-free alternative is Ogg Theora, an open source video codec along the lines of the Ogg Vorbis audio codec. Theora is derived from VP3, a proprietary codec from On2 Technologies, which was released as open source in 2001, along with a disclaimer freeing it from On2’s patents. The easiest way to work with it is with ffmpeg2theora, which will convert just about anything to an Ogg file with Theora video and Vorbis audio. However, Theora doesn’t yet perform as well as Xvid, and there are concerns that it never will, at least without using any patented encoding techniques.
This article appeared in the
July, 2007 issue of PC Authority.