Captions
captions burns captions into the picture, so they show wherever the clip is posted.
await createSplice({ source, start, end, captions: '/video/interview.en.vtt' })
It takes any of:
| Value | Read as |
|---|---|
CaptionCue[] | { start, end, text } on the source's timeline, in seconds |
a string from WEBVTT | The text of a WebVTT file |
any other string, URL | The address of a WebVTT file, fetched (CORS applies) |
Only the cues inside the clip's range are drawn. Only WebVTT is read; convert SRT first.
What's read
Timing and text. Headers, NOTE and STYLE blocks, cue ids and cue settings are skipped, cue markup (<v Speaker>, <i>) is stripped, and a cue whose timing line can't be read is dropped rather than failing the file.
The look
Bold white text on a translucent dark box per line, wrapping to fit. Sizes are fractions of the frame, so a caption looks the same at every output size.
Style
captionStyle changes any of the look; leave out what you don't change.
| Field | Default | Description |
|---|---|---|
fontFamily | the system sans-serif | CSS font family |
fontWeight | 700 | CSS font weight |
size | 0.045 | Font size, as a fraction of the frame's height |
color | white | Text colour |
background | 'rgba(0, 0, 0, 0.6)' | The box behind each line; null for none |
margin | 0.14 | Distance from the top or bottom edge, of the height |
maxWidth | 0.86 | Widest a line runs before wrapping, of the width |
await createSplice({
source,
start,
end,
captions,
captionStyle: {
fontFamily: 'Georgia, serif',
color: '#ffd400',
background: null,
},
})
Position
captionPosition puts the caption block at the 'bottom' (the default), the 'top' or in the 'middle'. Top and bottom sit 14% of the frame's height in from the edge, clear of what short-form apps draw over a vertical video.
await createSplice({
source,
start,
end,
captions: '/video/interview.en.vtt',
captionPosition: 'top',
})
When they can't be loaded
A caption file that can't be fetched, answers with an HTTP error or isn't WebVTT (an HTML error page served as 200, say) leaves the clip without captions and warns through onWarning, rather than failing the clip.
From a player
In the editor, the captions burned in are the ones the viewer has on in the player, at the position chosen in the panel, read from the <video>'s text tracks. That covers WebVTT tracks and HLS subtitles, which hls.js and Safari add as text tracks.