Subtitles4j is a simple library which allows you to parse and manipulate subtitles files.
For the moment, only SubRip (srt) and Advanced SubStation Alpha (ass).
You can easily parse, write and convert files thanks to Subtitles4jFactory
.
// Getting the factory
Subtitles4jFactory factory = Subtitles4jFactory.getInstance();
// From a File
File inputFile = new File("/an/input/file.srt");
// The input type is deducted from the extension
SubtitlesContainer container = factory.fromFile(inputFile);
// From an InputStream
InputStream is = new FileInputStream(inputFile);
// The input type must be provided
container = factory.fromStream(is, SubtitlesType.SRT);
// To a File
File outputFile = new File("/an/output/file.ass");
factory.toASS(container, outputFile);
// To an OutputStream
FileOutputStream os = new FileOutputStream(outputFile);
factory.toASS(container, os);
// File to File
factory.toASS(inputFile, outputFile);
// InputStream to OutputStream
factory.toASS(is, SubtitlesType.SRT, os);
The utility class Subtitles4jUtils
allows you to perform operation on subtitles files.
// From a File, add 250 ms to every timestamp
Subtitles4jUtils.shift(inputFile, 250);
// From an InputStream, remove 150 ms to every timestamp
Subtitles4jUtils.shift(is, SubtitlesType.SRT, os, -150);
// From a File, remove all captions matching the pattern
Subtitles4jUtils.removeCaptions(inputFile, "some pattern");
// From an InputStream, remove all captions matching the pattern
Subtitles4jUtils.removeCaptions(is, SubtitlesType.SRT, os, "some pattern");