[FFmpeg-devel] [PATCH] SubRip decoder

Aurelien Jacobs aurel
Fri Dec 10 23:57:57 CET 2010

On Fri, Dec 10, 2010 at 02:33:04PM +0100, Aurelien Jacobs wrote:
> On Thu, Dec 09, 2010 at 05:46:32PM -0500, Alexander Strange wrote:
> > 
> > On Dec 8, 2010, at 5:41 PM, Aurelien Jacobs wrote:
> > 
> > > On Wed, Dec 08, 2010 at 02:03:48AM -0500, Alexander Strange wrote:
> > >> 
> > >> On Dec 4, 2010, at 9:58 AM, Aurelien Jacobs wrote:
> > >> 
> > >>> On Sun, Nov 28, 2010 at 05:53:04PM -0500, Alexander Strange wrote:
> > >>>> 
> > >>>> On Nov 28, 2010, at 5:31 PM, Aurelien Jacobs wrote:
> > >>>> 
> > >>>>> Hi,
> > >>>>> 
> > >>>>> $subject
> > >>>>> 
> > >>>>> This SubRip decoder supports all the SubRip features that I know about.
> > >>>>> It especially support everything tested by the sample files from
> > >>>>> http://ale5000.altervista.org/subtitles.htm
> > >>>> 
> > >>>> [...]
> > >>>> 
> > >>>>> +    snprintf(header, sizeof(header),
> > >>>>> +             "[Script Info]\r\n"
> > >>>>> +             "ScriptType: v4.00+\r\n"
> > >>>>> +             "\r\n"
> > >>>>> +             "[V4+ Styles]\r\n"
> > >>>> 
> > >>>> Watch out for the weird default PlayRes* values.
> > >>> 
> > >>> The default is 384x288.
> > >>> Do you think I should choose another default value ?
> > >> 
> > >> If you're happy with the current font size, I guess it's OK.
> > >> 
> > >> But actually there's another problem - this sets a hardcoded style
> > >> named Default,
> > > 
> > > Yes.
> > > 
> > >> so players will render with that style.
> > > 
> > > No. At least that's not what the ASS spec says:
> > > 
> > > 5. Dialogue event lines, [Events] section
> > > [...]
> > > Field 4: Style
> > >         Style name. If it is "Default", then your own *Default style
> > >         will be subtituted.
> > >         However, the Default style used by the script author IS stored
> > >         in the script even though SSA ignores it - so if you want to
> > >         use it, the information is there - you could even change the
> > >         Name in the Style definition line, so that it will appear in
> > >         the list of "script" styles.
> > > 
> > > So we store the Default style of the "authoring software" in the script,
> > > as a reference (or for non-compilant software) but the player should
> > > ignore it and use its own default style.
> > 
> > Well, usually ass-spec.doc isn't too far wrong, but VSFilter doesn't do this at all.
> > It sets a style named "Default" before loading the file, and then sets the styles in the file over that. It ignores * as the first character of all style name definitions(!) but doesn't otherwise have a style named *Default.
> > 
> > >> I think it's expected that srt should be rendered with the "default"
> > >> style of the player.
> > > 
> > > Yes,and that's exactly how the generated ASS should be rendered too.
> > > 
> > >> How about not emitting a Style: line at all, and setting the style
> > >> of each subtitle to "*Default" (IIRC what the built-in default ASS
> > >> style is called)?
> > > 
> > > I'm pretty certain this would break some renderer.
> > 
> > Looks like the style per-subtitle should be Default with no Style:
> > line. That definitely works with VSFilter, and therefore every other
> > renderer (which is just Perian and libass).
> OK. Then I guess I can drop the entire [V4+ Styles] section, right ?

Well, I did some tests with libass (MPlayer) and it don't seem that

With my current patch (ie. including a Default style), the rendering
is using the Defaut style written in the file, and is working exactly
as expected.

If I rename the Default style in the produced file, this randomly
named style is used by the renderer as it's default style, so no
change from previous test.

If I drop the Style: line from the produced file, subtitles are not
rendered at all. (maybe a bug in libass ?)

If I drop the whole [V4+ Styles] section, the renderer seems to use
its own default style. Font color is yellow, instead of the white I
did specify in the (removed) Default style. So it seems to work as
you suggested. But unfortunately most of the style overrides in the
Dialogue lines are not honored anymore, so the rendering is very broken.
(another libass bug ??)

Anyway, it looks like the only viable solution, for now, is to write
a Default style in the produced ASS.
And I think it is a good thing that the file contains a suggested
default rendering style. Renderers are still free to ignore this
Default style and use their own default instead, if they want (as
suggested by the ass spec).

So for now, I keep my patch unchanged.


PS: you can experiment this by yourself with the attached ASS file
produced by my SubRip decoder.
-------------- next part --------------
[Script Info]
ScriptType: v4.00+

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding
Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,1,1,0,2,10,10,10,0,0

Format: Layer, Start, End, Text
Dialogue: 0,0:00:00.00,0:00:00.00,Don't show this text it may be used to insert hidden data
Dialogue: 0,0:00:01.50,0:00:04.50,SubRip subtitles capability tester 1.3o by ale5000\N{\b1}{\i1}Use VLC 1.1 or higher as reference for most things and MPC Home Cinema for others{\i0}{\b0}\N{\c&HFF0000&}This text should be blue{\c}\N{\c&HFF&}This text should be red{\c}\N{\c&H0&}This text should be black{\c}\N{\fnWebdings}If you see this with the normal font, the player don't (fully) support font face{\fn}
Dialogue: 0,0:00:04.50,0:00:04.50,Hidden
Dialogue: 0,0:00:04.50,0:00:07.50,{\fs8}This text should be small{\fs}\NThis text should be normal\N{\fs35}This text should be big{\fs}
Dialogue: 0,0:00:07.50,0:00:11.50,This should be an E with an accent: ?\N???\N{\fs30}{\b1}{\i1}{\u1}This text should be bold, italics and underline{\u0}{\i0}{\b0}{\fs}\N{\fs9}{\c&HFF00&}This text should be small and green{\c}{\fs}\N{\fs9}{\c&HFF&}This text should be small and red{\c}{\fs}\N{\fs24}{\c&H2A2AA5&}This text should be big and brown{\c}{\fs}
Dialogue: 0,0:00:11.50,0:00:14.50,{\b1}This line should be bold{\b0}\N{\i1}This line should be italics{\i0}\N{\u1}This line should be underline{\u0}\N{\s1}This line should be strikethrough{\s0}\N{\u1}Both lines\Nshould be underline{\u0}
Dialogue: 0,0:00:14.50,0:00:17.50,>\NIt would be a good thing to\Nhide invalid html tags that are closed and show the text in them\N<invalid_tag_unclosed>but show un-closed invalid html tags\NShow not opened tags</invalid_tag_not_opened>\N<
Dialogue: 0,0:00:17.50,0:00:20.50,and also\Nhide invalid html tags with parameters that are closed and show the text in them\N<invalid_tag_uc par=5>but show un-closed invalid html tags\N{\u1}This text should be showed underlined without problems also: 2<3,5>1,4<6{\u0}\NThis shouldn't be underlined
Dialogue: 0,0:00:20.50,0:00:21.50,This text should be in the normal position...
Dialogue: 0,0:00:21.50,0:00:22.50,{\an1}{\move(0,50,0,100)}This text should NOT be in the normal position
Dialogue: 0,0:00:22.50,0:00:24.50,Implementation is the same of the ASS tag\N{\an8}This text should be at the\Ntop and horizontally centered
Dialogue: 0,0:00:22.50,0:00:24.50,{\an5}This text should be at the\Nmiddle and horizontally centered
Dialogue: 0,0:00:22.50,0:00:24.50,{\an2}This text should be at the\Nbottom and horizontally centered
Dialogue: 0,0:00:24.50,0:00:26.50,This text should be at the\Ntop and horizontally at the left{\an7}
Dialogue: 0,0:00:24.50,0:00:26.50,{\an4}This text should be at the\Nmiddle and horizontally at the left\N(The second position must be ignored)
Dialogue: 0,0:00:24.50,0:00:26.50,{\an1}This text should be at the\Nbottom and horizontally at the left
Dialogue: 0,0:00:26.50,0:00:28.50,{\an9}This text should be at the\Ntop and horizontally at the right
Dialogue: 0,0:00:26.50,0:00:28.50,{\an6}This text should be at the\Nmiddle and horizontally at the right
Dialogue: 0,0:00:26.50,0:00:28.50,{\an3}This text should be at the\Nbottom and horizontally at the right
Dialogue: 0,0:00:28.50,0:00:31.50,{\fs6}{\c&HFF00&}This could be the {\fs35}m{\c&H0&}o{\c&HFF00&}st{\fs6} difficult thing to implement{\c}{\fs}
Dialogue: 0,0:00:31.50,0:00:50.50,First text
Dialogue: 0,0:00:33.50,0:00:35.50,Second, it shouldn't overlap first
Dialogue: 0,0:00:35.50,0:00:37.50,Third, it should replace second
Dialogue: 0,0:00:36.50,0:00:50.50,Fourth, it shouldn't overlap first and third
Dialogue: 0,0:00:40.50,0:00:45.50,Fifth, it should replace third
Dialogue: 0,0:00:45.50,0:00:50.50,Sixth, it shouldn't be\Nshowed overlapped
Dialogue: 0,0:00:50.50,0:00:52.50,TEXT 1 (bottom)
Dialogue: 0,0:00:50.50,0:00:52.50,text 2
Dialogue: 0,0:00:52.50,0:00:54.50,Hide these tags:\Nalso hide these tags:\Nbut show this: {normal text}
Dialogue: 0,0:00:54.50,0:01:00.50,{\an8}\N\ N is a forced line break\N\ h is a hard space\NNormal spaces at the start and at the end of the line are trimmed while hard spaces are not trimmed.\NThe\hline\hwill\hnever\hbreak\hautomatically\hright\hbefore\hor\hafter\ha\hhard\hspace.\h:-D
Dialogue: 0,0:00:54.50,0:00:56.50,{\an1}\N\h\h\h\h\hA (05 hard spaces followed by a letter)\NA (Normal  spaces followed by a letter)\NA (No hard spaces followed by a letter)
Dialogue: 0,0:00:56.50,0:00:58.50,\h\h\h\h\hA (05 hard spaces followed by a letter)\NA (Normal  spaces followed by a letter)\NA (No hard spaces followed by a letter)\NShow this: \TEST and this: \-)
Dialogue: 0,0:00:58.50,0:01:00.50,{\an3}\NA letter followed by 05 hard spaces: A\h\h\h\h\h\NA letter followed by normal  spaces: A\NA letter followed by no hard spaces: A\N05 hard  spaces between letters: A\h\h\h\h\hA\N5 normal spaces between letters: A     A\N\N^--Forced line break
Dialogue: 0,0:01:00.50,0:01:02.50,{\s1}Both line should be strikethrough,\Nyes.{\s0}\NCorrectly closed tags\Nshould be hidden.
Dialogue: 0,0:01:02.50,0:01:04.50,It shouldn't be strikethrough,\Nnot opened tag showed as text.</s>\NNot opened tag showed as text.</xxxxx>
Dialogue: 0,0:01:04.50,0:01:06.50,{\s1}Three lines should be strikethrough,\Nyes.\N<yyyy>Not closed tags showed as text
Dialogue: 0,0:01:06.50,0:01:08.50,{\s1}Both line should be strikethrough but\Nthe wrong closing tag should be showed</b>

More information about the ffmpeg-devel mailing list