by Alexander Thomas (aka Dr. Lex)
What is it?
This is a Perl script that can perform certain operations on SubRip (.srt) subtitle files. For instance, it can scale and offset the time stamps of all subtitles based on two pairs of current and expected time values. It can also check files for subtitles that appear overly long or too briefly, and attempt to fix the latter (which is of course not always possible).
It also offers an option to strip hearing aid annotations for those people who like to have subtitles of the dialogue without stuff like “[CLEARS THROAT]”.
As the version number shows I do not consider it to be a finished product, but in its current form it is already useful.
Download and Usage
This script can be run under any environment that has a Perl interpreter, like Linux, Mac OS X, or Windows with Cygwin or a native Perl implementation.
The download includes a README with additional info, and the script itself prints the following usage information when invoked with ‘-h’:
srtlab [options] file1.srt [file2.srt ...] > output.srt Multiple input files will be joined. You should make sure in such case that the time stamps do not overlap and the character encodings are the same. Options: Time values must be in the format [-]HH:MM:SS.sss, or a floating-point number representing seconds. -s S: scale all timestamps. S can be a floating-point number or any of these shortcuts: NTSCPAL: 0.95904 = 23.976/25 (subs for NTSC framerate to PAL video) PALNTSC: 1.04270938 = 25/23.976 (PAL framerate to NTSC) NTSCFILM: 0.999 = 23.976/24 (NTSC framerate to film) PALFILM: 1.04166667 = 25/24 (PAL framerate to film) FILMNTSC: 1.001001 = 24/23.976 (film framerate to NTSC) FILMPAL: 0.96 = 24/25 (film framerate to PAL) -o O: offset all timestamps by time O. Offset is added after scaling, i.e. new times are calculated as S*t+O. -a Ta1 Ta2 Tb1 Tb2: automatically calculate S and O. Ta1 is the time at which a subtitle appears in the current SRT file, Ta2 is where it should appear in the output. The same for Tb1 and Tb2, for another subtitle. For maximum accuracy, use the earliest possible subtitle for Ta and the last subtitle for Tb. -b Ta1 Ta2: like -a, but only calculate the offset O. -i I: insert a new subtitle at index I (in the original file). This command can be repeated, e.g. to insert two subs at index 3, use -ii 3 3. -j J: insert a new subtitle at original time J (can be repeated as well). -l: report subtitles that appear too briefly or overly long, or overlap. -L: report and attempt to repair subtitles that appear too briefly or overlap. -c: remove empty subtitles (empty = really empty, no whitespace characters). -r: maintain Redmond-style compatibility with typewriters (CRLF). If this option is not enabled, any existing CR will be obliterated. -u: save output in UTF-8. -m: add BOM character to output file if it is Unicode. -M: do not add BOM character to output file (default is same as input). -e: in-place editing: overwrite first file instead of printing to stdout (BE CAREFUL!) -t: strip all SRT formatting and only output the text. -H: attempt to remove typical non-verbal annotations in subs for the hearing impaired, e.g. (CLEARS THROAT). You may want to combine this with -c. Repeat -H to try to remove non-capitalized annotations. -v: verbose mode. -V: print version and exit.
- 0.9 (2009/08): unfinished
- 0.91 (2010/03): added CRLF option
- 0.92 (2010/04): split parser & renderer, added time check & fix
- 0.93 (2011/01): more robustness against crappy files
- 0.94 (2011/08): improved hearing-aid filtering
- 0.95 (2011/09): added extra hearing-aid filtering mode
- 0.96 (2012/07): overlap detection and removal
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.