Saturday, March 12, 2011

TiVo to Mac to Apple TV — Part II, Capturing Captions

In TiVo to Mac to Apple TV — Part I, Moving Movies I showed how to make Apple TV videos out of TiVo recordings of old movies shown on the Turner Classic Movies HD channel — or, for that matter, of any TV shows your TiVo has recorded and that you have downloaded to your Mac.

The workflow I gave there works miracles, but one miracle it cannot work is adding subtitles to an Apple TV-compatible video file.

TCM HD shows its movies — the vast majority of them — with closed captioning for the hearing-impaired, of whom I am one. When I, using kmttg, download one of these TCM HD recordings to my Mac, the closed captions come along for the ride. They're embedded in the digital video stream.

Let's say, for example, that I download a recording of the 1956 movie The Searchers from my TiVo Premiere to my Mac. A copy of the recording appears on my Mac in a file called The Searchers.TiVo. (The actual The Searchers ________.TiVo filename as saved by kmttg would contain the date of the original recording in place of the ________, but I'll ignore the inclusion of the date in the filename for purposes of this post.) I can then tell VideoReDo TV Suite version 4 with H.264 (VRD) to trim off the unwanted extra material at the beginning and end, and to save the result in a new Mac file. (To use VRD on a Mac, you also have to employ the likes of Parallels Desktop 6 for Mac to let the Mac run Windows.)

If I used the previous post's workflow, I would save the final result as The Searchers.mp4, a video "container" or "wrapper" file in the MPEG-4 format. That file would house an H.264 video stream along with an AAC audio stream. It could in fact be added to my iTunes movie library and played successfully on my Apple TV. The only problem is, VRD isn't presently capable of turning the closed captions in the original MPEG-2 file into subtitles in the MPEG-4/H.264 output file, the one that would be given an .mp4 filename extension.

That's a shame, because the Apple TV is perfectly capable of rendering subtitles that are contained in .mp4 files. An especially nice feature of the way it does so is that the user can turn subtitle rendering on and off for any particular video file at any moment in time, on the fly, while viewing the video on the TV to which the Apple TV connects.

When subtitles can be turned on and off at the whim of the user, they're called "soft" subtitles. When a video's subtitles can't be turned off and on — they're "burned into" the image, so to speak, and they're always "on," and so the video player (the Apple TV, in this case) simply can't turn them off — they're "hard" subtitles.

That's the difference between "hard" and "soft" subtitles. Now, how can I give my .mp4 files soft subtitles?

Step 1

The first step I do is to tell VRD to create a The Searchers Trimmed.mpg output file containing my trimmed selection of video material. The filename extension is now .mpg instead of .mp4. That means the VRD output file is an MPEG-2 "container" file that houses, basically, the selected swath of the original video ... and this time it's not going to be re-encoded to a different format, i.e., MPEG-4/H.264.

When you start VRD, you'll see this window. Click on the "Open Video" button ...

You see an "Open" dialog. Navigate to the (in this example) The Searchers.Tivo file and open it ...

Now, use VRD's editing tools to select a swath of the input video to save. Then, click on the "Save As" button ...

Clicking on the "Save As" button brings up another dialog. If "Save as type:" is not already set to "MPEG2 Program Stream (*.mpg)" click the V button to get ...

In the drop-down menu, select "MPEG2 Program Stream (*.mpg)". After the drop-down menu disappears, click on "Save" in the "Save As" dialog ...

The VRD window will shrink to become a small window with a progress bar while the "Fast Frame Copy" is happening. When it's done, the small window will replaced with one confirming the completion of the output operation. When you click "OK," the main VRD window reappears. You can close it at this point.


Step 1 goes pretty fast — about half an hour for a two-hour movie — because VRD is doing a "fast frame copy" instead of a major re-encoding of the video.

This way of doing things means the closed captioning embedded in the original video gets passed to the output The Searchers Trimmed.mpg video file absolutely intact.

Step 2

Next, I pass The Searchers Trimmed.mpg as input to CCExtractor, an application I run on my Mac from the command line in Terminal.

