Tuesday, August 21, 2007

Apple TV: Adding Subtitles

In Apple TV is a Winner! I wrote about my new Apple TV, which plays iTunes media files on my HDTV via my wireless home network. In Apple TV: Getting Content I showed how to get movies to play on it using BitTorrent (plus, of course, buying them from the iTunes store or manually ripping them from DVDs using HandBrake). Now I'd like to discuss how people who are like me in being hearing-impaired can add subtitles to their content. (Of course, you don't have to be hearing-impaired to want subtitles. Maybe you don't speak the language the movie is in. What I'm about to discuss can help anyone who wants subtitles for any reason.)

If you rip your own movies using HandBrake, you have the option of telling HandBrake to burn the subtitles (a.k.a. captions) that are right on the DVD into the image on the output file. End of story.

But if you get movies in any other way, there will probably not be subtitles or captions included with it. Never fear. You can probably remedy that situation.


In broad overview, what you need to do is, first of all, obtain a movie file from, say, BitTorrent. As an example, I'll be using a copy of the 1994 movie Maverick that I downloaded as a torrent file in the .avi format.

Then, you go to one of the websites where subtitles are available, locate a subtitle file for the movie in question, and download it. I've been to two such sites so far:


I found my Maverick subtitles at OpenSubtitles.

You also need to download and install software that will let you make use of the downloaded subtitles files. I currently have two such packages for the Mac:


I'm going to show how to use TitleLAB in this post. In a coming post I'll discuss Submerge.

Edit: Since I wrote the following,
I have run into a strange problem using
movie files that TitleLAB subtitles
have been added to in QuickTime.
Although the files played fine initially,
they've ceased to work after a day or so.

In iTunes, they simply won't play when asked to;
nor will "Convert Selection for Apple TV"
in iTunes' Advanced menu work with them.

In QuickTime, they fail with the message
"The movie could not be opened. An invalid
public movie atom was found in the movie."

I don't have any idea what could account for
this strange behavior, or how to fix it. For now, I
have to recommend that no one use TitleLAB in
the way the rest of this post describes.


The Maverick subtitles I downloaded from OpenSubtitles unzipped to a folder on my desktop that contained two files. One was subtitles.nfo, whose utility I haven't a clue about. The other was anglais.srt. The .srt extension was the key: it meant this file contained the actual subtitles. (The filename, anglais, was whatever the maker chose to name the file. It could have been whatsis or lollapalooza, for all anyone cares.)

I opened anglais.srt in TitleLAB, which presented me with a window:


Each line in the window was a subtitle for a line of dialogue in the movie, with its start and ending times. I selected the first line and selected Set Sync Point A in TitleLAB's Syncing menu. I then scrolled down to one of the very last lines in the movie, selected it ...



... and selected Set Sync Point B in the Syncing menu.

Now that I had identified two widely spaced sync points in the list of subtitles, I chose Synchronize from the Syncing menu. That caused TitleLAB to ask me what movie file to sync the subtitles with. I navigated to it in the Open File dialog, and TitleLAB opened a new window. In that Window I clicked Go There under Sync Point A, and got this:


As you can see, TitleLAB had opened a viewer for the .avi file containing Maverick. The fact that it was able to do this at all had to do with my already having installed DivX and XviD codecs on my Mac — see Apple TV: Getting Content for more on that.

When I clicked Go There, TitleLAB positioned the viewer to the time given in the subtitles list for the Sync Point A subtitle, "Almost got hung myself once." It then allowed me to click the play button, and the movie started to play from that point.

Only problem was, I soon found that 0:01:31.58 wasn't the right spot for the Sync Point A subtitle. That didn't come until 0:01:47.14 in the movie. Why there was about a 15 second discrepancy I had no idea. But never mind — I simply clicked Set at the exact right spot in the movie, and 0:01:47.14 immediately became the starting time for the Sync Point A subtitle line.

Sync Point B was even further off, it turned out, so I used a similar method in the TitleLAB Sync window to change it to 2:02:11.28. Then I clicked the Apply button. The TitleLAB Sync window with the movie viewer in it closed, and I saw that the original window's list of subtitles had had their times adjusted for proper synchronization with this version of the movie.


I next clicked on the Settings tab, and got this:


I clicked on Find Best to have TitleLAB determine the optimal width and height of the subtitle area that would eventually be combined into the movie image. This is what I got:


TitleLAB had located both the widest and the tallest subtitles and set the width of the subtitle area to 433 and its height to 40. (If you don't set the subtitle area's width and height in Settings, TitleLAB will default to a square subtitle area that is much too narrow and much too tall for my taste.)

Then it was time to select Save and Preview from TitleLAB's File menu. TitleLAB let me name the output subtitles file whatever I wanted (I chose Maverick 6) and let me put it wherever I wanted on my hard drive. Notice that this is a separate file from the original anglais.srt input file, which does not change or get overwritten. After TitleLAB saves the output subtitles file, it previews it in a dropdown sheet in the main window, which shows what is in effect a little movie of just the subtitles! I closed that boring thing right away and quite TitleLAB.


At that point, I had nothing but a revised set of subtitles, synced precisely to the movie file, but not yet applied to that file. My next step was to open in QuickTime both the Maverick 6 file with the subtitles in it and the .avi file containing the movie.

That's right: there were two separate windows open in QuickTime, one for the movie and one for the Maverick 6 subtitles file, which QuickTime treats as a movie with just a Text track (no Video or Sound tracks).

I made sure both "movies" were set to their starting points, so synchronization would not be a problem, and with the subtitles window active I did Select All and then Copy (both from the Edit menu). Then I made the "real" movie window active and did Add To Movie in the Edit menu. (Note: don't use Paste instead.)

This added my subtitles to the real movie as an extra track, Text, in addition to its existing Video and Sound tracks.

Next, I had to reposition the Text track in the movie window so that the subtitles would show up centered at the bottom of the frame. (Their default position is upper-left.) To do that, I chose Show Movie Properties from QuickTime's Windows menu while the actual movie window was active. In the properties window which then opened, I made some strategic changes under the Visual Settings tab, with this as the result:



Specifically, I changed the Offset from 0 x 0 pixels to 140 x 280. The first number represents 140 pixels from the left edge of the image. The second, 280 pixels from the top. I found these offset numbers by trial and error, inasmuch as each time I changed a number the subtitle moved to a different position in the movie window. A different set of subtitles for a different movie might well have somewhat different offset numbers.

I also used the popup menu at lower-left of Properties to change Transparency to Blend so the movie image would "show through" the subtitle area behind the actual subtitles. The default behavior is for the subtitle area to have a solid black, opaque background.

Once I had done all that, I selected Export in QuickTime's File menu. In the resulting dialog I selected Export: Movie to MPEG-4, which meant that the output movie would be playable by iTunes and Apple TV. (The input version of the movie was an .avi file that iTunes can't use.) I exported the movie to a file and location of my choice, with encoding settings I discussed in Apple TV: Getting Content. The hours-long process of having QuickTime convert the input movie without subtitles to the output movie with subtitles began.

When it eventually wrapped up, I discovered I had to make sure the output filename had been given an extension iTunes would recognize. I chose .m4v, though .mp4 and .mov would have worked too. (My originally chosen filename had no extension. If I had but known, I would have specified the extension at the time I exported it from QuickTime.)

Then I added the output movie to my iTunes library, by dragging its icon in Finder to the iTunes icon in the Dock. The movie opened up in iTunes and began to play. Here's a frame from it:



Meanwhile, iTunes began automatically syncing the subtitled movie to my Apple TV. It played there just fine, too.

6 comments:

Anonymous said...

Thanks
I had difficulties finding the right way to add a subtitle (Dutch) to a movie for my Apple TV.
Your explanation was very helpfull

Christian said...

