Adding Captions and Transcripts to Videos

Tutorial 2 of 5

1. Introduction

This tutorial aims to guide you on how to make your video content more accessible by adding captions and transcripts using HTML. Captions and transcripts make your videos more accessible to a broader audience, especially those who are hard of hearing.

By the end of this tutorial, you will learn:
- How to add captions to videos using HTML
- How to add transcripts to videos using HTML

Prerequisites:
- Basic understanding of HTML (HyperText Markup Language)

2. Step-by-Step Guide

HTML Track Element:

HTML provides the <track> element which is used to specify text tracks for media elements (<audio> and <video>). The text tracks are specified as subtitles, captions, descriptions, chapters, or metadata. The source for the track file is given with the src attribute, and the kind of text track is specified with the kind attribute.

Adding Captions:

Captions are similar to dialogue-only subtitles, in addition to which they also include relevant parts of the soundtrack — representing background noises, phone rings, or other significant sounds.

To add captions to a video:

  1. Convert your captions into a WebVTT (.vtt) file. WebVTT stands for "Web Video Text Tracks". It is a format for captions, subtitles, and screen descriptions, chapters, and metadata.

  2. Add a <track> element inside your <video> element with the kind attribute set to "captions", src attribute pointing to your .vtt file, and label attribute for user-readable title.

Adding Transcripts:

Transcripts are a text version of the speech and non-speech audio information needed to understand the content. They may include the same language as the original audio or a translation to another language.

To add transcripts to a video, you can place the text of the transcript below the video, inside a <div> or <p> tag. You could also make the transcript interactive by synchronizing it with the video.

3. Code Examples

Adding Captions:

<video controls>
   <source src="myVideo.mp4" type="video/mp4">
   <track kind="captions" src="captions_en.vtt" srclang="en" label="English">
</video>

Explanation:

  • The <video> tag is used to embed video content.
  • The <source> tag is used to specify multiple media resources for media elements, such as <video>, <audio>, <picture>, and <iframe>.
  • The <track> tag is used to specify external text track resources, such as captions, subtitles, etc.

Adding Transcripts:

<video id="myVideo" controls>
   <source src="myVideo.mp4" type="video/mp4">
</video>

<div id="transcript">
   <p>Transcript: Hello, welcome to our tutorial...</p>
</div>

Explanation:

  • The <div> tag defines a division or a section in an HTML document.
  • The <p> tag defines a paragraph.

4. Summary

We have learned how to use HTML to add captions and transcripts to videos, making them accessible to a wider audience. You can now try adding captions and transcripts to a video of your choice.

5. Practice Exercises

  1. Add English and Spanish captions to a video.
<!-- Your code here -->
  1. Add a transcript to a video and style it with CSS.
<!-- Your code here -->

Solutions:

  1. Adding English and Spanish captions:
<video controls>
   <source src="myVideo.mp4" type="video/mp4">
   <track kind="captions" src="captions_en.vtt" srclang="en" label="English">
   <track kind="captions" src="captions_es.vtt" srclang="es" label="Spanish">
</video>
  1. Adding a transcript and styling it with CSS:
<video id="myVideo" controls>
   <source src="myVideo.mp4" type="video/mp4">
</video>

<div id="transcript" style="font-size:16px; color:blue;">
   <p>Transcript: Hello, welcome to our tutorial...</p>
</div>

To further practice, try adding more languages to the captions and changing the style of the transcript. You can also try to make the transcript interactive by synchronizing it with the video.