Thursday, March 3, 2011

TiVo to Mac to Apple TV — Part I, Moving Movies

2nd-Generation
Apple TV
A fun thing: record movies from cable TV on your TiVo, then capture the movies on a Mac so they can be watched on an Apple TV. Meanwhile, delete the original recordings from the TiVo to free up space.

It's a good way to avoid buying DVDs. Unfortunately, there's no really simple way to send movies from a TiVo to an Apple TV. One reason is that programs recorded on a TiVo are in a different digital-video format than the Apple TV can use.

So I have to:

  1. Move each "keeper" movie from my TiVo to my Mac over my home WiFi network. The Mac software I use to do that is kmttg. It makes a file on my Mac that contains a copy of the original TiVo recording. That file has .TiVo as its filename extension. See Archive HDTV Recordings to Your Mac, Then Stream Them Back to Your TiVo! for more about how to use kmttg.
  2. Decode the Mac copy of the recording so that it is no longer encrypted. That makes it into an unencrypted video container/wrapper file in the MPEG-2 format, with an .mpg filename extension.
  3. Edit the MPEG-2 container file to remove any unwanted sections. The movies I record from Turner Classic Movies HD usually have a lot of trimmable material (sorry, Robert Osborne and Ben Mankiewicz) prior to the start of the actual movie, plus more at the end. This step makes what I call a "trimmed" MPEG-2 file. The filename extension again is .mpg.
  4. Convert the trimmed file to MPEG-4. The new MPEG-4 container/wrapper file will have .mp4 as its filename extension. Internally, it needs to contain a copy of the original MPEG-2 video that has been converted to the H.264 encoding format. It also must contain a copy of the original digitally encoded audio converted to the AAC encoding format, so that the file will play properly on the Apple TV. In short, the original video/audio must be recoded.


VideoRedo
TV Suite w/ H.264
Steps 2 to 4 can be done all at once in VideoReDo TV Suite version 4 with H.264. I'll refer to it as VRD. VRD is, at $95.99, admittedly pricey. Unfortunately, though, I know of no other software that will do what it does with anywhere as much flexibility and ease of use. For those who are interested in building a TiVo-to-Mac-to-Apple TV video collection, it's money well spent.

Parallels Desktop 6
For Mac
A problem with using VRD is that it's Windows-only and won't run on a Mac. I use Parallels Desktop 6 for Mac to deal with that. Parallels Desktop ($79.99; but check for discount offers) is commercial software that lets me install Windows XP Professional Edition (or various other versions of Windows) into a so-called "virtual machine" or "VM" on my Mac. I fire up my WinXP VM in Parallels Desktop, and suddenly my Mac is a Windows XP machine. The WinXP VM runs in (you guessed it) a window under Mac OS X, so I can hop back and forth between it and the Mac desktop, as well as use other Mac applications, all while Parallels Desktop is running and executing VRD.

Installing Parallels Desktop takes a while, and then installing Windows in Parallels Desktop takes another long while — plus, you do have to buy a copy of Windows. Then you have to download and install VRD in Windows. Don't expect to rush right into any of this. Don't think it can be done on the cheap, either.

Before I go into more detail on how to do all this, a quick word about so-called "container" files. Here's a picture of one:

The components of a QuickTime container file

This graphic comes from this one-page "Container vs. Codec" PDF, which discusses the geeky question of what the difference is between a container file and the codec or codecs that create its various component parts. In it, "QuickTime file" is being used synonymously with "MPEG-4 container file."

For purists: H.264 and AAC are actually better spoken of as encoding formats or encoding types, not codecs. There are various actual codecs that can produce, say, video output in the H.264 format. One of these codecs is called x264. But x264 is the codec, H.264 the encoding format or type.

That said, just about everybody uses the terms "codec" and "encoding format/type" interchangeably.

Now for more detail about how I do Steps 2 through 4 in the list I gave above:

In my Mac's WinXP VM window — i.e., in Parallels Desktop — I start VRD and click it's big blue Open Video button ...


The Open Video button is huge ...


... to browse to and open any particular TiVo recording, such as Black Orpheus.TiVo ...


