Styling video subtitles.

What is SSA/ASS?

SSA/ASS stands for SubStation Alpha.
It allows better control on the styling of subtitles: position, fonts, italic, bold, underline, rotation, etc.
You can modify the styles per sentence or inside the sentences as well.
Layers are also available.
And stylesheets too!
Animation of subtitles is also an option.

See introduction and examples here: http://en.wikipedia.org/wiki/SubStation_Alpha

All the options explained here: http://aegisub.cellosoft.com/docs/ASS_Tags

There are some SSA/ASS editors out there. But here we are interested in generating it to be able to produce them differently.

Fonts can be changed. For the moment, I didn't find a way to specify a path to the font (but it seems to be possible), so I can only use fonts installed on the computer.

Convert usual .srt subtitles into .ssa

SSA/ASS requires a specific way to describe information. It uses timestamps and not frames just like .srt files.

The srt2ssa.sh script makes several "search and replace" for the subtitles fit the SSA format. Copy the code in a file called srt2ssa.sh. Don't forget to make it executable by chmod +x srt2ssa.sh.

The header is an example header to which we will append the subtitles. Be free to change the options there.

#!/bin/bash

cat << HEADER
Collisions: Normal
PlayResX: 200
PlayResY: 200
PlayDepth: 0
Timer: 100,0000
Video Aspect Ratio: 0
Video Zoom: 6 
Video Position: 0

[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: MyStyle, DejaVu Sans Bold, 28, &H00B4FCFC, &H00FF0000, &H000000FF, &H8000FF00, -1, 0, 0, 0, 100, 100, 0.00, 0.00, 1, 1.00, 2.00, 1, 30, 30, 30, 0


[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text

HEADER

sed "s/^[0-9]*$//g" | \
sed s/\ --\>\ /,/g | \
sed "s/\([0-9][0-9]\),\([0-9][0-9][0-9]\)/\1.\2/g" | \
sed "s/\([0-9].*[0-9]\)/Dialogue: 1,\0,MyStyle,NTP,0000,0000,0000,,/g" | \
tr -d "\n" | \
sed "s/Dialogue/\n\0/g" | \
sed "s/\(,\)[0-9]\([0-9]:\)/\1\2/g"

Usage

./srt2ssa.sh < your_subtitle_file.srt > your_subtitles_file.ssa

To use in mplayer: mplayer your_video.avi -ssa -sub your_subtitles_file.ssa

Making a stylesheet for each person in an interview

The script is detecting every sentence beginning like this: Name: and apply to these sentences and the following until the next name a specific stylesheet. Don't forget to make the script executable by chmod +x ssa2voices.py.

#! /usr/bin/python

import fileinput
import re

speaker="MyStyle"

for l in fileinput.input():
    r = re.search(r".+,,(.+):.+", l)
    if r is None:
        l = re.sub(r"MyStyle", speaker, l)
        print l
    else:
        speaker = r.groups()[0]
        l = re.sub(r"MyStyle", speaker, l)
        print l

After we get a styled .ssa file, we can just change the styles of each character (see the "Format" to understand how to change the options). For the moment, only one stylesheet is in the file, copy/paste it as needed, and change name and options.

[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: Myriam, Courier, 14, &H00B4FCFC, &H00FF0000, &H00000008, &H80000008, -1, 0, 0, 0, 100, 100, 0.00, 0.00, 1, 1.00, 2.00, 1, 30, 30, 100, 0

Style: David, DejaVu Sans Bold, 28, &H00B4FCFC, &H00FF0000, &H00000008, &H80000008, -1, 0, 0, 0, 100, 100, 0.00, 0.00, 1, 1.00, 2.00, 1, 30, 30, 100, 0

Style: Hahn, DejaVu Serif Bold, 14, &H00B4FCFC, &H00FF0000, &H00000008, &H80000008, -1, 0, 0, 0, 100, 100, 0.00, 0.00, 1, 1.00, 2.00, 1, 30, 30, 100, 0

Usage

With an existing .ssa file: ./ssa2voices.py your_subtitles_file.ssa >| multiple_voices.ssa

To use with mplayer: mplayer your_video.avi -ssa -sub multiple_voices.ssa

Bazar/SSA/ASS

Updated on 12/02/2011