In other articles we looked at how to build a cross browser video player using the HTMLMediaElement
and Window.fullScreen
APIs, and also at how to style the player. This article will take the same player and show how to add captions and subtitles to it, using the WebVTT format
and the <track>
element.
Captioned video example
In this article, we will refer to the Video player with captions example. This example uses an excerpt from the Sintel open movie, created by the Blender Foundation.
Note: You can find the source on Github, and also view the example live.
HTML5 and Video Captions
Before diving into how to add captions to the video player, there are a number of things that we will first mention, which you should be aware of before we start.
Captions versus subtitles
Captions and subtitles are not the same thing: they have significantly different audiences, and convey different information, and it is recommended that you read up on the differences if you are not sure what they are. They are however implemented in the same way technically, so the material in this article will apply to both.
In other articles we looked at how to build a cross browser video player using the HTMLMediaElement and Window.fullScreen APIs, and also at how to style the player. This article will take the same player and show how to add captions and subtitles to it, using the WebVTT format and the track element.
For this article we will refer to the text tracks displayed as subtitles, as their content is aimed at hearing people who have difficulty understanding the language of the film, rather than deaf or hard-of-hearing people.
The <track> element
HTML5 allows us to specify subtitles for a video using the <track>
element. The various attributes of this element allow us to specify such things as the type of content that we're adding, the language it's in, and of course a reference to the text file that contains the actual subtitle information.
WebVTT
The files that contain the actual subtitle data are simple text files that follow a specified format, in this case the Web Video Text Tracks (WebVTT) format. The WebVTT specification is still being worked on, but major parts of it are stable so we can use it today.
Video providers (such as the Blender Foundation) provide captions and subtitles in a text format with their videos, but they're usually in the SubRip Text (SRT) format. These can be easily converted to WebVTT using an online converter such as srt2vtt.
Modifications to the HTML and CSS
This section summarises the modifications made to the previous article's code in order to facilitate the addition of subtitles to the video. If you are not interested in this, and just want to get straight into the JavaScript and more relevant CSS, skip to the Subtitle implementation section.
In this example we are using a different video, Sintel, as it actually has some speech in it and therefore is better for illustrating how subtitles work!
HTML Markup
As mentioned above, we need to make use of the new HTML5 <track>
element to add our subtitle files to the HTML5 video. We actually have our subtitles in three different languages — English, German, and Spanish — so we will reference all three of the relevant VTT files by adding <track>
elements inside our HTML5 <video>
element:
As you can see, each <track>
element has the following attributes set:
kind
is given a value ofsubtitles
, indicating the type of content the files containlabel
is given a value indicating which language that subtitle set is for — for exampleEnglish
orDeutsch
— these labels will appear in the user interface to allow the user to easily select which subtitle language they want to see.src
is assigned a valid URL pointing to the relevant WebVTT subtitle file in each case.srclang
indicates what language each subtitle files' contents are in.- The
default
attribute is set on the English<track>
element, indicating to the browser that this is the default subtitle file definition to use when subtitles have been turned on and the user has not made a specific selection.
In addition to adding the <track>
elements, we have also added a new button to control the subtitles menu that we will build. As a consequence, the video controls now look as follows:
CSS Changes
The video controls have undergone some minor changes in order to make space for the extra button, but these are relatively straightforward.
No image is used for the captions button, so it is simply styled as:
There are also other CSS changes that are specific to some extra JavaScript implementation, but these will be mentioned at the appropriate place below.
Subtitle implementation
A lot of what we do to access the video subtitles revolves around JavaScript. Similar to the video controls, if a browser supports HTML5 video subtitles, there will be a button provided within the native control set to access them. However, since we have defined our own video controls, this button is hidden, and we need to define our own.
Browsers do vary as to what they support, so we will be attempting to bring a more unified UI to each browser where possible. There's more on browser compatibility issues later on.
Initial setup
As with all the other buttons, one of the first things we need to do is store a handle to the subtitles' button:
We also initially turn off all subtitles, in case the browser turns any of them on by default:
The video.textTracks
property contains an array of all the text tracks attached to the video. We loop through each one and set its mode
to hidden
.
Note: The WebVTT API gives us access to all the text tracks that are defined for an HTML5 video using the <track>
element.
Building a caption menu
Our aim is to use the subtitles
button we added earlier to display a menu that allows users to choose which language they want the subtitles displayed in, or to turn them off entirely.
We have added the button, but before we make it do anything, we need to build the menu that goes with it. This menu is built dynamically, so that languages can be added or removed later by simply editing the <track>
elements within the video's markup.
All we need to do is to go through the video's textTracks
, reading their properties and building the menu up from there:
This code creates a documentFragment
, which is used to hold an unordered list containing our subtitles menu. First of all an option is added to allow the user to switch all subtitles off, and then buttons are added for each text track, reading the language and label from each one.
The creation of each list item and button is done by the createMenuItem()
function, which is defined as follows:
This function builds the required <li>
and <button>
elements, and returns them so they can be added to the subtitles menu list. It also sets up the required event listeners on the button to toggle the relevant subtitle set on or off. This is done by simply setting the required subtlte's mode
attribute to showing
, and setting the others to hidden
.
Once the menu is built, it is then inserted into the DOM at the bottom of the videoContainer.
Initially the menu is hidden by default, so an event listener needs to be added to our subtitles button to toggle it:
Subtitle menu CSS
We also added some rudimentary styling for the newly created subtitles menu:
Styling the displayed subtitles
One of the less well known about and supported features of WebVTT is the ability to style the individual subtitles (something called text cues) via CSS Extensions.
The ::cue
pseudo-element is the key to targetting individual text track cues for styling, as it matches any defined cue. There are only a handful of CSS properties that can be applied to a text cue:
background
shorthand propertiesoutline
shorthand propertiesfont
shorthand properties, includingline-height
For example, to change the text colour of the text track cues you can write:
If the WebVTT file uses voice spans, which allow cues to be defined as having a particular 'voice':
![Add Add](https://www.online-tech-tips.com/wp-content/uploads/2008/02/subtitle-workshop.jpg.optimal.jpg)
Then this specific 'voice' will be stylable like so:
Note: Some of the styling of cues with ::cue currently works on Chrome, Opera, and Safari, but not yet on Firefox.
Browser Compatibility
Browser support for WebVTT and the <track>
element is fairly good, although some browsers differ slightly in their implementation.
Internet Explorer
Internet Explorer 10+ subtitles are enabled by default, and the default controls contain a button and a menu that offers the same functionality as the menu we just built. The default
attribute is also supported.
Note: IE will completely ignore WebVTT files unless you define the MIME type. This can easily be done by adding an .htaccess
file to an appropriate directory that contains AddType text/vtt .vtt
.
Safari
Safari 6.1+ has similar support to Internet Explorer 10+, displaying a menu with the different available options, with the addition of an 'Auto' option, which allows the browser to choose.
Chrome and Opera
These browsers have similar implementations again: subtitles are enabled by default and the default control set contains a 'cc' button that turns subtitles on and off. Chrome and Opera ignore the default
attribute on the <track>
element and will instead try to match the browser's language to the subtitle's language.
Firefox
Firefox's implementation was completely broken due to a bug, leading to Mozilla turning off WebVTT support by default (you can turn it on via the media.webvtt.enabled
flag.) However, this bug looks to have been fixed and WebVTT support re-enabled as of Gecko 31, so this will not be a problem for Firefox final release users for much longer (on Gecko 29 as of the time of this writing) this has been fixed as of Firefox 31, and everything works as it should.
Plugins
If, after reading through this article you decide that you can't be bothered to do all of this and want someone else to do it for you, there are plenty of plugins out there that offer caption and subtitle support that you can use.
- plyr.io
- This modern video player implements subtitles in both SRT and WebVTT file formats.
- playr
- This small plugin implements subtitles, captions, and chapters as well as both WebVTT and SRT file formats.
- Flowplayer
- HTML5 player supporting WebVTT.
- jwplayer
- This video player is very extensive and does a lot more than simply support video captions. It supports the WebVTT, SRT and DFXP formats.
- MediaElement.js
- Another complete video player that also support video captions, albeit only in SRT format.
- LeanBack Player
- Yet another video player that supports WebVTT captions as well as providing other standard player functionality.
- SublimeVideo
- This player also supports captions through WebVTT and SRT files.
- Video.js
- Supports WebVTT video subtitles.
- Radiant Media Player
- Supports multi-languages WebVTT closed captions
Note: You can find an excellent list of HTML5 Video Players and their current 'state' at HTML5 Video Player Comparison.
Sometimes when you are editing your videos, you may want to add some subtitles to the videos either for better conveying the meaning or for making the videos more personalized.
There are many subtitle tools which can help you add and edit video subtitle. Below is a list of the best 10 subtitle editors for video editing on Windows/Mac. Have a look and get the great subtitle tools to add more fun to your home movie making.
Part 1. Top 10 Subtitle Editor You Should Know
- Subtitle Workshop
- Jubler
- SubtitleCreator
- Open Subtitle Editor
- SubMagic
- iToolSoft Movie Subtitle Editor
- POP Subtitle Editor
- Video Subtitle Editor
- Womble EasySub
- Aura Video Editor
Product Recommendation
Wondershare UniConverter - Your Complete Video Toolbox
- Support adding subtitle from local and Internet, changing font, font color, font size, and more other settings.
- Edit, enhance & personalize your video files, like trim/crop video, add watermarks, apply video effects, etc.
- Convert videos over 1000 formats, including MP4, AVI, WMV, FLV, MKV, MOV and more.
- Burn and customize your video to DVD with free DVD menu templates.
- Download or record videos from 10,000+ video sharing sites.
- All-in-one toolbox includes GIF maker, video compressor, screen recorder, fix video metadata, and cast video to TV.
- Industry-leading APEXTRANS technology converts or compresses videos with zero quality loss.
- Supported OS: Windows 10/8/7/XP/Vista, Mac OS 10.15 (Catalina), 10.14, 10.13, 10.12, 10.11, 10.10, 10.9, 10.8, 10.7, 10.6.
1. Subtitle Workshop
Price: Free
Subtitle Workshop is considered to be the best free subtitle editing tool with a user-friendly interface. It well supports all the popular subtitle formats like ASS, DKS, SCR, SUB, etc. Besides, it allows you to create, edit and convert subtitles with ease. In addition, it comes with some advanced features, such as spell check, video preview, etc. With these great features, great speed and stability, Subtitle Workshop takes much less time to edit subtitles and received worldwide awarding. Note that it is also compatible with Windows Vista.
2. Jubler
Price: Free
Jubler is a text-based subtitle editing tool. It can be either used to create new subtitles or to correct, refine, transform and convert existing subtitles. Like Subtitle Workshop, Jubler also supports all regular subtitle formats. This free subtitle editor comes with an optimization algorithm to help you fix the time inconsistencies. Besides, you can freely set the subtitles colors, check the spelling, choose the translation mode, etc. Before saving the subtitles, you can test the subtitles using MPlayer. Jubler can work on Windows, Mac and Linux.
3. SubtitleCreator
Price: Free
SubtitleCreator is a free subtitle editor that lets you add subtitles to your DVD. It can convert ASCII-based SRT or SUB text files to the binary SUP format and enables you to change the color of the existing subtitles. It comes with an inbuilt DVD Authoring Wizard function, which allows you to add new subtitles to a previously copied DVD. The latest version supports Karaoke.
4. Open Subtitle Editor
Price: Free
The free subtitle editor is very easy to use. Video editing and subtitle editing functions like subtitles translation, video resyncing, subtitles adding and removing, etc. are provided. You are also free to add new subtitles to any videos.
5. SubMagic
Price: Free
SubMagic is a free yet powerful video subtitle tool. You can freely convert, edit and enhance video subtitles. Beside, subtitles translation function is also provided.
6. iToolSoft Movie Subtitle Editor
Price: $39.95
iToolSoft Movie Subtitle Editor is the ultimate subtitle editor with lots of options for editing subtitles. This program is awarded by softonic.com and software.informer.com for clean software (No viruses, No Adware, No spyware).
Key Features:- Edits movie subtitles.
- Supports for making the subtitles into the film.
- Makes subtitles more distinct by adjusting bit rate and resolution ratio.
- Edits all kinds of settings for subtitles i.e. as typeface, color, and location.
7. POP Subtitle Editor
Price: $24.95
POP Subtitle Editor is a very easy-to-use tool to write and add subtitles to any movie format such as WMV, MPEG, AVI or QT video file.
Key Features:- Edits subtitles while previewing movies.
- Customizes font style, font size, font color and position of the subtitles in the screen.
- One-click movie generation with subtitles.
8. Video Subtitle Editor
Price: $24.95
Video Subtitle Editor is the mastering tool to edit subtitles for movies and TV shows very easily and efficiently.
Key Features:- Powerful and easy-to-use interface.
- Support almost every video formats such as iPod, WMV, DivX, AVI, MPEG, XviD, MP4, RM, 3G2, MOV, MPEG-4, etc.
- Edit movie subtitles with customization option like font style, font size, font color and position of the subtitles in screen.
- Supports for converting movies with high quality and faster speed from one format to another and can cut larger video into smaller video clips.
![Add subtitles to video youtube Add subtitles to video youtube](http://www.wikihow.com/images/3/34/Add-Subtitles-to-a-Movie_Video-on-VLC-Step-7.jpg)
9. Womble EasySub
Price: $149
Womble EasySub is a subtitle editor tool for DVD.
Key Features:- Supports for creating, editing and managing subtitle text within DVD video files.
- It has an embedded video player for editing subtitle and viewing effect in real-time.
- Real-time preview also helps to synchronize subtitle with the voice segment.
- Supports for importing existing subtitle files and then manipulate it like shifting time or change language.
- Supports for writing subtitle to DVD.
10. Aura Video Editor
Price: $9.95
Aura Video Editor is a full-featured and easy-to-use video editor with built-in subtitle editor.
Key Features:- Drag and drop video editing.
- Supports for adding subtitles to movies or videos.
- Customizes subtitles with different effects like you can change font type, color and position as well as transition effects.
- Real-time preview lets you see your video before saving video with customized effect.
Part 2. How to Easily Edit Subtitle on Windows/Mac
Besides the subtitle editors listed above, Wondershare UniConverter (originally Wondershare Video Converter Ultimate) is the best subtitle editor for your video. It's also the best video converter for over 1000 video and audio formats, you can change the format from MOV to MP4 or any other to playback on different devices. With this all-in-one video tool, you can also edit videos with trimming, cropping, rotating, watermarks, effects, etc. It's compatible for both Windows and Mac system, free download and follow the simple steps in the next part to edit subtitles easily.
Steps to Edit Subtitle with Wondershare Video Subtitle Editor
Step 1 Add Video for Editing Subtitle
Download, install and launch Wondershare UniConverter on your PC/Mac, then you'll come to the Convert tab by default. Click the Add Files button on the interface to choose and add the video you want to edit subtitle.
Step 2 Edit Subtitle to Video
After the video added successfully, a thumbnail will appear. Click the second or the third icon on the video thumbnail to open the Video Editor window, and then choose Subtitle option. From where, you can change different options about your subtitle such as font, color, size, position, and so on. Click the OK button to save all your changes.
Step 3 Save Subtitle for Playback
Choose an output video format for your video if you need from the Convert all files to: option. Open the drop-down list and choose Video tab, then select a video format and resolution. You can also tap on the Device tab to choose iPhone/iPad/Android devices supported formats. Finally, click on the Convert All button to save and convert all your changes.