Hack52.Add Custom Subtitles to Video


Hack 52. Add Custom Subtitles to Video

Use MPlayer's subtitle format to add your own commentary to your favorite movies.

When it comes to watching foreign films, I've found there are two types of people: those who prefer subtitles, and those who prefer dubbing. Even though dubbing has come a long way since the days of Godzilla and '70s Kung Fu movies, I still find that I fall into the subtitle camp. I prefer being able to hear the original actors say their lines in their own language. I read fast enough, so following along with the dialogue as it's printed hasn't been a problem for me.

Of course, not every foreign video is subtitled. In fact, there's a rather large movement of fans of certain programs who create subtitles (called fansubs) for them. Many of these subtitles not only contain translations of the dialogue on screen, but also extra explanation for any cultural references that were made, and so on. MPlayer supports its own rather simple subtitle format that you can use to add custom subtitles to your favorite videos. You might use this to add legitimate translated subtitles to a movie, or as you'll see in the section "A Sample .sub File," your own off-the-wall commentary on a movie. Think Mystery Science Theater 3000, but with text.

The MPlayer subtitle format was designed to be particularly easy to create and edit. There are only a few fields to worry about, as you can see from the beginning of this example:

 TITLE=Pulp Fiction TYPE=VIDEO FORMAT=TIME 0 2 Welcome to Pulp Fsckion  

The first field, TITLE, simply labels the name of the video that this subtitle goes with, in this case Pulp Fiction. You can choose whatever name you like, but it makes sense to name it something that associates it with the movie it is with. The second field labels what type of file the subtitle will be played with, and the FORMAT field specifies whether the following numbers refer to seconds (TIME) or frames (use a number, such as 25, for the argument).

Where the file gets interesting is in the next line, 0 2. This field always precedes some text to display as a subtitle. The first number specifies how long to wait after the previous subtitle disappears before appearing. In this case, since this is the first subtitle, I specified zero, but if you wanted to bypass some opening credits, you might increase this number. The second number specifies how long to display the following subtitle on the screen. In this example I chose to display for two seconds.

Probably the most difficult part of creating your own subtitles is timing. You might find that you must watch a scene multiple times so that the subtitles sync with the dialogue perfectly. Remember that each subtitle's numbers are based on the timing of any preceding subtitles, so if you adjust the amount of time a subtitle is displayed, you will need to adjust the amount of time before the next subtitle displays as well, so that everything remains synched.

After you have created your subtitle file, name it after the video it goes with so it's easy to find. Many people use .sub as the file extensions for these files. When you are ready to play back, add the -sub argument to mplayer, followed by the path to your subtitle file:

 $ mplayer -sub video.sub video.avi 

The subtitles you specify will advance along with the movie, even if you skip ahead while viewing. Note, however, that the .sub file contains no chapter information, so if you skip a chapter in a DVD, when MPlayer starts playing on the advanced chapter it will still display the subtitles with the same timing.

3.7.1. A Sample .sub File

So, to give an example of how these subtitles work, I have created a series of subtitles for the second chapter (which is the first scene with dialogue) for the movie Pulp Fiction. The following subtitle assumes the video will begin with the contents of chapter two, so if you have ripped your DVD to a file, you may have to adjust the timing for the initial subtitle a bit so things display properly. Save the following file as pulp_fsckion.sub:

 TITLE=Pulp Fiction TYPE=VIDEO FORMAT=TIME 0 2 Welcome to Pulp Fsckion 0 4 Forget it, it's too risky, never dist-upgrading again. 0 2 You always say that… 0 3 "I'm through, never dist-upgrading again… too dangerous" 0 2.5 I know that's what I always say, and I'm always right. 0 2 But you trash your system after a day or two… 0 4 The days of my trashing my system are over, The days of installing packages right has just begun 0 2 You know when you go on like this, what you sound like? 0 1.5 I sound like a sensible sysadmin 0 2 You sound like a penguin *quack*quack*quack* 1 3 Well, since I'm never going to dist-upgrade again 0 3 You're never going to have to fix my system for me again 0 2 After tonight's upgrade… 11 3 Way it is now, you take the same risks as a --force 2 2 Take more of a risk, apt-get is easier… 0 3 You know --force doesn't stop you in any way when you are upgrading… 2 3 Don't even need dependencies when ya --force… 

With this file saved, pop the Pulp Fiction DVD into your computer and type:

 $ mplayer dvd://1 -chapter 2 -sub pulp_fsckion.sub 

The subtitles should start immediately and should be pretty well synched to the action. Feel free to add your own dialogue to the file.




Linux Multimedia Hacks
Linux Multimedia Hacks
ISBN: 596100760
EAN: N/A
Year: 2005
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net