Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ssf-specs.txt « docs « libssf « Subtitles « src - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bc34fed147baf61fcc3e944412f0726ab3feaedc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
Structured Subtitle Format 1.0 (boring name, need a better one)
------------------------------

The encoding must be utf-8/16le/16be with the BOM at the beginning.

Parsing is prefered to be stream oriented, which means:
- new-line characters in text do not differ from the rest of the white-space characters
- forward references are not allowed

Comments
--------

// a comment, ends at the end of the line
/* this is a comment, too */

Syntax
------

Fortunatelly, there is only one general way to define something. The elements are broken
into lines for better understanding, but they can be compressed into one single line as well,
whichever suits your preference. The term "type" could be read as "attribute" or "member of
a structure" too.

[!]
[type[.type[..]]]
[#name]
[: | =]
[refs | quoted string | num | bool | raw]
;

As you can see nearly everything is optional, even the terminating semi-colon is not required
when a closing bracket ends the definition anyway. However, either type or #name must be given,
otherwise there would be no meaning of the expression.

"!":
- gives the definition high priority, normal priority types of the same kind cannot override it:
    #a {!t: 123;};
    #b {t: 234;};
    #c a b; // t of c equals to 123
    - works on references too:
    !#a {t: 123;};
    #b {t: 234;};
    #ab a b;
    #c ab; // t of c still equals to 123

"type" and "name":
- alphanumeric or underscore characters only, without spaces
- cannot start with a number
- case-sensitive

"type":
- type is optional but can be inherited through referencing other names which happen to have a type already
    color#c1 {a: 0x80;};
    #c2: c1; // c2 also has the type of color now
    #c3: c2; // c3 too
- if there is a type already additional references cannot change it
- when mixing different types (not recommended) the first one decides
- there is one special type which have an important but a limited use: @ (see 'subtitle' for an example usage)
    - it is not parsed for references or nested definitions
    - the content of the following block {...} is saved as-is for the application
    - cannot be global or named and therefore referenced
    - { and } have to be escaped with \ inside the block (other block specific characters may as well)
- type.type.type.... is equal to writing: type {type {type {...};};};

"name":
- every name is globally visible
- redefining a name is forbidden, unless it was predefined by the application
- using the type as the name (type#type) can change the type's default values
    - however, the scope is important:

    subtitle#subtitle {style.font.size: 20;};
    style#style {font.size: 30;};
    style#s1 {font.face: "Arial";};
    style#s2 : s1 {font.color: red;};
    subtitle#a {style: s2 {font.weight: "normal";};};

    Here font.size equals to 20, because it inherits from subtitle#subtitle.style instead of the
    global style#style, additionally it gets the properties of s2-s1 and the inline def. If it also
    inherited properties from style#style through s2-s1 indirectly, there would be two default base
    definitions and the order of overriding eachother would not be clear.

    subtitle#a.style
        <- subtitle#subtitle.style
        <- s2 <- s1 <-NOT- style#style
        <- {font.weight: "normal";}

"refs":
- combination of any names or nested definitions separated by spaces
- forward references are not allowed
- referencing a value type directly is not allowed: (TODO: this may change)
    OK:
    color#c1: {a: 12;};
    color#c2: c1;
    BAD:
    #twelve: 12;
    color#c2: {a: twelve;};
- 'name' must have been defined by a parent node
    OK:
    #c1: {a: 12;};
    style#s1 {color: c1;};
    style#s2 {color: c1;};
    BAD:
    style#s1 {color#c1: {a: 12;};};
    style#s2 {color: c1;}; // c1 cannot be accessed here

"quoted string" or 'quoted string':
- \ escapes characters, including " and '
- cannot contain any new-line characters

"num":
- decimal, hexadecimal (prefixed with: 0x), float [+ unit (optional, see 'time' below for an example)]
- there are numbers with restricted range or special formatting:
    - degrees: <num> mod 360
    - percent: must be between 0 and 1
    - time: [+] [<num>:[<num>:[<num>.]]]<num> | <num>h | <num>m | <num>s | <num>ms

"bool":
- "true" | "false" | "on" | "off" | "yes" | "no" | 1 | 0
- unrecognizable values will result in unpredictable behaviour, since there can't be a default fallback value

Recognized types and attributes
-------------------------------

file
{
    format: <string>; // identifies the file format ("ssf")
    version: <num>; // file format version (1)
    language: <string>; // iso6392
    title: <string>;
    year: <num>;
    author: <string>;
};

color
{
    // a, r, g, b: 0 - 255 or 0x00 - 0xff

    a: <num>;
    r: <num>;
    g: <num>;
    b: <num>;
};

point
{
    x: <num>;
    y: <num>;
};

size
{
    cx: <num>;
    cy: <num>;
};

rect
{
    t: <num>;
    r: <num>;
    b: <num>;
    l: <num>;
};

align
{
    // when given in percent, 0 means top/left, 1 bottom/right, 0.5 middle/center

    v: ["top" | "middle" | "bottom" | <percent>];
    h: ["left" | "center" | "right" | <percent>];
};

angle
{
    x: <degrees>;
    y: <degrees>;
    z: <degrees>;
};

frame
{
    reference: ["video" | "window"];
    resolution: <size>;
};

direction
{
    primary: ["right" | "left" | "down" | "up"];
    secondary: ["right" | "left" | "down" | "up"]; // must be perpendicular to primary
};

placement
{
    clip: ["none" | "frame" | <rect>]; // anything drawn outside this rectangle is clipped, negative or larger than 'resolution' values are not allowed for rect
    margin: <rect>; // "top" "right" "bottom" "left" are also valid values for the rect members, they refer to the values of the "frame" rect (0, 0, frame.resolution.cx, frame.resolution.cy)
    align: <align>;
    pos: ["auto" | <point>]; // absolute values, pos.x or pos.y can be animated only when both the source and destination style defined it
    offset: <point>; // relative to pos, unlike pos this can be applied to fragments of the text as an override
    angle: <angle>; // origin of rotation is the alignment point, unless it is overriden
    org: ["auto" | <point>]; // override for the origin
    path: <string>; // a series of x y coord pairs (at least two points)
};

font
{
    face: <string>;
    size: <num>;
    weight: ["normal" | "bold" | "thin" | <num>];
    color: <color>;
    underline: <bool>;
    strikethrough: <bool>;
    italic: <bool>;
    spacing: <num>;
    scale: <size>;
    kerning: <bool>;
};

background
{
    color: <color>;
    size: <num>;
    type: ["outline" | "enlarge" | "box"];
    blur: <num>; // number of passes

    // "enlarge" can be computed faster, but because it follows the path of the original outline it is
    // not rounded and size > 1 can make it look pretty bad if it intersects with itself.
};

shadow
{
    color: <color>;
    depth: <num>;
    angle: <degrees>;
    blur: <num>; // number of passes
};

fill
{
    color: <color>;
    width: <percent>;

    // It cannot be applied to the same text multiple times as an override.
    //
    // #k1 {fill.width:1; time {start: +0; stop: +1s;}};
    // #k2 {fill.width:1; time {start: 0; stop: 2s;}};
    //
    // OK:
    // [k1] {Hello}
    //
    // BAD:
    // [k1] {Wo[k2]{r}ld!}
    //
};

time
{
    id: [<string> | <num>];
    start: <time>; // inclusive
    stop: <time>; // exclusive
    scale: <num>; // if the time was set WITHOUT a unit, then start and stop are measured in [scale * seconds]
};

style
{
    linebreak: ["word" | "char" | "none"]; // ignored if subtitle.wrap: "manual"
    placement: <placement>;
    font: <font>;
    background: <background>;
    shadow: <shadow>;
    fill: <fill>;
};

animation
{
    time: <time>; // before start: previous style, after stop: this style, animation is done between start and stop according to transition
    transition: ["linear" | "start" | "stop" | <num>]; // <num> is the same as the acceleration parameter of advanced ssa (see the "ass-specs"), "start" or "stop" sets num to 0 and inf, "linear" sets it to 1.0
    loop: <num>; // the number of times the effect should repeat, e.g. loop set to 2 makes the style turn from src to dst twice, between start => (start+stop)/2 and (start+stop)/2 => stop
    direction: ["fw" | "bw" | "fwbw" | "bwfw"]; // "bwfw" and "fwbw" makes the value of loop multiplied by two internally
};

subtitle
{
    frame: <frame>;
    direction: <direction>;
    wrap: ["normal" | "even" | "manual"];
    layer: <num>;
    time: <time>;
    style: <style>;
    @: {... dialog lines ...};

    To have a subtitle displayed the minimal set of fields required are:
    - time.start
    - time.stop
    - @

    About dialog lines
    ------------------

    All white-space will be compressed into one space character.

    Special characters can be enforced:
    - new-line: \n
    - non-breaking space: \h

    Empty space will be completly removed at these places:
    - before and after outermost text block brackets:
        @ { --> here <-- Hello World! --> here <-- }
    - between the inner closing and opening brackets of overrides:
        [s1] --> here <-- {Hello World!}
    - around forced new-lines:
        Hello --> here <-- \n --> here <-- World!

    When neighboring spaces have different styles, the style of the trailing space is used:
        #u {font.underline: "true"};
        #s {font.strikethrough: "true"};
        [u] { Hello }
        [s] { World! }
        =>
        Hello_World!-
        ______-------

    These special characters have to be escaped with a backslash:
        { } [ ] \

    Style overrides
    ---------------

    [refs] {... more dialog text ...}

    "name" as in type#name ... is unimportant and ignored.

    If there is a text block right after an override, the new style will be used only inside
    that block.

    Style and time offsets are restored at the end of text blocks.

    Examples:

    [s1] {s1 applies only to this block.}

    [s2] s2 applies till the end of the container block.

    [s1 s2 {color: red;} s3] {Multiple styles are valid just like in a normal ref list}

    {
        Nesting text blocks. Some may have overrides, others may not.

        [s1]
        {
            Every text block will be trimmed and white-space compressed,
            so we can use the space freely to make it a bit more readable.

            {Yet another nested block}
        }
    }

    Animation:

    The override is style + animation mixed.

    [{time.stop: +00:00:01.000; transition: "linear"; font.size: 20;}]
    {
        Here the size of the font gradually becomes 20 after one second.
    }

    [{font.color: white;}]
    {
        [{time.stop: +00:00:10.000; font.color: black;}]
        {Text turns from white to black in the first 10 seconds}

        [a1]
        {This one does whatever a1 tells to do}
    }

    [{time.start: "start"; time.stop: "stop"; font.size: 20}]
    {
        This is a way to refer to the subtitle's own start and stop values.

        You can predefine it for easier use:

        #a1 {time.start: "start"; time.stop: "stop";};
        [a1 {font.size: 20}] {...}
    }

    Karaoke effect using animation:

    [{background.size: 0;}]
    {
        [{time.start: 0s; time.stop: +1s; background.size: 10;}]
        {Ka}
        [{time.start: 1s; time.stop: +1s; background.size: 10;}]
        {ra}
        [{time.start: 2s; time.stop: +1s; background.size: 10;}]
        {o}
        [{time.start: 3s; time.stop: +1s; background.size: 10;}]
        {ke!}
    }

    To simplify the above, we can predefine the common parameters:

    #s1 {background.size: 0;};
    #a1 {time.start: +0s; time.stop: +1s; background.size: 10;};

    [s1]
    {
        [a1]{Ka}[a1]{ra}[a1]{o}[a1 {font.color: red;}]{ke!}

        // That last piece has even turned into a red in the end :)

        // And to make sure s1 has not been red already, we could derive it
        // from "whitefont" (defined somewhere else as: #whitefont {font.color: white;};)

        [a1]{Ka}[a1]{ra}[a1]{o}[a1 whitefont {font.color: red;};}]{ke!}
    }

    When specifying multiple style references watch out for the start/stop values
    of time. Since they override eachother you should only set them once.

    #a2 {font.color.a: 0;};
    #a3 {placement.angle.x: 360;};

    [s1] [a1 a2 a3]{Ka}[a1 a2 a3]{ra}[a1 a2 a3]{o}[a1 a2 a3]{ke!}

    If you want to be even lazier:

    #a4: a1 a2 a3;

    [s1] [a4]{Ka}[a4]{ra}[a4]{o}[a4]{ke!}

    To avoid the times overriding eachother use either nested text blocks ...

    #a2 {time.start: +0.5s; time.stop: +1s; font.color.a: 0;};
    #a3 {time.start: +1s; time.stop: +1s; placement.angle.x: 360;};

    [s1] [a1]{[a2]{[a3]Ka}}[a1]{[a2]{[a3]ra}}[a1]{[a2]{[a3]o}}[a1]{[a2]{[a3]ke}}

    ... or a list of references were each has a different time.id ...

    #a1 {time {id: 1; start: +0s; stop: +1s;}; background.size: 10;};
    #a2 {time {id: 2; start: +0.5s; stop: +1s;}; font.color.a: 0;};
    #a3 {time {id: 3; start: +1s; stop: +1s;}; placement.angle.x: 360;};

    [s1] [a1,a2,a3]{Ka}[a1,a2,a3]{ra}[a1,a2,a3]{o}[a1,a2,a3]{ke!}

    ... or just let it auto-number the ids, each timer id becomes the actual position
    in the comma separated list (a1 id => 1, a2 id => 2, a3 id => 3).

    #a1 {time {start: +0s; stop: +1s;}; background.size: 10;};
    #a2 {time {start: +0.5s; stop: +1s;}; font.color.a: 0;};
    #a3 {time {start: +1s; stop: +1s;}; placement.angle.x: 360;};

    [s1] [a1,a2,a3]{Ka}[a1,a2,a3]{ra}[a1,a2,a3]{o}[a1,a2,a3]{ke!}

    It is also possible to leave some of the ref list slots empty.

    [s1] [a1,a2,a3]{Ka}[,a2,a3]{ra}[a1,,a3]{o}[a1,a2,]{ke!}

    Text includes
    -------------

    Text blocks can also be defined outside subtitles and included later.

    #hw { @ {[{font.italic: "true"}]Hello World!}; };
    subtitle { @ {[hw]}; };

    When mixing style overrides and text includes, the new style applies to the text too.

    #hw { @ {Hello World!}; };
    subtitle { @ {[hw {font.italic: "true"}]}; };

    Multiple levels of recursion:

    #dblspace { @ {[{font.scale.cx: 2;}]             }; }; // note: there is still only one space character here because of white space compression
    #hw { @ {Hello[dblspace]World!}; };
    subtitle { @ {[hw]}; };
};

Defaults and predefined names
-----------------------------

These must be predefined by the application and always assumed to be there for ssf version 1.

color#white {a: 255; r: 255; g: 255; b: 255;};
color#black {a: 255; r: 0; g: 0; b: 0;};
color#gray {a: 255; r: 128; g: 128; b: 128;};
color#red {a: 255; r: 255; g: 0; b: 0;};
color#green {a: 255; r: 0; g: 255; b: 0;};
color#blue {a: 255; r: 0; g: 0; b: 255;};
color#cyan {a: 255; r: 0; g: 255; b: 255;};
color#yellow {a: 255; r: 255; g: 255; b: 0;};
color#magenta {a: 255; r: 255; g: 0; b: 255;};

align#topleft {v: "top"; h: "left";};
align#topcenter {v: "top"; h: "center";};
align#topright {v: "top"; h: "right";};
align#middleleft {v: "middle"; h: "left";};
align#middlecenter {v: "middle"; h: "center";};
align#middleright {v: "middle"; h: "right";};
align#bottomleft {v: "bottom"; h: "left";};
align#bottomcenter {v: "bottom"; h: "center";};
align#bottomright {v: "bottom"; h: "right";};

time#time {scale: 1;};
time#startstop {start: "start"; stop: "stop";};

#b {font.weight: "bold"};
#i {font.italic: "true"};
#u {font.underline: "true"};
#s {font.strikethrough: "true"};

#nobr {linebreak: "none"};

subtitle#subtitle
{
    frame
    {
        reference: "video";
        resolution: {cx: 640; cy: 480;};
    };

    direction
    {
        primary: "right";
        secondary: "down";
    };

    wrap: "normal";

    layer: 0;

    style
    {
        linebreak: "word";

        placement
        {
            clip: "none";
            margin: {t: 0; r: 0; b: 0; l: 0;};
            align: bottomcenter;
            pos: "auto";
            offset: {x: 0; y: 0;};
            angle: {x: 0; y: 0; z: 0;};
        };

        font
        {
            face: "Arial";
            size: 20;
            weight: "bold";
            color: white;
            underline: "false";
            strikethrough: "false";
            italic: "false";
            spacing: 0;
            scale: {cx: 1; cy: 1;};
            kerning: "true";
        };

        background
        {
            color: black;
            size: 2;
            type: "outline";
        };

        shadow
        {
            color: black {a: 128;};
            depth: 2;
            angle: -45;
            blur: 0;
        };

        fill
        {
            color: yellow;
            width: 0;
        };
    };
};

Streaming
---------

Correct packetization is important when a subtitle file has to be embeded into a media
file. Putting everything into the header would be trivial, but sending the whole track
data ahead cannot be called streaming really, and it also makes editing impossible
unless the application learns how to parse and resave our format.

The recommended way of segmenting ssf into media samples:
- Search top level definitions which do not satisfy the requirements of a displayable
subtitle (one of start/stop/@ is absent) and save them into the file header of the media
file as the initializer data for playback.
- Multiplex the rest of the top level definitions as media samples, their timestamps
shall be used for interleaving with other streams.

Example:

#mystyle {font.face: "Times New Roman";};
subtitle#s1 {time.start: 2s;};
subtitle#s2 : s1 {style: mystyle; time.stop: +1s; @ {2s -> 3s};};
subtitle#s3 {style: mystyle; time.start: 5s; @ {5s -> 7s};};
subtitle#s4 : s3 {time.stop: +2s;};

File header:

#mystyle {font.face: "Times New Roman";};
subtitle#s1 {time.start: 2s;};
subtitle#s3 {style: mystyle; time.start: 5s; @ {5s -> 7s};};

Media samples:

subtitle#s2 : s1 {style: mystyle; time.stop: +1s; @ {2s -> 3s};};
subtitle#s4 : s3 {time.stop: +2s;};