This is Zach's personal blog. If you're looking for his movies, please click here. Otherwise, have fun!

Friday, March 30, 2007

Houston, we have HD! In a very esoteric fashion, anyway...

As one might expect, grabbing HD frames from the MPEG-2 TS stream, and converting them to H.264 for the Apple TV, is a process fraught with danger, whether from the Long Conversion Time of Doom, the Horror of Out-Of-Sync Audio, or the Terror of Low Disk Space. But I tell ye, here are the programs you need on Mac OS X to make all your troubles vanish:
  • iRecord, as mentioned in this space previously;
  • iSquint, the iPod converter which also does a serviceable job converting for Apple TV; and last but not least
  • MPEG Streamclip, an absolutely essential editor for MPEG-TS files.

All three of these items are absolutely free. For best results, especially if you want to edit out commercials, you should also buy Apple's MPEG2 player component for QuickTime, which is $20. But if you're fine with fast-forwarding, à la TiVo, you can do it all for free. Read on...

First off, you need a compatible HD cable box. I have the Motorola DCT-2600, the standard non-DVR digital box from Comcast. If your cable box has a FireWire output, it'll probably work.

Set up your recording in iRecord's intuitive interface. For me, I was taping Bones (a guilty pleasure my wife and I share; I like Emily Deschanel, she likes David Boreanaz). Fox is a 720p network. If you're taping on ABC or Fox, no scaling is needed; any other network broadcasts at 1080i, so you'll lose some resolution, as the Apple TV doesn't play 1080. In any case, I set the machine to record on Wednesday from 7:59 to 9:00 P.M. 8 to 9 would have been fine, too, as it turned out. (Needless to say, you'll have the computer connected to the box via FireWire at the appropriate time.)

Once the recording is finished, open MPEG Streamclip. If you haven't already, go to the Preferences window and check the box marked "Fix streams with data breaks." This is absolutely essential to make sure the audio and video sync up throughout the stream. Now open the MPEG-TS file you just recorded. It may tell you the file is not legal; hit "Open Anyway."

Now, if you don't have the Quicktime MPEG2 component, you'll get a warning and a play bar will appear, but no picture. No worries. Choose "Convert to MPEG..." from the File menu. You're transforming it from a transport stream to a picture stream (like those used on DVDs) but with no loss of resolution. You need to do this conversion so the aforementioned "Fix streams with data breaks" will apply to the new stream. You could just as easily convert it to a new TS stream as well.

When you've got the new picture stream done, open iSquint and drag the new file to the iSquint conversion list. Select "Optimize for TV" and "H.264 encoding," then hit the Advanced button. Now, enter a resolution of 1280 x 720, a data rate of 4500 (or so... in my experience you could go down to 2000 and still have it look OK), and a frame rate--this is important--of 23.976. If you put in a straight 24, you can get judder, since the original stream is running at 59.94 FPS. You should also choose an audio bitrate of 160 or less. Hit Start. Several cups of coffee later, you'll have an .mp4 file suitable for dropping into iTunes and syncing to your Apple TV! (If you have Quicktime Pro, you can open the .mp4 file in Quicktime, edit out the commercials, and save the result as a self-contained movie; the .mov will also play on the Apple TV.)

If you have the MPEG2 component, you can take iSquint out of the equation entirely. Open the first file (the MPEG-TS you recorded with iRecord) in MPEG Streamclip and edit it directly. MPEG Streamclip uses an in-point, out-point system for its edits; see the in-program help for details. Pay special attention to where the MPEG2 keyframes are; you can use the Go To Keyframe command in the Edit menu liberally. (MPEG Streamclip will choose appropriate cut points for you if you don't do this, but I prefer to have the control.) Then, instead of choosing Convert to MPEG, you can choose Export to MPEG-4 to convert directly. Again, you need to make sure "Fix streams with data breaks" is ON in Preferences, otherwise you're doing absolutely no good.

The bit rate, frame rate, audio bit rate, etc. settings are similar to iSquint. Just be sure you choose the 720p scaling if you've recorded a 1080i stream. I haven't done a 1080i stream yet, so YMMV. In particular, I'm not sure whether the frame-rate would still be 23.976. But I think so. You may also want to choose "de-interlace" for a 1080i file.

Be warned, MPEG Streamclip takes a lot longer to export than iSquint. On the other hand, the second process takes up a lot less disk space.

I realize, with my teeny weeny readership, most of you are probably scratching your head and saying "whaaa?" But if this helped, or if you have any questions or corrections, please do leave a comment in this post.

Edit: after writing most of this, I finished the Bones export. After about a half-hour, judder appears in the stream, as though the exported frame rate is not quite synched with the original frame rate. Perhaps 23.976 is not the magic number after all. Working...

No comments: