[MPlayer-dev-eng] [PATCH] subedit.pl - piped editing of SRT subtitles

Michael Klepikov mike72 at mail.ru
Tue Mar 30 08:56:29 CEST 2004


New script: main/TOOLS/subedit.pl
Patch applies with "patch -p1". The script should have an execute permission.

This is a new script, not a patch to any existing code.

I looked for a Linux tool to edit timing in SRT subtitles (shift, scale, 
split, merge), there's ksubeditor which built but didn't really work, there 
are a few others that also didn't really work, at least not on SRT or 
anything that MPlayer can convert from/to SRT. So I decided to write my own 
simple script and contribute it to MPlayer.

If you think about it, GUI is really unnecessary for the operations like the 
ones I mentioned. In fact, traditional UNIX piping works exceptionally well: 
pipe subtitles into shift, then into scale, then into shift again; or shift a 
second part of a two-file set, cat it together with the first part, and 
renumber. See examples which the script prints with --help.

So far it only supports the SRT format, but more formats could be added. I 
preferred SRT over mpsub as the format for timing modifications, because 
mpsub would potentially accumulate a rounding error, while SRT doesn't. The 
mpsub format allows to do shift, split, and merge very easily, but not scale. 
MPlayer itself also can't scale subtitle timing, as far as I know. The 
differences per subtitle upon scaling could be really minute -- less than a 
millisecond per subtitle, while by default mpsub represents timings up to 
hundredths only, which is insufficient to, for example, stretch a file with a 
couple of thousand subtitles by one second. I used big integer arithmetics in 
the script to get scaled timings as precisely as possible, and the precision 
is independent of the total number of subtitles in the stream.

Please CC by email all criticism and/or modification requests.

Thanks.

--Michael Klepikov

-------------- next part --------------
A non-text attachment was scrubbed...
Name: subedit.pl.patch
Type: text/x-diff
Size: 13786 bytes
Desc: main/TOOLS/subedit.pl
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20040330/60211b8b/attachment.patch>


More information about the MPlayer-dev-eng mailing list