The Lumber Room

"Consign them to dust and damp by way of preserving them"

Archive for December 1st, 2006

Editing subtitles on Linux

leave a comment »

Note: This was written in 2006, so it’s probably out-dated by now.

First, the not-so-good ones:

There is Ksubtile (note: it’s not Ksubtitle!) which is a KDE app. It handles only SRTs (but I think it can import from other formats), and doesn’t even seem to have a way to change the framerate. Pretty useless, but if you want it, the package’s name is ksubtile.
Then there is gsubedit, but it hasn’t released a stable version since June 2002, so I’m guessing it’s dead (or it’s perfect ;-)).

Then the good ones:

But what is alive and good is subtitleeditor. debuntu.org has written a couple of articles and has it in its repository. Subtitleeditor seems to have almost everything one could possibly ask for (including spell-check and Find/Replace!). Update: subtitleeditor is available in universe on edgy; no need for an “outside” repository.

I also discovered gaupol, which seems to be much better. Because I hadn’t used subtitleditor much, I didn’t realise how many badly needed features are missing in it (especially Undo). The edgy repos have gaupol too (but it’s slightly broken).

Also recently added is libsubtitles-perl (install with perl -MCPAN -e 'install Subtitles'), which comes with a commandline tool called subs… it’s already my favourite :-)

Other things to do:

If you want to make your own subtitles, the tutorials Subtiteling with Linux and Linux Digital Fansubbing Guide might help.

For rudimentary tasks, it may not even be necessary to install anything: there is an Online Subtitle Synchronizer / FPS & Format Converter.

BTW, there’s one thing I’d very much like to know: Is there any hope at all for removing hard subtitles? Maybe some kind of clever pattern recognition and then filling the region with the local background colour? Something? :-(
(Update: I must try Subrip, AVISubDetector and Subtitle Workshop sometime… I think they promise to extract the subtitles from the video stream, but I don’t know if this means they can remove them…) In the meantime, mplayer has a “delogo” filter, intended for detecting fixed logos and removing them. It works, somewhat — it replaces the subtitles and interpolates from the surroundings, but leaves a rectangle which is somewhat blurred. For one particular video, I used
-vf delogo=120:250:400:70:-1,expand=:::::4/3
, or -vf expand=:::::4/3,delogo=120:320:400:70:-1. The parameters are x:y:w:h:t, where (x,y) are the coordinates of the top left of the rectangle (with origin at top left of the screen), and w and h its width and height. Remove the -1 after you have the right rectangle; it’s for a green border.

Some general info on subtitles (I use mplayer):

Sync

If the subtitle and audio are out of sync, first try using the `z` and `x` keys till you get them in sync. `z` rewinds (delays) the subtitles (makes them come later wrt the audio) (recalls subtitles that already went by), and `x` prepones the subtitles (makes the subtitles come earlier, gets subtitles from future). (Perversely, for reasons I don’t yet know, mplayer calls the former a negative “sub delay” and the latter a positive sub delay.)
If after some time they start falling out of sync again (one quick way to check is to seek forward or backward a few minutes and check if they are still in sync), then the problem is probably that the video and subtitles have different framerates (fps). To fix this, you must run mplayer with -subfps [correct_fps]. You might be able to find the correct fps at the place you downloaded the subtitle from ;-); else simply try the three values 23.976, 25, and 29.97; which work in most cases. (If *that* doesn’t work, try all three values for the video as well (-fps [value]). One of the nine pairs should hopefully work!)

Placement

`r` raises the subtitle, and `t` lowers it. (Or you could also start mplayer with -subpos [value])
I used to wonder whether it was possible to have the subtitles not covering the actual movie (there was usually some blank area below and above the actual movie content…), and I just discovered that it is! Basically, you have to expand the video so that some blank space is part of it, and then `r` and `t` will go into that blank space. Using -vf expand=0:-50:0:0 adds a 50-pixel blank space at the bottom of the video. (Leaving out the 0:0 and using only -vf expand=0:-50 adds the 50 pixels but centres the video, so that there are 25-pixel bars at the top and bottom.) Another way to get blank space would be to use -vf expand=:::::4/3 which means “Expand the video so that the aspect ratio is 4/3″. In fact, it may be a good idea to add either vf=expand=0:-50:0:0 or vf=expand=:::::4/3 to ~/.mplayer/config. (Update: Screen ratio is 16/10 on the MacBook.)

Written by S

Fri, 2006-12-01 at 16:11:37 +05:30

Follow

Get every new post delivered to your Inbox.

Join 68 other followers