-
Notifications
You must be signed in to change notification settings - Fork 0
/
bc-dvd2srt.pl
executable file
·60 lines (43 loc) · 1.25 KB
/
bc-dvd2srt.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/perl
# attempts to use closed captioning (not subtitles) to create an srt
# file for a DVD.
#
# REQUIRES MY EDITED VERSION OF MPLAYER (see .c files in this directory)
require "/usr/local/lib/bclib.pl";
# determine number of titles
$tits = `mplayer dvd://1 -frames 0 -vo null -ao null`;
unless ($tits=~/there are (\d+) titles on this dvd./is) {
die "Can't determine number of titles";
}
$tits = $1;
# go through each title and count chapters
for $i (1..$tits) {
# extract cc as fast as possible
# TODO: printing file while reading is inefficient
open(A,"mplayer -subcc 1 -speed 100 -nosound -vo null dvd://$i 2>&1|");
while(<A>) {
chomp;
# if this line is a timestamp, record it and move on
if (/v:\s+(.*?)\s+/i) {
$time = $1;
next;
}
# if time hasnt been set at all yet, ignore lines
unless ($time) {next;}
debug("TIME: $time");
# find milliseconds as 3 digits (strftime doesnt do this?)
$milli = sprintf("%0.3d",($time-int($time))*1000);
# convert time to SRT format
$str = strftime("%H:%M:%S",gmtime($time));
debug("STR: $str,$milli");
# this probably wont work, early test only
$count++;
print << "MARK";
$count
$str,$milli --> $str,$milli
$_
MARK
;
}
die "TESTING";
}