-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathsubtitles-and-captions.html
More file actions
526 lines (472 loc) · 16.4 KB
/
subtitles-and-captions.html
File metadata and controls
526 lines (472 loc) · 16.4 KB
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cloudinary Video Player</title>
<link href="https://res.cloudinary.com/cloudinary-marketing/image/upload/f_auto,q_auto/c_scale,w_32/v1597183771/creative_staging/cloudinary_internal/Website/Brand%20Updates/Favicon/cloudinary_web_favicon_192x192.png" rel="icon" type="image/png">
<!-- Bootstrap -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- highlight.js -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/solarized-light.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<!--
We're loading scripts & style dynamically for development/testing.
Real-world usage would look like this:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cloudinary-video-player/dist/cld-video-player.min.css">
<script src="https://cdn.jsdelivr.net/npm/cloudinary-video-player/dist/cld-video-player.min.js"></script>
-->
<script type="text/javascript" src="./scripts.js"></script>
<script type="text/javascript">
window.addEventListener('load', function(){
var player = cloudinary.videoPlayer('player', {
cloud_name: 'demo'
});
player.source(
'video-player/stubhub',
{
textTracks: {
captions: {
label: 'English captions',
language: 'en',
default: true,
url: 'https://res.cloudinary.com/demo/raw/upload/v1636972013/video-player/vtt/Meetup_english.vtt'
},
subtitles: [
{
label: 'German subtitles',
language: 'de',
url: 'https://res.cloudinary.com/demo/raw/upload/v1636970250/video-player/vtt/Meetup_german.vtt'
},
{
label: 'Russian subtitles',
language: 'ru',
url: 'https://res.cloudinary.com/demo/raw/upload/v1636970275/video-player/vtt/Meetup_russian.vtt'
}
]
}
}
);
// Playlist
var playlist = cloudinary.videoPlayer('playlist', {
cloud_name: 'demo'
});
var source1 = {
publicId: 'video-player/stubhub',
info: { title: 'Subtitles & Captions playlist' },
textTracks: {
captions: {
label: 'English captions',
language: 'en',
default: true,
url: 'https://res.cloudinary.com/demo/raw/upload/v1636972013/video-player/vtt/Meetup_english.vtt'
},
subtitles: [
{
label: 'German subtitles',
language: 'de',
url: 'https://res.cloudinary.com/demo/raw/upload/v1636970250/video-player/vtt/Meetup_german.vtt'
},
{
label: 'Russian subtitles',
language: 'ru',
url: 'https://res.cloudinary.com/demo/raw/upload/v1636970275/video-player/vtt/Meetup_russian.vtt'
}
]
}
};
var source2 = {
publicId: 'video-player/outdoors',
info: { title: 'Outdoors', subtitle: 'Outdoors movie with captions' },
textTracks: {
captions: {
label: 'English captions',
language: 'en',
default: true,
url: 'https://res.cloudinary.com/demo/raw/upload/v1636971261/video-player/vtt/outdoors.vtt',
}
}
};
var source3 = {
publicId: 'video-player/dog',
info: { title: 'Dog', subtitle: 'Video of a dog, no captions' }
};
var playlistSources = [source1, source2, source3];
var playlistOptions = {
autoAdvance: true,
repeat: true,
presentUpcoming: 8
};
playlist.playlist(playlistSources, playlistOptions);
// Paced
const pacedPlayer = cloudinary.videoPlayer('paced', {
cloudName: 'demo'
});
const publicId = 'lincoln';
const textTracks = {
options: {
// theme: "", // one of 'default', 'videojs-default', 'yellow-outlined', 'player-colors' & '3d'
// fontFace: "", // any Google font
// fontSize: "", // any CSS value
// gravity: "", // i.e. 'top-left', 'center' etc
// box: { // Object of x/y/width/height
// x: "0%",
// y: "0%",
// width: "100%",
// height: "100%"
// },
// style: { // Styles key-value object
// color: "hotpink"
// }
},
captions: {
label: 'English Paced',
maxWords: 4,
default: true,
},
subtitles: [
{
label: 'German subtitles',
language: 'de',
url: 'https://res.cloudinary.com/demo/raw/upload/v1636970250/video-player/vtt/Meetup_german.vtt'
},
{
label: 'Russian subtitles',
language: 'ru',
url: 'https://res.cloudinary.com/demo/raw/upload/v1636970275/video-player/vtt/Meetup_russian.vtt'
}
]
}
pacedPlayer.source(publicId, {
textTracks
});
const maxWordsInput = document.getElementById('maxWords');
const themeSelect = document.getElementById('theme');
const fontSelect = document.getElementById('font');
const gravitySelect = document.getElementById('gravity');
const applyButton = document.getElementById('apply');
applyButton.addEventListener('click', function () {
textTracks.captions.maxWords = parseInt(maxWordsInput.value);
textTracks.options.theme = themeSelect.value;
textTracks.options.fontFace = fontSelect.value;
textTracks.options.gravity = gravitySelect.value;
pacedPlayer.source(publicId, {
textTracks
});
});
// Karaoke
const karaokePlayer = cloudinary.videoPlayer('karaoke', {
cloudName: 'demo'
});
karaokePlayer.source('lincoln', {
textTracks: {
options: {
fontFace: 'Lobster',
fontSize: '200%',
gravity: 'top',
wordHighlightStyle: {
color: 'white',
'text-shadow': `2px 2px 0px violet,
4px 4px 0px indigo,
6px 6px 0px blue,
8px 8px 0px green,
10px 10px 0px yellow,
12px 12px 0px orange,
14px 14px 0px red`
}
},
captions: {
label: 'KARAOKE',
wordHighlight: true,
maxWords: 5,
timeOffset: -0.2,
default: true
}
}
});
// Transcript from URL
const urlTranscriptPlayer = cloudinary.videoPlayer('url-transcript', {
cloudName: 'demo'
});
urlTranscriptPlayer.source('elephants', {
textTracks: {
captions: {
label: "Lincoln's Transcript",
url: 'https://res.cloudinary.com/demo/raw/upload/lincoln.transcript',
wordHighlight: true,
maxWords: 8
}
}
});
}, false);
</script>
</head>
<body>
<div class="container p-4 col-12 col-md-9">
<nav class="nav mb-2">
<a href="./index.html"><< Back to examples index</a>
</nav>
<h1>Cloudinary Video Player</h1>
<h3 class="mb-4">Subtitles & Captions</h3>
<video
id="player"
playsinline
controls
class="cld-video-player cld-fluid"
crossorigin="anonymous"
width="500"
></video>
<h4 class="mt-4 mb-2">Playlist Subtitles (switch per source)</h4>
<video
id="playlist"
playsinline
controls
class="cld-video-player cld-fluid"
crossorigin="anonymous"
width="500"
></video>
<h4 class="mt-4 mb-2">Paced & Styled Captions</h4>
<form>
<label for="maxWords">Max Words</label>
<input type="number" id="maxWords" name="maxWords" min="1" max="100" value="4" />
<label for="theme">Theme</label>
<select id="theme" name="theme">
<option value="default" selected>Default</option>
<option value="videojs-default">VideoJS Default</option>
<option value="player-colors">Player Colors</option>
<option value="yellow-outlined">Yellow Outlined</option>
<option value="3d">3D</option>
</select>
<label for="font">Font</label>
<select id="font" name="font">
<option value="Inter" selected>Inter</option>
<option value="Ceviche One">Ceviche One</option>
<option value="Merienda">Merienda</option>
<option value="Ultra">Ultra</option>
<option value="Kavoon">Kavoon</option>
<option value="Erica One">Erica One</option>
<option value="Corben">Corben</option>
<option value="Bungee Spice">Bungee Spice (Color)</option>
<option value="Nabla">Nabla (Color)</option>
</select>
<label for="gravity">Gravity</label>
<select id="gravity" name="gravity">
<option value="bottom" selected>Bottom</option>
<option value="bottom-left">Bottom Left</option>
<option value="bottom-right">Bottom Right</option>
<option value="top">Top</option>
<option value="top-left">Top Left</option>
<option value="top-right">Top Right</option>
<option value="center">Center</option>
<option value="center-left">Center Left</option>
<option value="center-right">Center Right</option>
</select>
<button type="button" id="apply">Apply</button>
</form>
<video
id="paced"
playsinline
controls
class="cld-video-player cld-fluid"
crossorigin="anonymous"
width="500"
></video>
<h4 class="mt-4 mb-2">Karaoke player</h4>
<video
id="karaoke"
playsinline
controls
class="cld-video-player cld-fluid"
crossorigin="anonymous"
width="500"
></video>
<h4 class="mt-4 mb-2">Transcript from URL</h4>
<video
id="url-transcript"
playsinline
controls
class="cld-video-player cld-fluid"
crossorigin="anonymous"
width="500"
></video>
<p class="mt-4">
<a href="https://cloudinary.com/documentation/cloudinary_video_player">Full documentation</a>
</p>
<h3 class="mt-4">Example Code:</h3>
<pre>
<code class="language-html">
<video
id="player"
controls
class="cld-video-player"
crossorigin="anonymous"
width="500">
</video>
<!-- ... a few more <video> tags -->
</code>
<code class="language-javascript">
// Initialize players
var player = cloudinary.videoPlayer('player', { cloud_name: 'demo' });
player.source(
'video-player/stubhub',
{
textTracks: {
captions: {
label: 'English captions',
language: 'en',
default: true,
url: 'https://res.cloudinary.com/demo/raw/upload/v1636972013/video-player/vtt/Meetup_english.vtt'
},
subtitles: [
{
label: 'German subtitles',
language: 'de',
url: 'https://res.cloudinary.com/demo/raw/upload/v1636970250/video-player/vtt/Meetup_german.vtt'
},
{
label: 'Russian subtitles',
language: 'ru',
url: 'https://res.cloudinary.com/demo/raw/upload/v1636970275/video-player/vtt/Meetup_russian.vtt'
}
]
}
}
);
// Playlist
var playlist = cloudinary.videoPlayer('playlist', { cloud_name: 'demo' });
var source1 = {
publicId: 'video-player/stubhub',
info: { title: 'Subtitles & Captions playlist' },
textTracks: {
captions: {
label: 'English captions',
language: 'en',
default: true,
url: 'https://res.cloudinary.com/demo/raw/upload/v1636972013/video-player/vtt/Meetup_english.vtt'
},
subtitles: [
{
label: 'German subtitles',
language: 'de',
url: 'https://res.cloudinary.com/demo/raw/upload/v1636970250/video-player/vtt/Meetup_german.vtt'
},
{
label: 'Russian subtitles',
language: 'ru',
url: 'https://res.cloudinary.com/demo/raw/upload/v1636970275/video-player/vtt/Meetup_russian.vtt'
}
]
}
};
var source2 = {
publicId: 'video-player/outdoors',
info: { title: 'Outdoors', subtitle: 'Outdoors movie with captions' },
textTracks: {
captions: {
label: 'English captions',
language: 'en',
default: true,
url: 'https://res.cloudinary.com/demo/raw/upload/v1636971261/video-player/vtt/outdoors.vtt',
}
}
};
var source3 = {
publicId: 'video-player/dog',
info: { title: 'Dog', subtitle: 'Video of a dog, no captions' }
};
var playlistSources = [source1, source2, source3];
var playlistOptions = {
autoAdvance: true,
repeat: true,
presentUpcoming: 8
};
playlist.playlist(playlistSources, playlistOptions);
// Paced
const pacedPlayer = cloudinary.videoPlayer('paced', {
cloudName: 'demo'
});
pacedPlayer.source('lincoln', {
textTracks: {
options: {
// theme: "", // one of 'default', 'videojs-default', 'yellow-outlined', 'player-colors' & '3d'
// fontFace: "", // any Google font
// fontSize: "", // any CSS value
// gravity: "", // i.e. 'top-left', 'center' etc
// box: { // Object of x/y/width/height
// x: "0%",
// y: "0%",
// width: "100%",
// height: "100%"
// },
// style: { // Styles key-value object
// color: "hotpink"
// }
},
captions: {
label: 'English Paced',
maxWords: 4,
default: true
},
subtitles: [
{
label: 'German subtitles',
language: 'de',
url: 'https://res.cloudinary.com/demo/raw/upload/v1636970250/video-player/vtt/Meetup_german.vtt'
},
{
label: 'Russian subtitles',
language: 'ru',
url: 'https://res.cloudinary.com/demo/raw/upload/v1636970275/video-player/vtt/Meetup_russian.vtt'
}
]
}
});
// Karaoke
const karaokePlayer = cloudinary.videoPlayer('karaoke', {
cloudName: 'demo'
});
karaokePlayer.source('lincoln', {
textTracks: {
options: {
fontFace: 'Lobster',
fontSize: '200%',
gravity: 'top',
wordHighlightStyle: {
color: 'white',
'text-shadow': `2px 2px 0px violet,
4px 4px 0px indigo,
6px 6px 0px blue,
8px 8px 0px green,
10px 10px 0px yellow,
12px 12px 0px orange,
14px 14px 0px red`
}
},
captions: {
label: 'KARAOKE',
wordHighlight: true,
maxWords: 5,
timeOffset: -0.2,
default: true
}
}
});
// Transcript from URL
const urlTranscriptPlayer = cloudinary.videoPlayer('url-transcript', {
cloudName: 'demo'
});
urlTranscriptPlayer.source('elephants', {
textTracks: {
captions: {
label: "Lincoln's Transcript",
url: 'https://res.cloudinary.com/demo/raw/upload/lincoln.transcript',
wordHighlight: true,
maxWords: 8
}
}
});
</code>
</pre>
</div>
</body>
</html>