- Advanced SubStation Alpha (ASS)
1.1 SSA vs ASS
SubStation Alpha (SSA) was created by CS Low (Kotus) and offers richer capabilities than basic formats like SRT. Its rendered via VSFilter on Windows media players and is no longer developed. Advanced SubStation Alpha (ASS) builds on SSA 4.00+ encoding, adding more effects and commands. SSA currently uses version V4.00; ASS uses the more advanced V4.00+.
1.2 Script Structure
1.2.1 Header Section
- Script Info: Global metadata including Title, Original Script, Script Updated By, Script Type (V4.00 for SSA, V4.00+ for ASS), PlayResX/PlayResY (resolution), PlayDepth, and Timer.
1.2.2 Style Definition
[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
- PrimaryColour: Text color.
- SecondaryColour: Used in karaoke effects where primary fills secondary.
- OutlineColour: Border color of text.
- BackColour: Shadow color.
- MarginL / MarginR: Minimum left/right distance from video edges.
- MarginV: Vertical margin depending on alignment; ignored for centered text. Use
\Nor\nfor line breaks. - Outline: Border style (none, outline, or opaque background).
- Shadow: Shadow offset distance.
- Encoding: Character encoding.
1.2.3 Events Section
The core subtitle content: timing, style references, and overrides. Commands use the syntax {\command(param1,param2,...)}, e.g., {\move(80,80,200,200,150,300)}. Single‑parameter commands skip parentheses (e.g., {\kf89}).
1.2.4 Notes
- Multiple commands can be placed inside one brace pair, e.g.,
{\bord8\be1}. \Nand\nfor line breaks do not require braces.
1.3 Bilingual Subtitle Example
[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,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0
Style: Chs,Arial,12,&Hcccccc,&Hcccccc,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0
Style: Eng,Arial,20,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:01:06.63,0:01:07.63,Default,,0,0,0,,GIRL: Hey, Nat!\N{\rChs}女孩:嘿,纳特!
Dialogue: 0,0:01:37.08,0:01:38.71,Default,,0,0,0,,We're both upside down.\N{\rChs}我们两个都颠倒了。
Dialogue: 0,0:01:38.87,0:01:40.96,Default,,0,0,0,,And I bet you're gonna fall down first.\N{\rChs}我打赌你会先倒下。
Dialogue: 0,0:01:41.12,0:01:42.66,Default,,0,0,0,,No, you will.\N{\rChs}不,你会的。
- SubRip (SRT)
SubRip is a free Windows tool (GNU GPL) that extracts subtitles from video files. Its .srt format is widely used and human‑readable.
2.1 File Structure
- Sequence number: Incremental counter.
- Time range: Start time → End time (format
hh:mm:ss,mmm). - Subtitle text: One or more lines.
- Blank line: Terminates the entry.
2.2 Styling (Informal)
SRT supports basic HTML‑like tags for bold, italic, underline, and color:
- Bold:
<bold>...</bold>or{bold}...{/bold} - Italic:
<italic>...</italic>or{italic}...{/italic} - Underline:
<underline>...</underline>or{underline}...{/underline} - Color:
<font color="color_name/#hex">...</font> - Position: Coordinates
X1:... X2:... Y1:... Y2:...after the timestamp.
2.3 Positioning
Default alignment is bottom center ({\an2}). Use override tags for custom positions:
| Left | Center | Right | |
|---|---|---|---|
| Top | {\an7} |
{\an8} |
{\an9} |
| Middle | {\an4} |
{\an5} |
{\an6} |
| Bottom | {\an1} |
{\an2} |
{\an3} |
- Summary and Conversions
ASS = SRT + simple stylesheet. Use SRT for plain text, ASS when styling (colors, fonts, effects) is needed — common for bilingual subtitles where each language can have different appearance.
3.1 Supported Subtitle Codecs (ffmpeg)
$ ffmpeg -hide_banner -codecs | grep "^...S"
Common entries:
DES... ass(decoders: ssa ass; encoders: ssa ass)..S... srt..S... ssaDES... subrip(decoders: srt subrip; encoders: srt subrip)DES... mov_text
3.2 SRT ↔ ASS Conversion
# SRT to ASS
$ ffmpeg -i input.srt output.ass
# ASS to SRT
$ ffmpeg -i out.ass out.srt
3.3 SBV to SRT
$ ffmpeg -i captions.sbv captions.srt
$ ffmpeg -fix_sub_duration -i captions.sbv captions.srt
- Subtitle Operations with FFmpeg
4.1 Soft Subtitles (Recommended)
Soft subtitles exist as separate streams within the container. They can be added/removed without re‑encoding video, thus fast and lossless.
4.1.1 Extracting a Subtitle Stream
# List streams
$ ffmpeg -i input.mkv
# Extract first subtitle (default)
$ ffmpeg -i input.mkv sub.srt
# Extract specific stream by absolute index (e.g., stream 6)
$ ffmpeg -i input.mkv -map 0:5 sub.srt
# Extract by relative index (e.g., fourth subtitle stream)
$ ffmpeg -i input.mkv -map 0:s:3 sub.srt
4.1.2 Adding Subtitle Streams
# Add one subtitle stream to a video
$ ffmpeg -i source.mp4 -i subtitle.eng.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=en source_eng.mp4
# On top of existing subtitles
$ ffmpeg -i source_eng.mp4 -i subtitle.chi.srt -map 0 -map 1 -c copy -c:s mov_text source_eng_chi.mp4
# Multiple subtitles in one go
$ ffmpeg -i source.mp4 -i subtitle.eng.srt -i subtitle.chi.srt -i subtitle.eng.ass \
-map 0 -map 1 -map 2 -map 3 -c copy -c:s mov_text \
-metadata:s:s:0 language=en -metadata:s:s:1 language=chi -metadata:s:s:2 language=en.ass \
source_all.mp4
# Alternative with relative mapping
$ ffmpeg -i source.avi -i en.srt -i CN.srt \
-map 0:v -map 0:a -map 1 -map 2 \
-c:v copy -c:a copy -c:s mov_text \
-metadata:s:s:0 language=en -metadata:s:s:1 language=cn \
output.mp4
4.1.3 Important Notes
- Omitting
-mapwhen adding a subtitle to MP4 will have no effect. - For MP4, you must explicitly specify
-map 0 -map 1and-c:s mov_text. - For MKV,
-map 0 -map 1 -c copyworks withoutmov_text. - Full working command for MP4:
$ ffmpeg -i input.mp4 -i sub.srt -map 0 -map 1 -c copy -c:s mov_text output.mp4 - Optionally set metadata:
-metadata:s:s:0 language=enortitle=<desired title=""></desired>.
4.2 Hard Subtitles (Burn-in, Not Recommended)
Hard subtitles are rendered directly into the video frames. This requires re‑encoding the video, making the process slow and irreversible.
Two filters can be used: subtitles (works with any text subtitle via automatic conversion) or ass (only for ASS files).
# Using subtitles filter (supports SRT, etc.)
$ ffmpeg -i input.avi -vf "subtitles=subtitle.srt" output.avi
# Burn subtitles from a container
$ ffmpeg -i input.mkv -vf "subtitles=input.mkv" output.avi
# Using ass filter (ASS only)
$ ffmpeg -i input.avi -vf "ass=subtitle.ass" output.avi
# Convert SRT to ASS first if using ass filter
$ ffmpeg -i subtitle.srt subtitle.ass
For image‑based subtitles (e.g., DVD sub/dvdsub), use the overlay filter:
$ ffmpeg -i input.mkv -filter_complex "[0:v][0:s]overlay[v]" -map "[v]" -map 0:a output.mkv
- References