If I rip a DVD with Handbrake, and I choose two different language audio track (let's say, English as the primary, Spanish as the secondary), then I'm able to choose between the two audio track when I'm using QuickTime. Now my question is: Is it possible to switch between audio tracks for a movie when it is playing on AppleTV. We speak several languages in the family, and I use this to keep the languages "alive" in the kids.

I have yet to purchase a movie via the iTunes Store, so I don't even know if those movies come loaded with options for multiple languages (like most DVDs) and subtitles, or if a single language audio track is define by the country of origin for you iTunes account (i.e., your credit card).

Also, can I turn on and off subtitles on Apple TV?

Would you care to comment on this technical detail.

eric said...

Christian,

Most of this response to your questions is guesswork on my part, since I don't have a lot of experience with multiple subtitles/soundtracks on Apple TV ... except, of course, when I use HandBrake to "burn" subtitles into movies I rip.

"Is it possible to switch between audio tracks for a movie when it is playing on AppleTV?"

Supposedly, if you hold down the Play button on the Apple TV remote for a couple of seconds while playing a movie (see this discussion) you can then switch audio tracks.

This is also the way to switch chapters. I don't have any movies with second audio tracks, so all I see when I do this is a chapter list. I imagine that a movie with two audio tracks and a chapter list would present you with the opportunity to say which you want to do: change the audio track, or change the chapter.

"Also, can I turn on and off subtitles on Apple TV?"

I'll refer you to this discussion.

Reading between the lines, I get the idea that the type of movie file used for iTunes/iPod/iPhone/Apple TV is capable of supporting not only multiple language tracks but multiple subtitles.

That is confirmed for iTunes itself here.

Yet it is questionable (a) whether any movies at the iTunes Store actually have subtitles, much less subtitles in multiple languages; (b) whether the Apple TV could access those subtitles and switch between them whenever you want.

(A related issue: closed-captioning. It looks like a grand total of 90 movies at iTunes Store have it!)

It also is hard to tell whether "Ratatouille," the movie Steve Jobs used to advertise iPhone/iPod selection of alternate audio tracks and subtitles, actually has either, in real life.

I believe HandBrake is unable to code subtitles in a way that they can be turned on and off. But it does encode second audio tracks, and I think you may find that the trick I mentioned earlier will let you switch between them on the Apple TV.

As for your speculation about the language that you get when you download a movie at the iTunes Store depends on the country where you live or where your credit card is registered ... I am at a loss to confirm or refute that. Does anybody know and want to leave a comment about it?

Permit me to editorialize some now: I think it is shameful that the iTunes Store does not provide alternate audio tracks, selectable subtitles, and closed captions on all movies and TV shows ... just as a DVD typically does.

It is a "grievous sin" and not just a minor one because Apple has cultivated such an image of being multicultural and handicapped-friendly. If the technology supports doing that on iTunes movies — and it looks like it does — then there is no excuse for Apple not taking advantage of it!

Anonymous said...

try iSubtitle... It is a lot simpler and works better. Make sure you use the .m4v extension!

Anonymous said...

Hi there, I know you posted this a little while back but, I found this very informative. However, when I saved the titlelab file, it saved as a txt file that wouldn't open in quicktime. I'm not sure why this happened. I was using an mp4 file for my movie.

Thanks again!

eric said...

Anonymous said...

Hi there, I know you posted this a little while back but, I found this very informative. However, when I saved the titlelab file, it saved as a txt file that wouldn't open in quicktime. I'm not sure why this happened. I was using an mp4 file for my movie.

Anonymous,

The output file from TitleLAB is supposed to be a Text file, so that much is right and proper.

If you look at that file in TextEdit, you should see something like this at the beginning ...

{QTtext}
{plain}
{anti-alias:Off}
{keyedText:Off}
{dropShadow:Off}
{backColor:255, 255, 255}
{timeScale:1000}
{width:0}
{height:0}
{timeStamps:absolute}
{language:0}
{textEncoding:0}
{ScrollDelay:0}
{ScrollIn:Off}
{ScrollOut:Off}
{HorizontalScroll:Off}
{ReverseScroll:Off}
{ContinuousScroll:Off}
{FlowHorizontal:Off}
{font:Helvetica}
{size:20}
{textColor:65535, 65535, 65535}
{justify:center}
{plain}

... after which come the actual time stamps and captions, such as this ...

[00:00:09.242]
CAPTIONING MADE POSSIBLE BY
WARNER BROS.

Such a Text file ought to be able to be opened in QuickTime Player, in which it will actually play as if it were a movie (except the picture is black). That is, the captions will appear in the "movie" window, and nothing else will appear except for a black background.

If this much of the workflow doesn't work for you, I can't imagine why.

By the way, I hope you pay heed to my warning that the TitleLAB workflow I outlined in the original post produced as an end product movie files that mysteriously stopped playing a day or so after I created them!

That is why I suggest to you that before you do too much head-scratching about TitleLAB, you might consider switching to the Jubler subtitle editor. it's not perfect either, but you may be able to obtain decent results with it.

Best of luck,
Eric