Drag the CCExtractor icon from the Desktop and drop it on a new Terminal window ...

Now, drag the (in this example) The Searchers Trimmed.mpg file from Step 1 and drop it on the Terminal window, and press Return ...

CCExtractor will begin extracting the closed captions from the The Searchers Trimmed.mpg file ...

When CCExtractor is done, the Terminal window looks like this. A file called The Searchers.srt will now be in the same folder as The Searchers.mpg is in. You can quit the Terminal application.  

CCExtractor creates, over a period of perhaps ten minutes, a text file called The Searchers.srt that contains the closed captions themselves, along with timing information to show when and for how long each caption should be displayed.

Step 3

Now I use HandBrake — specifically, I use the Mac GUI version — to re-encode The Searchers Trimmed.mpg, the output file I made when I used VRD in Step 1, as The Searchers Trimmed.m4v. The .m4v extension indicates an MPEG-4/H.264 video file that is internally constructed in a format that is specifically compatible with QuickTime, iTunes, and Apple TV. In other words, it's not a "generic" MPEG-4/H.264 video file; if it were, it would have an .mp4 filename extension instead.

Here, I have selected The Searchers Trimmed.mpg as the input file to HandBrake. The output file will be called The Searchers Trimmed.m4v. For purposes of re-encoding the input file, I'm using a group of video and audio parameters called "My Apple TV 2 960x544," which I have previously defined. 


I've clicked on the Subtitles tab, then on the "Add External SRT ..." button, to get the following file selection dialog ...


I choose The Searchers Trimmed.srt ...


... and I see this. Notice that I have not clicked the "Burned In" checkbox, although I've clicked the "Default" checkbox so that these will be the default subtitles to be used during playback. (Actually, they're the only subtitles I've specified, but it's theoretically possible to specify more than one set.) Now I'm ready to begin creating my The Searchers Trimmed.m4v output file, so I click on the "Start" button near the upper left corner, and pretty soon I see ... 


The progress bar at the bottom of the window may crawl along for several hours.


That's how I use HandBrake's GUI interface to tell it that, in re-encoding the original The Searchers Trimmed.mpg file as The Searchers Trimmed.m4v, it should use an external SRT file as a source of subtitles. This external file is, of course, The Searchers Trimmed.srt, as output earlier by CCExtractor. By expressly telling HandBrake not to burn these subtitles in, I in effect order it to produce soft, rather than hard, subtitles in its The Searchers Trimmed.m4v output file.

I also tell HandBrake to use my own specially constructed "My Apple TV 2 960x544" preset, which yields an .m4v output file that has 960x544-pixel video resolution at 29.97 frames per second. That resolution is exactly half of the input's in both the horizontal and vertical directions, while the frame rate of the output is the same as that of the input. I expressly tell HandBrake to do no cropping of the original image, so any black bars in the original will show up unchanged in the copy. (Purists will hate that, but I believe HandBrake operates more quickly this way, since cropping necessitates that it compute non-square, anamorphic pixels from the input's square, non-anamorphic ones.) I'm using HandBrake's RF 20 "constant quality" video quality setting, which I feel gives me perfectly acceptable video quality all through the movie.

Fair warning: This step can take a long time — up to six hours or so for a two-hour movie, depending on how slow your Mac is. Re-encoding a two-hour .mpg file as an .m4v can be a lengthy process, and adding soft subtitles makes it even longer.

Step 4

Finally, after the long wait for Step 3 to finish is over, I can add The Searchers Trimmed.m4v to my iTunes movies library. Before I do so, in its Finder window I'm going to rename it The Searchers (SS).m4v so that I'll remember from here on out that it contains soft subtitles. When I add it to my iTunes movies library, it will have the iTunes-internal name The Searchers (SS).

It is my custom to, at this juncture, type Command-I to bring up iTunes' Get Info window on the newly added movie and add poster art via the Artwork tab. (I find the poster images in Google Images by Googling, for instance, "the searchers" poster.) I add information under other tabs as well — usually, Description, under the Video tab, and Year, under the Info tab.

