Previous section   Next section

Hack 85 Converting Extracted Video

figs/moderate.giffigs/hack85.gif

Coerce those TiVo ty files into a more standard video format.

Video file formats proliferate, but there are a few standards supported by the lion's share of media players, MPEG, DiVX, and AVI being among the most common. TiVo's ty files are just not one of them. So, in order to play them just about anywhere, we need to coerce those files into a more standard video format.

You have a couple of options here, both of which have varying degrees success. Both solutions are still under development and have received their fair share of complaints.

MPlayer

If you compiled your own version of TiVo-MPlayer [Hack #83], you also have a copy of the bundled mencoder application, a perfectly fine option for simple encoding.

mencoder can take a ty file specified on the command line and encode the audio and video using a variety of different codecs. In my opinion, the best tradeoff of quality, space, and resolution is to encode the video using the DiVX 5.0 codec (http://www.divx.com) and audio into MP3 using lame (http://lame.sourceforge.net/). I like to resize the output to 352 by 240 pixels, because that is approximately the resolution of a video CD; anything larger may be a waste, and anything smaller loses information. You can also deinterlace the resulting AVI file at the same time. Instead of transmitting every line on your television at one time, all the odd lines are transmitted first, followed by all the even lines. While this looks fine on a television set, it looks horrendous on a computer screen; deinterlacing cleans that up.

As an example, here I encode an episode of TechTV's Fresh Gear:

$ mencoder fresh_gear.ty -ovc lavc -lavcopts vcodec=mpeg4[RETURN]
-vop scale=352:240,pp=lb -oac mp3lame -o fresh_gear.avi

I'm afraid that mencoder's command-line options are notoriously convoluted. Specify the appropriate ty file first. We're using the audio/video codec libraries to handle the output video. The ovc command-line option specifies which output video codec you want to use—in this case, MPEG4 (DiVX). The vop option says that we'll be toggling the video options; we are rescaling the video and deinterlacing it. Similar to ovc, the oac option controls the output audio codec. We are using lame to do the MP3 encoding of the sound.

After a while, depending on how fast your CPU is, mencoder will spit out a file called fresh_gear.avi, which you can then drag-and-drop into just about any popular media player to watch.

If your media player doesn't support DiVX 5.0 right out of the box, you can download the DiVX 5.0 codec for most platforms to integrate into Windows Media Player, QuickTime, MPlayer, and the like.

If you prefer a really high-quality encoding, you might want to do something called a three-pass encode, which requires three calls to mencoder:

  1. Encode only the audio from the ty file into MP3 format. The audio has to go into a file called frameno.avi; it won't work any place else, so don't change that filename.

    $ mencoder -ovc frameno -o frameno.avi -oac mp3lame fresh_gear.ty
  2. Extract and compute bitrate information from the ty file. With this added information, the next step can make a better guess at the quality at which to encode the video for a higher quality, yet smaller-sized file.

    $ mencoder -nosound -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vpass=1[RETURN]
    -vop scale 352:240,pp=lb -o /dev/null fresh_gear.ty
  3. Encode the ty file as a DiVX AVI using the hints generated from step 2. And, while you're at it, include the MP3 generated from step 1.

    $ mencoder -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vpass=2[RETURN]
    -vop scale=352:240,pp=lb -o fresh_gear.avi fresh_gear.ty

The mencoder also encodes to most other popular formats, such as MPEG-1 and OGM. For further information, see the mplayer home page (http://www.mplayerhq.hu/).

TyStudio

One problem with mencoder is its inability to edit your streams before encoding them. What if you want to create an AVI or MPEG of your favorite show, excluding the commercials? Or perhaps you'd like to capture one particular segment of a favorite talk show featuring your favorite singer, actress, or crocodile hunter?

TyStudio (http://dvd-create.sourceforge.net/tystudio/) allows you to do just that. You'll find both Linux and Windows versions, with one for Mac OS X in the works.

While I'm using the Windows version (shown in Figure 6-3) for the rest of this hack, these instructions also apply rather well to the other releases.

Figure 6-3. The TyStudio interface
figs/tivo_0603.gif

Don't be fooled by TyStudio's bare interface. Great power is hidden within its menus.

As with mplayer and mencoder, we can load ty files either from the filesystem or directly from the TiVo itself. You can either click the "Click here to load a local TY file" button and select a ty file, or you can grab their tyServer (http://dvd-create.sourceforge.net/tystudio/tyserver.ppc.sh) and run it on your TiVo to give TyStudio direct access. Either way, you'll end up with a ty file that is ready for editing.

Use the slider under the viewer pane to move forward and backward through the stream; the video will update as you do so. When you come to the beginning of a section you want to remove from the final video, click the Cut Start button, slide forward to the end of what you want to remove, and click the Cut Stop button. You'll see the time codes for the block destined for the cutting-room floor appear in the pane to the right. If you make a mistake and want to add a cut back into your video, select it in the right pane and click the Remove Selected button. ("Remove" means "remove from the to-be-cut list," not "remove from the video.")

Now to generate the edited video. Notice the "Video to" and "Audio to" pull-down menus on the lower-right side of the interface. You have a couple of options, depending on exactly what you plan to do with the resulting video file:

Generic MPEG2

An MPEG stream, playable by any software and most hardware MPEG players. Be sure to set "Audio to" to "No Transcoding."

DVD

A DVD-compliant MPEG stream. If you have a South African or United Kingdom TiVo, set the "Audio to" to either "DVD" or "AC3 DVD." However, the AC3 option is recommended only if you have a DVD player capable of playing AC3 audio. DirecTiVo owners should set "Audio to" to "No Transcoding."

SVCD

An SVCD-compliant MPEG stream. Set "Audio to" to "44100."

Elementary Stream

Produces a raw video file and a raw audio file. You will most likely use this if you want to edit the files separately in another program—a DVD-authoring program, for instance. You may wish to "Transcode" the audio; just follow the same audio steps you would follow if you were making a DVD or an SVCD.

Click the Process button and wait a while—though not nearly as long as with mencoder.

You should have an MPEG-2 file of your television show—sans whatever you edited out—that you can open in almost any DVD-player application on your computer. In a pinch, you can easily convert the MPEG-2 to MPEG-1 using programs like TMPGEnc (http://www.tmpgenc.net).


  Previous section   Next section
Top