Intro

ET OSX is a list of useful tools for the MacOS X, most of which live in the Applications folder on my startup drive. It started as a 'what's on my Mac' page on my personal site but quickly evolved into a blog of its own. I'm trying to focus most on of the tiny but useful utilities that sometimes save you lots of trouble and effort, and to omit for the most part the list of big guns, that one normally uses on a daily basis. The list serves two purposes, lets me easily answer 'how do I do this on the Mac' questions asked by other users, and helps me remember answers to the same questions myself.

HOWTO: Watch (Cyrillic) subtitles right inside QuickTime, FrontRow

Problem: quicktime gives us great stuff like full-screen view through Front Row, AppleTV, browser integration and what not... but for most of us non-native English speakers subtitles are a must. Most of the popular video players out there like VLC or MPlayer support the viewing of subtitles along with the video content. Anybody who has ever played a XviD movie with Cyrillic(wikipedia.org) subtitles will tell you, that the process is far from double-click. Theoretically, Quick Time supports text tracks, but not anything like the popular .srt or .sub subtitle file formats.
Solution: While browsing through a long AppleTV related discussion last weekend I saw a post that promised built-in subtitles support for version 1.0. Turns out the guys that are behind the Perian project have the feature already working, but they are still not offering it for download. Well this got me interested and a couple of days later I had a QuickTime component that allows to watch XviD movies complete with .srt subtitles. Here's how you can also build one for yourself.
Requirements: Apple's Developer Tools, available for free from Apple's Developer Connection or the install disc of every Mac and Subversion, which is a version-control system. You can get background info on Subversion at http://svnbook.red-bean.com/, but I recommend installing the MacOS X packages available from http://www.codingmonkeys.de/mbo/. After installing the them you'll be able to download the programming code for the Perian project. Use the following command

[localhost:~] username% svn co http://svn.perian.org/trunk Perian

which will create a folder called perian and will download the source code for the whole project in it. Then double-click on Perian.xcodeproj which is the Xcode project file and if you've never used Apple's IDE follow these steps:
Locate the file Categories.m and double-click on it:

Now find the line that says something similar to:
NSStringEncoding encodings[] = {NSUTF8StringEncoding, NSUnicodeStringEncoding, NSWindowsCP1252StringEncoding, NSWindowsCP1251StringEncoding};
This is the magic line, by re-ordering those items you set the preference for the encoding of your subtitle track. If you want to be able to view cyrillic subs, you change the line to:
NSStringEncoding encodings[] = {NSWindowsCP1251StringEncoding, NSUTF8StringEncoding, NSUnicodeStringEncoding, NSWindowsCP1252StringEncoding};
Ok, we're almost ready. Now you need to set the build phase of the project to 'Deployment' like on the picture...

And now, build the project:

After a minute you can look into your Perian project folder, where you should have a new subfolder called 'build', inside which you should have 'Deployment' in which at last should be your brand new Perian.component!
Now you can copy it to /Library/QuickTime and immediately you'll be able to view XviD content complete with .srt subtitles! Just make sure you name the .srt file exactly the same as the XviD file and place both files in the same directory. Thats it!
Note: If you previously had Perian installed, play it safe, move the component file somewhere, log out and log back into Finder before installing your new version.
Update: As already noted elsewhere on this site the good folks from the perian dev team have now shipped version 1.0 with complete subtitle support an language recognition. Means you no-longer need to play with svn if you don't want to. Just grab your pre-built copy from perian.org

3 comments:

D-Mo said...

First of all, thank you for the post, it worked like a charm! I recently did this, however, and I did not have to change any lines of code in the categories.m file in order to watch a file with .srt subtitles. In fact, I could not find any of the lines you were talking about. Maybe the code available through svn is newer.

djidji said...

d-mo you are right, since my post the perian dev team has included code that auto-detects the subtitles's encodings so no need to change anything.

Bob said...

Since you are in terminal or iTerm to issue the svn command, "CFLAGS="" LDFLAGS="" make" will build the current Deployment which you can move/copy to /Library/QuickTime or ~/Library/QuickTime. I found that my default CFLAGS interferred with the compilation of the ffmpeg portion of perian. Anyway, just thought that you might like to know this.