brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: an HTML track element adds captions to your own video with a small text file

Html
~/tips/tip-html-track-captions

srclang="en" label="English" default>

Offer subtitles on a self hosted video with a WebVTT file.

If you host a video yourself, captions are not something you have to burn into the picture. A text file next to the video does the job, and viewers can switch it off.

<video controls width="640">
  <source src="demo.mp4" type="video/mp4">
  <track kind="captions" src="demo.vtt"
         srclang="en" label="English" default>
</video>

The file is WebVTT, which you can write in any editor:

WEBVTT

00:00:01.000 --> 00:00:04.000
First we open the settings page.

00:00:04.500 --> 00:00:06.000
[notification sound]

The first line must be WEBVTT, and a blank line separates the cues. Use kind="captions" when you include sounds as well as speech, and kind="subtitles" for translations. Add one track per language. default turns that one on.

Browsers load the file under the same rules as other cross origin resources, so keep it on the same host as the page, or set up CORS and add crossorigin to the video. Opening the page straight from disk often shows no captions for the same reason; test through a local web server. I would watch it once with the sound off to check the timing.

Further reading: MDN: the track element

More Html tips import { format } from "dates"; width="640" height="360" poster="demo.jpg"> The HTML optgroup element puts headings inside a long dropdown An HTML noindex meta tag keeps one page out of search results title="Example blog" href="/feed.xml"> All Html tips (14) All topics

Link