Formatting in SRT is unofficial. SubRip stored plain text; the tags below came from players and editors, and each program supports its own subset. The one reliable rule is that text a reader does not recognise as a tag is shown as it stands.
How common readers handle tags
From htmlsubtitles.c in FFmpeg, read as raw text. Other programs differ.
- Case. Tag names (
font,b,i,u,s,br) and the attributessize=,color=andface=are matched without regard to case, so<I>and<FONT COLOR="red">work. - Leading spaces. Spaces at the start of a line are dropped, and spaces before a line break are removed.
<<. A doubled<is treated as text, not as the start of a tag.- Unknown tags. A tag-like name made only of letters, digits, underscore
and slash is removed with a warning. Anything else starting with
<is kept as text. Entities such as&are not decoded.
Backslash escapes
Some tools write the ASS escapes \N (line break) and \h (hard
space) into SRT text. They are not part of SubRip. FFmpeg’s converter does not look at a
backslash outside a brace block and passes it on unchanged to the ASS text it builds, where
these escapes mean what they mean in ASS. Players that read SRT directly may show them as
literal characters. A newline in the SRT text becomes \N in that output.
Alignment codes
Files converted from SubStation Alpha often contain
its numeric alignment codes in braces, such as {\an8} at the start of a
line to put it at the top of the picture. \an takes the position on a
numeric keypad: 1, 2 and 3 are bottom left, centre and right, 4, 5 and 6 the middle
row, and 7, 8 and 9 the top row.
What FFmpeg does (libavcodec/htmlsubtitles.c, read as raw text): a block
counts as an alignment code only when it is exactly {\an, one digit and
}. Only the first such block is kept. A {\…}
block that comes before it is stripped, and so is any second or later
{\anN}. Other {\…} blocks between the first and second
{\anN} are not stripped. It also strips
MicroDVD-style codes such as
{Y:i} (one of the letters CcFfoPSsYy, a colon, up to the next
}). A brace block with no closing } is left as text. Support
elsewhere varies, and a player without it shows the braces as text.
Worked example
7
00:00:40,000 --> 00:00:42,500
{\an8}<font color="#FFFF00"><i>[door slams]</i></font>
Not confirmed
No source settles how HTML character references such as & should
be treated in SRT. The set of colour names a player accepts also differs between
programs.