-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.html
221 lines (208 loc) · 5.91 KB
/
index.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE html>
<html xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head>
<title>Converting SRT files to WebVTT files</title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<style>
table {
width: 80%;
background-color: rgb(241,241,241);
border: gray 1px solid;
border-collapse: collapse;
}
table thead {
background-color: rgb(80,144,240);
}
table td, table th {
border: gray 1px solid;
padding: 7px;
}
table body tr {
background: #b8d1f3;
}
table tbody tr:hover {
background-color: rgb(174,211,248);
}
</style>
</head>
<body>
<h1>WebVTT support in browsers</h1>
<table>
<thead>
<tr>
<th>Feature</th>
<th>Chrome/Opera</th>
<th>Firefox</th>
<th>Internet Explorer</th>
<th>Safari</th>
</tr>
</thead>
<tbody>
<tr>
<td>Required Header</td>
<td>WEBVTT</td>
<td>WEBVTT</td>
<td>WEBVTT FILE</td>
<td>WEBVTT</td>
</tr>
<tr>
<td>File MIME Type</td>
<td>sniffing</td>
<td>sniffing</td>
<td>'text/vtt'</td>
<td>sniffing</td>
</tr>
<tr>
<td>Menu in video controls to select tracks</td>
<td>CC button</td>
<td></td>
<td>✔</td>
<td>✔</td>
</tr>
<tr>
<td>JavaScript TextTrack API</td>
<td>✔</td>
<td>✔</td>
<td>✔</td>
<td>✔</td>
</tr>
<tr>
<td>Rendering of text-only captions & subtitles</td>
<td>✔</td>
<td>✔</td>
<td>✔</td>
<td>✔</td>
</tr>
<tr>
<td>Cue styling with ::cue and ::cue()</td>
<td>✔</td>
<td></td>
<td></td>
<td>✔</td>
</tr>
<tr>
<td>Cue markup incl. Timestamps</td>
<td>✔</td>
<td>✔</td>
<td></td>
<td>✔</td>
</tr>
<tr>
<td>Vertical Cue setting</td>
<td>✔ (buggy)</td>
<td></td>
<td></td>
<td>✔</td>
</tr>
<tr>
<td>Line, Align, Position, Size Cue settings</td>
<td>✔</td>
<td>✔</td>
<td></td>
<td>✔</td>
</tr>
<tr>
<td>Comments (NOTE)</td>
<td>✔</td>
<td>✔</td>
<td></td>
<td>✔</td>
</tr>
<tr>
<td>Regions</td>
<td>Behind Flag</td>
<td></td>
<td></td>
<td>Behind Flag</td>
</tr>
<tr>
<td>Rendering of text descriptions</td>
<td>With extension</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Rendering of chapters</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<h1>Converting SRT files to WebVTT files</h1>
<h4>Cut and paste SRT file into text entry box:</h4>
<textarea cols="80" id="srt" name="content" rows="20"></textarea>
<button onclick="convert()">Convert</button>
<div id="webvtt"></div>
<script>
function convert() {
var input = document.getElementById("srt");
var output = document.getElementById("webvtt");
var srt = input.value;
var webvtt = srt2webvtt(srt);
output.innerHTML = "<textarea rows=20 cols=80>"
+ webvtt +
"</textarea>";
}
function srt2webvtt(data) {
// remove dos newlines
var srt = data.replace(/\r+/g, '');
// trim white space start and end
srt = srt.replace(/^\s+|\s+$/g, '');
// get cues
var cuelist = srt.split('\n\n');
var result = "";
if (cuelist.length > 0) {
result += "WEBVTT\n\n";
for (var i = 0; i < cuelist.length; i=i+1) {
result += convertSrtCue(cuelist[i]);
}
}
return result;
}
function convertSrtCue(caption) {
// remove all html tags for security reasons
//srt = srt.replace(/<[a-zA-Z\/][^>]*>/g, '');
var cue = "";
var s = caption.split(/\n/);
// concatenate muilt-line string separated in array into one
while (s.length > 3) {
for (var i = 3; i < s.length; i++) {
s[2] += "\n" + s[i]
}
s.splice(3, s.length - 3);
}
var line = 0;
// detect identifier
if (!s[0].match(/\d+:\d+:\d+/) && s[1].match(/\d+:\d+:\d+/)) {
cue += s[0].match(/\w+/) + "\n";
line += 1;
}
// get time strings
if (s[line].match(/\d+:\d+:\d+/)) {
// convert time string
var m = s[1].match(/(\d+):(\d+):(\d+)(?:,(\d+))?\s*--?>\s*(\d+):(\d+):(\d+)(?:,(\d+))?/);
if (m) {
cue += m[1]+":"+m[2]+":"+m[3]+"."+m[4]+" --> "
+m[5]+":"+m[6]+":"+m[7]+"."+m[8]+"\n";
line += 1;
} else {
// Unrecognized timestring
return "";
}
} else {
// file format error or comment lines
return "";
}
// get cue text
if (s[line]) {
cue += s[line] + "\n\n";
}
return cue;
}
</script>
<p>Source code at <a href="https://github.com/silviapfeiffer/silviapfeiffer.github.io">Github</a>.</p>
<p>Thanks to David Desmeurs for his contribution.</p>
</body>
</html>