Here, I'm selecting the "Black Orpheus.TiVo" input file ...


... that kmttg has transferred to my Mac. (The original recording date has been included by kmttg in the actual filename, but I'll omit it for purposes of this discussion.) This file is, of course, known to my Mac because it's sitting on one of its external hard drives. The WinXP VM can also see it and use it. Accordingly, VRD can do so, too.

VRD is capable of directly reading files such as Black Orpheus.TiVo that have been downloaded from a TiVo to a personal computer. With VRD, those files don't have to be decoded in a separate step, so Step 2 simply goes away!

VRD has flexible, easy-to-use video editing functions. It's easy to trim off unwanted material at the beginning and end of a video:

I've selected (shown in green on the timeline)
just the actual movie itself...



If you look closely at either end of the green part of the timeline, you'll see a red triangle. Those triangles were put there automatically by functions in VRD's Ad-Detective menu. Ad-Detective basically scans your video to find spots where the screen goes fully dark, which is called "video black." When there is a transition between two separate portions of the program-as-a-whole — say, between the actual program and a commercial — there is a brief fade to video black.

Ad-Detective puts a "scene mark" — a red triangle — at each point where the screen goes black. In a typical TCM movie recording, there are no spots in the middle of the movie where I need a scene mark, so I typically do the scan at the start of the recording, manually move the program cursor  to just before the end of the movie, and re-initiate the scan. I can fine tune the result by manually adding or removing scene marks at will. Then I use function keys F5 and F6 to move backward and forward among the scene marks that are generated. I can fine tune the result by manually adding or removing scene marks at will.

Once I have just two scene marks that bracket the actual movie I want to save, I:


  • Press F5 to get to the first of the two scene marks
  • Press F3 to set that point as the start of my actual selection
  • Press F6 to get to the second scene mark
  • Press F4 to set the end point of my actual selection
  • Press the Add Selection button to turn the timeline green between the start and end points


With a little more effort, I would be able remove commercials from the middle of a TiVo recording ... except that TCM shows its movies commercial-free, so I don't need to go to any further trouble in this regard. Step 3 is way easy. Now it's time for Step 4.

Step 4 is hard at first, but much easier after the first time you attempt it. Once I've finished selecting the portion(s) of the original video I want to save, I just click the Save As ...  button that appears in the VRD window, thus bringing up a Save As file dialog. In that dialog I tell VRD what folder to save the output file in, and by what filename:



Here I'm saving my output file to my Desktop as "Black Orpheus" ...



Notice that doing Step 4 right after Step 3 lets me bypass having VRD save the trimmed movie as an MPEG-2 file with filename extension .mpg, which saves me some time. Instead, I'm going to tell VRD to recode it straight away into a different format: the MPEG-4 container format.

But here's where things do get tricky.

They get tricky because I also need to tell VRD what output container and encoding formats to use.

Let's say the input file is Black Orpheus.TiVo. The .TiVo extension means the file is an MPEG-2 container file, but it's TiVo-encoded. (If it weren't TiVo-encoded, the extension would be .mpg.)

I want the output file to be an MPEG-4 container file, because that's what Apple TV needs. The MPEG-4 container/wrapper file will accordingly need to have an .mp4 extension. So I'll want to wind up with an output file called Black Orpheus.mp4.

That Black Orpheus.mp4 file will be playable in QuickTime Player on my Mac (or, for that matter, in QuickTime Player running under Windows in Parallels Desktop). It can be added to and will play in iTunes on either platform. And it can be played (via iTunes running on a Mac or in Windows) on an Apple TV.

To make sure the file works in a cooperative way with Apple-sanctioned software (iTunes, QuickTime) and hardware (Apple TV) requires some special care, however.

Just using an MPEG-4 wrapper file that has .mp4 as its filename extension isn't enough. I also have to make sure that the video and audio encodings that are contained within the wrapper file are of the right sort.

The video portion of the contents of the wrapper file has to use, specifically, the H.264 video encoding format. The audio portion has to use the AAC audio encoding format. Both encoding formats are supported by VRD, but I have to know how to select them and manage them properly. This is the trickiest part of all.

Here I again show my earlier dialog for saving VRD's output file:

That Save As dialog, again ...


Notice the "Save as type:" specification: "Apple TV H.264 MP4 (*.mp4)". It refers to an output profile that I myself created in VRD:

My "Apple TV H.264 MP4" Profile


I created it by clicking on the Options button in the Save As dialog shown above. A form like the one immediately above opened. I filled in the various fields in it, using the values shown, and chose "Save as new profile." That let me fill in the "Apple TV H.264 MP4" profile name at the top of the form, and when I clicked the OK button, my new VRD profile got saved for future use.

From that point on, any time I saved an output file in VRD I could select "Save as type: Apple TV H.264 MP4" in VRD's Save As dialog. I could do so by clicking on the downward-pointing arrow at the right end of the "Save as type:" input field in the dialog to get a menu:




In the menu I could simply select my "Apple TV H.264 MP4" profile whenever I needed to produce an output file that would eventually be sent to an Apple TV.

Notice that (*.mp4) is shown as an indication of the filename extension that will be used by default for my Apple TV output file. That's the extension that goes along with the "MP4 File (Generic)" file type that you can (barely) see in the Edit Output Profile form above. This generic MP4 file type is actually what I referred to earlier as an MPEG-4 "container" or "wrapper" file.

Now, let's go back and take a look at the various settings I made in the "Apple TV H.264 MP4" profile shown earlier in my Edit Output Form screen snapshot:

  • Output mode: Force Recode tells VRD to recode all parts of the input video, not just those that aren't already in the H.264 encoding format (which would be the case with Output mode: Intelligent Recode). In my situation, there is no H.264 material in the input, so this output mode choice would seem to make little difference. However, Force Recode lets me specify Avg Bitrate below, while Intelligent Recode does not.
  • Max resolution: 960 x 544 tells VRD to make a video frame 960 pixels across by 544 pixels vertically. My TCM HD input is 1920x1088, so this involves reducing the output resolution by exactly half in each direction. The Apple TV does not support high-definition resolution at 1920x1088, aka 1080i/1080p video. It will play 720p video (1280x720), but I find I don't need the extra dollop of picture detail, and my assumption is that VRD can do its job faster if the output resolution is a simple fraction of the input resolution.
  • Encoding mode: Single Pass Encoding keeps VRD from taking the extra time to do a 2-pass encoding, which might give me a slightly better picture ... but the picture I get with 1-pass is excellent.
  • Avg Bitrate: 3500 Kbps tells VRD to hold the average rate at which the output video is to be decoded to a modest 3.5 megabits per second.
  • Max bitrate: 5000 Kbps tells VRD to make sure the Apple TV never has to contend with trying to decode more than 5.0 megabits of video information per second. Restrictions on average and maximum bitrate reduce the picture quality somewhat, but they hold the size of the output file down as well and allow for faster streaming of the video across a network.
  • Aspect ratio: No Change tells VRD to retain a 16:9 ratio for the width of the video frame to its height. My source material, at 1920x1080, has a 16:9 aspect ratio. The output is to have this same aspect ratio — which is the proper ratio for a widescreen HDTV.
  • Deinterlace mode: Smart tells VRD what method to use to "deinterlace" the input video, which is originally in the 1080i format. 1080i video is "interlaced" — that's what the "i" stands for — which means each video frame is divided into odd-numbered and even-numbered rows of pixels. Every (approximately) 1/60 second, one of the two groups, called a video "field," is used. Then, in the next 1/60 second, the other field is used. Hence, you can't expect to unite the two fields into a single frame, since the second field is delayed with respect to the first. That means each output frame ought to be "deinterlaced" to get rid of messy picture details known as "interlace artifacts." The Smart method, I have found, works best for me. You can experiment with the other settings for deinterlace mode — None, Auto, BOB, and WEAVE — to see if you like them better.
  • Framerate: No change means VRD will honor the frame rate of the source video — in my case, 29.97 frames per second. This is fractionally less than the 30 fps or 60 fields per second I talked about earlier. The reason for the fractional difference is quite technical ... but it doesn't really matter here. All you need to know is to tell VRD not to change the source video's frame rate in the output video.
  • Audio encoding type: AAC tells VRD to re-encode the source audio to use the AAC encoding format that Apple TV expects.
  • Bitrate: 128 Kbps tells VRD to limit the rate at which the Apple TV's audio decoder has to deal with audio information to 128,000 bits per second.
  • Sample rate: No Change tells VRD that the output audio should provide "samples" at the same rate, measured in KHz, as the input.
  • Compression: None tells VRD not to try to reduce the differences between very loud sounds and very soft ones.
  • Normalization: None tells VRD not to try to turn up or down the overall sound level.

These are the parameters that will control what kind of output VRD will produce when I click on the Save button in the Save As dialog shown earlier.

As far as how long VRD will take to produce this output, this screen snap tells the story:




Yes, it does take some time.

Once the output process is complete, I will have a Black Orpheus.mp4 file sitting in the output folder I specified. This file can then be added to my iTunes Movies list, from which it can be streamed to my Apple TV. Mission accomplished.


* * * * *


There is one slight caveat, however. When I add my .mp4 output file to my iTunes Movies library, I like to go to the trouble to add poster art to it — something which can be easily enough done in iTunes's Get Info dialog, if I use my Web browser to Google to a suitable poster image, copy it to my Clipboard, and paste it into the Artwork pane of Get Info.

When I click Save, the Get Info window should promptly disappear, and the new poster art should promptly show up in cover flow in my Movies library.

Instead, it can take up to five minutes for all that to happen.

The reason has to do with how VRD incorporates into its MPEG-4/H.264 output file a geeky little thing called the "moov atom," which is, according to this discussion, "a self-contained data unit [within the video file itself] that contains information about the video file ... [It] defines the timescale, duration, display characteristics of the movie, as well as subatoms containing information for each track in the movie."

Depending on how the MPEG-4/H.264 output file is destined to be played, the moov atom is expected by the video player to be positioned in different locations within the file.

A frequent scenario is that used by an Adobe Flash Player for streaming video and/or so-called "progressive download" video. In this Flash-oriented scenario, the moov atom needs to be placed at the beginning of the file.

In other situations, the default location of the moov atom — the end of the file — works just fine.

VRD assumes the former scenario, expressly moving the moov atom to the beginning of the file.

Apple's iTunes, on the other hand, wants the moov atom at the end of the file. This appears to be the case even though the file will ultimately be streamed to an Apple TV.

It looks as if iTunes will leave the moov atom alone in a VRD output file that has been added to its Movies library ... until and unless you do something like try to add poster art to the file. In that case, iTunes will take it upon itself to move the moov atom from the beginning of the file to the end. That involves reading and rewriting the entire file, a time-consuming process.

The developers of VRD have hinted they may in some future release give users the ability to position the moov atom at the end of an MPEG-4/H.264 output file. Until that happens, we will have to put up with the irritating behavior of iTunes whenever it tries to move the moov atom on its own.


* * * * *

Further Reading:

For more detail on how to use VRD on a Mac, see my earlier blog post Using VideoReDo TVSuite on a Mac.

You can learn more about the subject of videos that play in iTunes and on iPods, iPhones, iPads, and Apple TVs from The Complete Guide to Managing iTunes Videos at iLounge.com. The article is particularly useful if the TiVo recordings you want to play on Apple TVs or other Apple gear are not movies but TV shows, since the article tells you how to fill in the iTunes Get Info tags properly for TV episodes.

Mac users who, like me, need to convert video files from one digital format to another will also want to read iLounge's The Complete Guide to iPod, iPhone and Apple TV Video Conversion (Mac). (A version of the same article for Windows users is here.)

Users who run into the problem that iTunes and QuickTime will play certain video files without their accompanying audio will want to read iPod plays video but not audio of some exported files.

For geeks only: The Complete Guide to iPod Video Formats and Display Resolutions talks about the various file formats and encoding formats of digital video and audio; the various video resolutions, bitrates, and aspect ratios; and which ones work on which pieces of Apple gear (iPods, iPhones, Apple TVs — but no mention of the iPad, since the article preceded the advent of that device).

No comments: