NAME
GoSaveTool::Subtitles - Parse, convert, shift and repair SRT and WebVTT subtitles
SYNOPSIS
use GoSaveTool::Subtitles qw(parse convert shift_cues repair to_srt to_vtt);
my $vtt = convert($srt_text, 'vtt');
my $cues = parse($text); # [ { start => 1000, end => 3500, settings => '', text => 'Hello' }, ... ]
my $later = to_srt(shift_cues($cues, 1500));
my ($fixed_cues, $n) = repair($cues);
print "$n problems fixed\n";
DESCRIPTION
The Perl version of the @gosavetool/subtitles JavaScript package, from GoSaveTool. Online editor: https://www.gosavetool.com/vtt-subtitle-generator. No dependencies outside the core.
FUNCTIONS
Nothing is exported by default. Times are in milliseconds.
- parse($text)
-
Array reference of cues (hash references with
start,end,settingsandtext) of an SRT or WebVTT text. Headers, NOTE and STYLE blocks are skipped. - to_srt($cues), to_vtt($cues), convert($text, 'srt' | 'vtt')
-
Write cues. WebVTT cue settings are kept.
- shift_cues($cues, $ms)
-
New cues moved by
$ms(negative = earlier). Cues pushed before zero are clipped or dropped. - repair($cues, $min_duration)
-
Returns the repaired cues and the number of changes: cues sorted, end times before the start set to
$min_duration(2000) after it, overlapping cues ended before the next one, empty cues dropped. The input is not changed. - to_ms($stamp), from_ms($ms, $separator), is_vtt($text)
-
"00:01:02,500"to 62500 (undef when it is not a timestamp), back, and whether the text starts withWEBVTT.
SEE ALSO
AUTHOR
GoSaveTool https://www.gosavetool.com/
LICENSE
MIT License. See the LICENSE file.