These informational nuggets I obtain by opening The Searchers.TiVo.txt in TextEdit. The Searchers.TiVo.txt is a file that gets created by kmttg way back in Step 1, by virtue of having that application's Metadata option checked at the time I download The Searchers.TiVo from my TiVo to my Mac. The Searchers.TiVo.txt contains such "metadata" items as title, seriesTitledescriptiontimempaaRatingmovieYear, and so forth and so on, for each movie that the TCM HD channel shows.

I also employ a little trick, while I'm editing the movie's Get Info window in iTunes: I set it's Genre to the first letter of its name! In the case of The Searchers (SS), I set Genre to "S." Doing this lets me, when I'm looking at my movies library on my Apple TV, select the Apple TV's View by Genre tab and then see, in effect, an alphabetical index into my movies library!

Here's what it all looks like in the main iTunes window on my Mac (click on the image to enlarge it):



At this point, I am able to play The Searchers (SS) in iTunes on my Mac, which I can tell to show the "English" subtitles during playback ...



... or not, as the mood strikes me.

I can likewise play The Searchers (SS).m4v in QuickTime Player, or in VLC ... or, via iTunes on my Mac, on my Apple TV. In each of those players, optionally turning on the "English" subtitles lets me view text that originally started out as closed captioning in the TCM HD cablecast stream.

And that's it! There are no more steps ...

... however, I should add that it's OK to delete:

  • The The Searchers.TiVo file that was downloaded by kmttg
  • The The Searchers Trimmed.mpg file that was output by VideoReDo
  • The The Searchers Trimmed.srt file that was output by CCExtractor

