SRT has no formal specification. It was defined by what the SubRip program wrote, and what follows is the layout that player and library authors agree on, including the places where they do not.
File layout
A file is a sequence of cues. There is no signature, header, version number or footer, so a program can only recognise SRT by the extension or by the shape of the first cue.
The text encoding is not stated in the file. SubRip wrote Windows-1252 by default and
offered many code pages and Unicode forms, with or without a byte order mark.
Readers must therefore guess, using a byte order mark when there is one. UTF-8 is the
usual form today, and Matroska stores SRT text as UTF-8. There is no registered media
type; application/x-subrip is in common use but not IANA-registered.
One cue
| Line | Name | Content | Notes |
|---|---|---|---|
| 1 | Counter | A decimal number | Starts at 1 and rises by 1. Most players ignore its value, and Matroska drops it when it stores the track. |
| 2 | Timing line | start --> end | The time the text appears and the time it goes, optionally followed by coordinates. |
| 3 onward | Text | One or more lines | The subtitle, with optional formatting. In the strict layout it ends at the first blank line. |
| last | Separator | A blank line | Ends the cue in the strict layout. The final cue may or may not have one. |
Lines end with CR LF or LF. In the strict layout a blank line ends the cue, so subtitle text cannot contain one. Readers do not all follow that rule (see below).
How common readers end a cue
A blank line inside the text does not necessarily end the cue. The two readers checked here look for the next timing line instead:
- FFmpeg (
libavformat/srtdec.c) skips every empty line. It starts a new cue only when a line parses as a timing line. Any other line after a timing line is added to the text, except that a line starting with a number is held back as a possible counter. If a timing line follows, the held line is dropped when it is a bare number or the cue already has text; after the last cue it is kept as text. Trailing newlines are removed from the text, and a cue with no text is not queued. - The Python
srtlibrary (srt.py) allows blank lines inside the content. It ends a cue where the following lines look like an optional counter and a timestamp, or at the end of the file. It also accepts a missing blank line at the end of the file, and a missing double blank line between cues.
Source: both files read as raw text from their repositories. Other programs may differ.
Time format
A time is written HH:MM:SS,mmm.
| Part | Digits | Range | Meaning |
|---|---|---|---|
HH | 2 | 00 and up | Hours, zero padded |
MM | 2 | 00–59 | Minutes, zero padded |
SS | 2 | 00–59 | Seconds, zero padded |
, | 1 | A comma, where WebVTT uses a full stop. This is the quickest way to tell the two apart. | |
mmm | 3 | 000–999 | Milliseconds, zero padded |
The two times are separated by a space, --> and a space.
What readers accept instead
The table above is the strict form. Readers are more tolerant:
- Separator before the milliseconds. FFmpeg accepts a comma or a full stop
(
%*1[,.]in its scan format). Thesrtlibrary accepts a full stop too, and its source comment says a full stop is “not technically valid” but that many editors write it and many editors and players accept it. - Digit counts. FFmpeg reads each field with
%d, so any number of digits is accepted in hours, minutes, seconds and milliseconds. Thesrtlibrary accepts one or more digits in the first three fields and zero or more in the last. Note that FFmpeg adds the fraction as a plain integer, so,5counts as 5 ms, not 500 ms. - Counter optional. Both readers find a cue from its timing line. FFmpeg
ignores a counter. In
srtthe counter is an optional pattern in front of the timing line, and may be negative or have a fractional part. - Arrow. The
srtlibrary also allows extra spaces around-->, lets the second hyphen be a space (- >), and keeps any text after the end time on the timing line as proprietary data.
Sources: srtdec.c (get_event_info) and srt.py
(RGX_TIMESTAMP and SRT_REGEX), read as raw text.
Coordinates
SubRip could record a box after the end time. This is an unofficial extension, and most players ignore it. Its unit and origin are undocumented: the Doom9 forum thread “Extended SRT spec (especially coordinate format) question” says they were not known, and the names below are only the usual guess of a bounding box. Do not read them as pixels or as particular screen edges.
FFmpeg (srtdec.c) reads the box only when all four values follow the end time
in the order X1: X2: Y1: Y2:, each as a
whole number, after one or more spaces. It then attaches them, without interpreting them,
to the cue as 16 bytes of position side data (AV_PKT_DATA_SUBTITLE_POSITION)
in the order X1, Y1, X2, Y2.
00:02:16,612 --> 00:02:19,376 X1:201 X2:516 Y1:43 Y2:68
| Name | Meaning |
|---|---|
X1 | First horizontal value (unit and origin undocumented) |
X2 | Second horizontal value (unit and origin undocumented) |
Y1 | First vertical value (unit and origin undocumented) |
Y2 | Second vertical value (unit and origin undocumented) |
Worked example
1
00:00:01,000 --> 00:00:03,500
Where are we going?
2
00:00:04,000 --> 00:00:06,250
Somewhere
we have never been.
Relatives
WebSRT was a 2010 WHATWG proposal for the HTML <track> element,
based on SRT and also using the .srt extension. It was renamed
WebVTT, which requires a WEBVTT signature
and full stops in times. It is not compatible with SRT.