srt / vtt / ass subtitle formats
SRT (SubRip Subtitle), VTT (WebVTT), and ASS (Advanced SubStation Alpha) are three very common subtitle formats. The following details each subtitle format, its properties, and settings.
SRT Subtitle Format
SRT is a simple and widely used subtitle format with the file extension .srt. It is especially popular in video players and subtitle editors. Its basic structure includes subtitle number, timestamp, and subtitle text. Subtitle properties (such as color, font) cannot be defined directly through SRT; they usually rely on the player's default settings or external style files for control.
SRT Format Structure
Each subtitle block in an SRT file is arranged in the following format:
- Subtitle Number (increments line by line)
- Timestamp (shows start and end time, precise to milliseconds)
- Subtitle Content (can contain multiple lines of text)
- An empty line (used to separate subtitle blocks)
SRT Example
1
00:00:01,000 --> 00:00:04,000
Hello there, my friend!
2
00:00:05,000 --> 00:00:08,000
The weather is nice today, don't you think?Detailed Explanation
Subtitle Number: Each subtitle block has a unique number, incrementing sequentially. Numbering starts from 1 and must be an integer.
- Example:
1
- Example:
Timestamp: The format is
HH:MM:SS,mmm, whereHHis hours,MMis minutes,SSis seconds, andmmmis milliseconds. The timestamp consists of two times separated by-->with a space on each side, indicating the start and end time of the subtitle.- Example:
00:00:01,000 --> 00:00:04,000
- Example:
Subtitle Content: The subtitle text can contain one or more lines, displayed on the video. SRT does not support formatted text, such as color, font size, etc. These must be defined through player settings or additional style files.
- Example:
Hello there, my friend!
- Example:
SRT Format Limitations
- Does not support text formatting: Cannot directly set color, font, etc.; requires the player or other tools for style adjustments.
VTT Subtitle Format
WebVTT (Web Video Text Tracks) is a subtitle format for HTML5 video elements, designed specifically for web video. It is more powerful than the SRT format, supporting styles, notes, multiple languages, positioning information, and other properties. The subtitle file format extension is .vtt. However, it cannot be directly embedded into a video; it must be referenced within the HTML <video> element.
VTT Format Structure
VTT files are similar to SRT but with more features. A VTT file begins with WEBVTT followed by an empty line, and uses a . (dot) instead of a , (comma) to separate seconds and milliseconds.
VTT Example
WEBVTT
1
00:00:01.000 --> 00:00:04.000
Hello there, <b>friends!</b>
2
00:00:05.000 --> 00:00:08.000
The rain today is <i>very, very heavy</i>.Detailed Explanation
WEBVTT Declaration: All VTT files must start with
WEBVTTto declare their file format.- Example:
WEBVTT
- Example:
Subtitle Number: Subtitle numbers are optional, unlike in the SRT format where they are required. Their purpose is to distinguish the order of each subtitle segment, but they can be omitted in VTT.
Timestamp: The format is
HH:MM:SS.mmm, whereHHis hours,MMis minutes,SSis seconds, andmmmis milliseconds. A.(dot) is used to separate seconds and milliseconds, not a,. The timestamp consists of two times separated by-->, also with a space on each side.- Example:
00:00:01.000 --> 00:00:04.000
- Example:
Subtitle Content: Subtitle text can contain HTML tags for text formatting, such as bold (
<b>), italic (<i>), underline (<u>), etc.- Example:plaintext
Hello there, <b>friends!</b>
- Example:
Other Features Supported by VTT
Styles (CSS):
- VTT supports text style adjustments via CSS, such as color, font size, position, etc. Styles can be defined in HTML via
<style>tags or external CSS files. - Example:plaintextDefining
<c.red>Hello there, friends!</c>.red { color: red; }in HTML will displayHello, world!in red.
- VTT supports text style adjustments via CSS, such as color, font size, position, etc. Styles can be defined in HTML via
Positioning Information:
- VTT supports setting specific positions for subtitles through properties like
position,line, etc. - Example:plaintext
00:00:01.000 --> 00:00:04.000 position:90% line:10%
- VTT supports setting specific positions for subtitles through properties like
Notes:
- VTT supports adding notes in the file, starting with
NOTE. - Example:plaintext
NOTE This is a note and will not be displayed.
- VTT supports adding notes in the file, starting with
Multi-language Support:
- VTT can support multi-language subtitles through metadata or HTML5's
<track>tag.
- VTT can support multi-language subtitles through metadata or HTML5's
Advantages of the VTT Format
- Text Formatting: Supports HTML tags for simple text formatting, such as bold, italic, etc.
- Styles and Positioning: Allows setting subtitle styles and positions via CSS.
- Notes and Metadata: Supports adding note information without affecting subtitle display.
- Web Compatibility: Designed for HTML5 video, suitable for web environments.
Comparison of SRT and VTT
| Feature | SRT | VTT |
|---|---|---|
| File Header | None | WEBVTT followed by an empty line |
| Timestamp Format | HH:MM:SS,mmm, comma separates seconds and milliseconds | HH:MM:SS.mmm, dot separates seconds and milliseconds |
| Supports Text Formatting | No | Supports HTML tags, e.g., <b>, <i> |
| Subtitle Number | Required | Optional |
| Style and Position Support | Relies on player or external style files | Built-in CSS style support, supports positioning info |
| Notes | Not supported | Supports NOTE notes |
| Supported Advanced Features | Basic subtitle functions only | Supports karaoke, notes, styles, etc. |
| Use Case | Local video files, simple subtitle display | HTML5 video, web subtitles, complex subtitle display |
| Can be embedded in video? | Can be embedded in video files | Cannot be embedded in video; can only be used within webpage <video> elements |
The VTT (WebVTT) subtitle format cannot be directly embedded into MP4 files, but VTT files can be associated with MP4 videos using HTML5's
<track>tag. When playing the MP4 in a browser, these associated subtitles can be displayed normally.
Using VTT Subtitles to Play MP4 in a Browser
In HTML5, you can load an MP4 video via the <video> element and associate VTT subtitles with it using the <track> element.
HTML Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<video controls width="600">
<source src="video.mp4" type="video/mp4">
<track src="subtitles.vtt" kind="subtitles" srclang="zh" label="Simplified Chinese">
Your browser does not support the video tag.
</video>
</body>
</html>HTML Element Explanation
<video>: Used to embed video files. Thecontrolsattribute allows users to control video playback (play/pause, etc.).<source>: Defines the path and type of the video file, using MP4 here.<track>: Defines the subtitle file. Thesrcattribute points to the path of the VTT file,kind="subtitles"indicates it is a subtitle,srclangspecifies the subtitle language (zhfor Chinese), andlabelgives the subtitle track a descriptive label.
Place the HTML file and the related video and subtitle files in the same directory. Then, open the HTML file (e.g., index.html) in a browser. You will see the video player, and when you click play, subtitles will automatically appear (if the player supports it and the user has subtitles enabled).
Most modern browsers and video players support subtitle switching. You can select different subtitles (if multiple tracks exist) via the subtitle button in the video control bar.
VTT Subtitle Notes
Browser Compatibility: Almost all modern browsers (e.g., Chrome, Firefox, Edge) support the
<video>element and WebVTT subtitles. As long as the VTT file and MP4 file are correctly associated, subtitles should be displayed when playing the video in a browser.Cannot be Directly Embedded in MP4 Files: VTT subtitle files cannot be directly embedded into MP4 files like SRT or other subtitle formats. MP4 files themselves do not contain VTT subtitle tracks. External subtitle files must be used and associated via the HTML5
<track>tag.VTT Subtitle Styling: In browsers, WebVTT subtitles can be styled to some extent via CSS. If customizing subtitle appearance is needed, further modifications can be made using JavaScript and CSS.
ASS Subtitle Format
ASS (Advanced SubStation Alpha) is a feature-rich subtitle format widely used for anime, karaoke subtitles, and other scenarios requiring complex subtitle effects. It supports rich style controls, including font, color, position, shadow, outline, and more.
Below is an example of an ASS subtitle.
[Script Info]
; Script generated by FFmpeg/Lavc60.27.100
ScriptType: v4.00+
PlayResX: 384
PlayResY: 288
ScaledBorderAndShadow: yes
YCbCr Matrix: None
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,SimHei,16,&hffffff,&HFFFFFF,&h000000,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:01.95,0:00:04.93,Default,,0,0,0,,This is an ancient galaxy,
Dialogue: 0,0:00:05.42,0:00:08.92,Default,,0,0,0,,We have been observing it for several years,
Dialogue: 0,0:00:09.38,0:00:13.32,Default,,0,0,0,,The Webb telescope recently sent back many previously undiscovered photos.ASS Subtitle Structure
A standard ASS subtitle file contains multiple sections:
- [Script Info]: Basic information about the script, such as title, original subtitle author, etc.
- [V4+ Styles]: Subtitle style definitions; each style can be referenced by different subtitle lines.
- [Events]: Actual subtitle events, defining the appearance time, disappearance time, and specific content of subtitles.
1. [Script Info] Section
This section contains metadata for the subtitle file, defining some basic information.
[Script Info]
Title: Subtitle Title
date: 2024-01-22 14:33:00
description:
Original Script: Subtitle Author
ScriptType: v4.00+
PlayDepth: 0
PlayResX: 1920
PlayResY: 1080
ScaledBorderAndShadow: yes
YCbCr Matrix: NoneTitle: The title of the subtitle file.Original Script: Information about the original subtitle author.ScriptType: Defines the script version, usuallyv4.00+.PlayResXandPlayResY: Define the video resolution, indicating the display effect of subtitles at that resolution.PlayDepth: The color depth of the video, generally 0.ScaledBorderAndShadow: Specifies whether to scale the subtitle's outline and shadow according to the screen resolution.yesmeans yes,nomeans no scaling.YCbCr Matrix: Specifies the YCbCr matrix used for color conversion. In video processing and subtitle rendering, YCbCr is a color space commonly used for video encoding and decoding. This setting may affect subtitle display under different color spaces.
2. [V4+ Styles] Section
This section defines subtitle styles. Each style can control font, color, shadow, etc., through fields. The format is as follows:
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,20,&H00FFFFFF,&H0000FFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,1,0,2,10,10,20,1Field Explanations:
Name: The name of the style, used for reference.
- Example:
Default, meaning this is the default style.
- Example:
Fontname: Font name.
- Example:
Arial, subtitles will use the Arial font.
- Example:
Fontsize: Font size.
- Example:
20, font size is 20.
- Example:
PrimaryColour: Primary subtitle color, representing the main color of the subtitle (usually the displayed text color).
- Example:
&H00FFFFFF, white font. The color value format is&HAABBGGRR, whereAAis transparency.
- Example:
SecondaryColour: Secondary subtitle color, typically used for karaoke subtitle transition colors.
- Example:
&H0000FFFF, blue.
- Example:
OutlineColour: Outline color.
- Example:
&H00000000, black outline.
- Example:
BackColour: Background color, typically used when
BorderStyle=3(subtitles with a background box).- Example:
&H00000000, black background.
- Example:
Bold: Bold setting.
- Example:
-1means bold,0means not bold.
- Example:
Italic: Italic setting.
- Example:
0means not italic,-1means italic.
- Example:
Underline: Underline setting.
- Example:
0means no underline.
- Example:
StrikeOut: Strikethrough setting.
- Example:
0means no strikethrough.
- Example:
ScaleX: Horizontal scaling ratio, 100 means normal scale.
- Example:
100, meaning no scaling.
- Example:
ScaleY: Vertical scaling ratio.
- Example:
100, meaning no scaling.
- Example:
Spacing: Character spacing.
- Example:
0, meaning no extra spacing.
- Example:
Angle: Subtitle rotation angle.
- Example:
0, meaning no rotation.
- Example:
BorderStyle: Border style, defining whether the subtitle has an outline or background box.
- Example:
1means has outline but no background box,3means has background box.
- Example:
Outline: Outline thickness.
- Example:
1, meaning outline thickness is 1.
- Example:
Shadow: Shadow depth.
- Example:
0, meaning no shadow.
- Example:
Alignment: Subtitle alignment, using numbers 1-9 to define different alignment positions.
- Example:
2, meaning center-bottom alignment.
Alignment Explanation:
- 1: Bottom-left
- 2: Bottom-center
- 3: Bottom-right
- 4: Middle-left
- 5: Center
- 6: Middle-right
- 7: Top-left
- 8: Top-center
- 9: Top-right
- Example:
MarginL, MarginR, MarginV: Left, right, and vertical margins, in pixels.
- Example:
10, 10, 20, meaning left and right margins are 10 pixels, vertical margin is 20 pixels.
- Example:
Encoding: Encoding format,
1means ANSI encoding,0means default encoding.
3. [Events] Section
This section defines actual subtitle events, including timestamps, subtitle content, and the style used.
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:01.00,0:00:05.00,Default,,0,0,0,,This is the first subtitle line
Dialogue: 0,0:00:06.00,0:00:10.00,Default,,0,0,0,,This is the second subtitle lineField Explanations:
Layer: Layer, controls the stacking order of subtitles; higher numbers are on top.
- Example:
0, meaning default layer.
- Example:
Start: Subtitle start time, format
hours:minutes:seconds.milliseconds.- Example:
0:00:01.00, meaning subtitle starts at 1 second.
- Example:
End: Subtitle end time.
- Example:
0:00:05.00, meaning subtitle ends at 5 seconds.
- Example:
Style: The name of the subtitle style used, referencing a style defined in [V4+ Styles].
- Example:
Default, uses the style named Default.
- Example:
Name: Optional field, typically used for character name annotation.
MarginL, MarginR, MarginV: Left, right, and vertical margins for the subtitle, overriding values defined in the style.
Effect: Subtitle effects, typically used for karaoke subtitles, etc.
Text: The actual content of the subtitle. ASS format control codes can be used for line breaks, special styles, positioning, etc.
Example Subtitle Event
Dialogue: 0,0:00:01.00,0:00:05.00,Default,,0,0,0,,{\pos(960,540)}This is the first subtitle line{\pos(960,540)}: Controls the subtitle to display at a specific screen position (horizontal 960 pixels, vertical 540 pixels).This is the first subtitle line: The actual displayed subtitle text.
Color Settings in ASS
Taking &HAABBGGRR as an example, &HAABBGGRR is a hexadecimal format used to represent a color, including the color's transparency and the color value itself. This format is used to define subtitle color properties, such as PrimaryColour, OutlineColour, and BackColour.
The meanings are as follows:
AA: Transparency (Alpha channel), representing the color's transparency.BB: Blue component.GG: Green component.RR: Red component.
The specific byte order is: Alpha (transparency) - Blue - Green - Red.
If you do not want to use transparency, you can simply ignore the value in the AA position, e.g.,
&HBBGGRRis sufficient.
Transparency and Color Values
Fully Transparent: The color is completely transparent, i.e., invisible. The representation is
&H00BBGGRR, where theAApart is00(fully transparent).Example:
plaintext&H00FFFFFF- Here,
&H00FFFFFFrepresents fully transparent white. Transparency is00(fully transparent), color isFFFFFF(white).
- Here,
Fully Opaque: The color is completely opaque, i.e., the color appears most solid. The representation is
&HFFBBGGRR, where theAApart isFF(fully opaque).Example:
plaintext&HFF000000- Here,
&HFF000000represents fully opaque black. Transparency isFF(fully opaque), color is000000(black).
- Here,
Actual Color Examples
Fully Transparent Red:
plaintext&H00FF0000- Transparency
00(fully transparent), colorFF0000(red).
- Transparency
Fully Opaque Green:
plaintext&HFF00FF00- Transparency
FF(fully opaque), color00FF00(green).
- Transparency
Summary:
- The
AApart in&HAABBGGRRcontrols transparency, while theBB,GG,RRparts control the color. - Fully Transparent: Transparency
00, e.g.,&H00FF0000represents fully transparent red. - Fully Opaque: Transparency
FF, e.g.,&HFFFF0000represents fully opaque red.