The only file you absolutely need to keep is The Searchers Trimmed.m4v. (I also tend to keep The Searchers.TiVo.txt, because it has other uses that I won't detail here.)

You may nevertheless choose to keep both The Searchers Trimmed.mpg and The Searchers Trimmed.srt, if (see Apple's New AirPlay Comes to Air Video) you want to be able to use the Air Video iPad/iPhone/iPod Touch app to send Air Video playback of (in this example) The Searchers Trimmed.mpg from the handheld mobile device to a big TV screen in your home, using Apple's new AirPlay/Home Sharing capability. In this Air Video/AirPlay scenario, your Apple TV is again used as an intermediary device.

If you also save the The Searchers Trimmed.srt file, Air Video will optionally (when doing a "Live Conversion") superimpose subtitles from it over top of the video on the touchscreen of the handheld iPad/iPhone/iPod Touch device ... and also over top of the video on the large HDTV screen to which the video + audio playback is being routed via AirPlay.

Still and all, it's not really necessary to keep The Searchers Trimmed.mpg and The Searchers Trimmed.srt as a means of being able to view subtitles during Air Video/AirPlay playback, since The Searchers Trimmed.m4v can reproduce its soft subtitles during Air Video play as well as during the more direct scenario of play via iTunes.

3 comments:

DW said...

I came across your series here and found it extremely informative, thank you!

Like you, I have settled upon KMTTG as the best approach to converting TIVO recordings to formats suitable for viewing on iTunes.

My biggest obstacle lately has been the corrupted closed captioning data in which either the timing is slightly off or the captions occasionally become garbled and/or overlap each other. This usually occurs with specific networks, to varying degrees. For instance, NBC digital has a moderate issue with this, while HBO & Showtime digital has the worst of it.

As far as I can tell, the problem is at the source (the .tivo file) and not with the decoding process.

Additionally, I believe this has to do with the analog and digital captions 'interfering' with one another. Indeed, the overlapping issue sometimes is evident on my television, and when I disable digital captions on my Tivo, this sometimes fixes the overlapping issue.

Although I note that sometimes when I transfer the file from Tivo to my mac, the issue seems to become more prominent.

I am trying to find an equivalent solution on my mac (i.e. disabling the use of digital captions) - What I am struggling with is how to instruct ccextractor to process only the analog closed caption data and ignore the digital caption data (or vice versa).

Ive experimented with the ccextractor settings with "-1, -2, -cc1, -cc2" et cetera none of which seems to accomplish what I am trying to do.

I do know that I can set the delay to solve the timing issue, but what I am interested in is trying to identify the source of the problem rather than address the symptoms.

I fear my best solution with this issue would be to record only the analog channels and ignore the digital network, which is not terribly viable, especially if I have already recorded the program in digital.

I am dying to know if you have come across similar issues with the caption data on a recording not being what they should be once you transfer the Tivo file to your mac.

eric said...

Thank you, DW ...

I can definitely confirm the need to turn off digital closed captions on my TiVo. I posted this thread at the TiVo Community Forum and was told by the creator of kmttg, "I find disabling Digital Captions usually fixes CC related display issues. i.e. Using Standard Captions only seems to work better." When I watch movies on TCM HD with digital captions on on my TiVo, roughly every second TCM HD caption fails to be displayed.

But if I download a TiVo recording of the TCM HD movie to my Mac using kmttg, then decode it into an MPG file, and then use ccextractor on that file, all the subtitles are in fact present. In my experience, they work OK in the procedure I outline in the main post above. In other words, when I use HandBrake to produce an .m4v conversion of the TiVo recording, the soft subtitles I have added to the converted output file are generally complete and well synchronized with the movie. Any problems with completeness, correctness, and synchronization are usually temporary and are attributable to the source recording, i.e., to TCM itself (or whoever TCM has used to produce the captions).

True, sometimes there is a little bit of garbling, which I attribute to hiccups in the cable company's transmission of the program.

However, when I capture captions from other channels, there can be the sort of timing/synchronization problems you talk about. I haven't made much use of it, but (as you seem to have discovered) ccextractor has a -delay ms setting:

"For srt/sami, add this number of milliseconds to all times. For example, -delay 400 makes subtitles appear 400ms late. You can also use negative numbers to make subs appear early."

Alternatively, you can use the "Srt Offset" setting in HandBrake to accomplish roughly the same thing.

I myself have yet to encounter a situation in which ccextractor gives me any digital captions whatever in its output, much less ones that interfere with proper results. I've never fiddled with the "-1, -2, -cc1, -cc2" settings and don't really understand the difference between "Field 1 data" and "Field 2 data," or between "channel 1 data" and "channel 2 data." But you seem to have found that fussing with these parameters is of no help, anyway.

BTW, I am surprised that you are able to capture programs from HBO & Showtime digital channels. I can't: for me, they're copy-protected.

I can't say I have ever found any problems with captions to be more prominent in the file that was downloaded to my Mac than in the original, either. (But see below about Quick Stream Fix in VideoReDo.)

I'd like to find some way in which you could give me more details about all this, but short of your sending me the entire TiVo recording (which is exceedingly difficult to do) I don't know how else to do that.

BTW, you may want to try using the Jubler subtitle editor software. I haven't had a lot of luck with it myself, but your mileage may vary. It supposedly will fix timing issues with subtitles (which is what the closed captions are turned into by ccextractor in outputting an SRT file). You can also edit the content of the captions ... a tedious process, admittedly. But you may want to check it out.

If you are able to use VideoReDo, you may also want to be aware of its Quick Stream Fix capability, which can fix all sorts of timing issues that arise from faulty cable transmissions. You would do that before inputting the file to ccextractor.

Anyway, thanks, DW. for sharing your comments and your frustrations ...

Andrew Bell said...

I am interested in extracting CC and converting that to an SRT file that I can use with my students who are learning English. I want to basically make a transcript of TV shows like "Mankind The Story of All of Us." I know I will need to a tool like CCextractor at the end to do what I want but I am am not what I need ot first use with the DVD to get access to to the Closed Captions? Do you think a program like handbrake is enough for my purposes? I do nor want to add subtitles to a movie...I just want to extract them or or CC and convert to subtitles as a text file. Any suggestions greatly appreciated !