[FFmpeg-devel] [PATCH] SubRip decoder

Alexander Strange astrange
Sat Dec 18 08:41:29 CET 2010

On Dec 10, 2010, at 5:57 PM, Aurelien Jacobs wrote:

> 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
> simple.
> 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).

The problem is that many ass files come with modified Default styles. If the player overrode that, it'd sort of break the file, either because it looks different from the author's intent, or because they used \pos and now the text positions are wrong.

But if libass doesn't work with it that rules it out, of course... either it'll be fixed sometime, or players can add a counter-hack to check the original codec ID and ignore the style line if it's not originally ASS.

I still think the patch is ok if it works. Did you try fuzzing some srt files?

More information about the ffmpeg-devel mailing list