[FFmpeg-devel] [PATCH 6/7] avcodec/ass_split: assume default order when "Format:" line is not found
Clément Bœsch
u at pkh.me
Sat Oct 11 23:47:46 CEST 2014
On Sat, Oct 11, 2014 at 10:53:28PM +0200, wm4 wrote:
> On Sat, 11 Oct 2014 19:59:11 +0200
> Clément Bœsch <u at pkh.me> wrote:
>
> > Fixes the decoding of the ASS stream in a mkv from a fansub release from
> > Coalgirls.
> > ---
> > libavcodec/ass_split.c | 26 +++++++++++++++++++++++++-
> > 1 file changed, 25 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/ass_split.c b/libavcodec/ass_split.c
> > index fea38e7..bd7db93 100644
> > --- a/libavcodec/ass_split.c
> > +++ b/libavcodec/ass_split.c
> > @@ -229,6 +229,20 @@ static inline const char *skip_space(const char *buf)
> > return buf;
> > }
> >
> > +static int *get_default_field_orders(const ASSSection *section)
> > +{
> > + int i;
> > + int *order = av_malloc(FF_ARRAY_ELEMS(section->fields) * sizeof(*order));
> > +
> > + if (!order)
> > + return NULL;
> > + for (i = 0; section->fields[i].name; i++)
> > + order[i] = i;
> > + while (i < FF_ARRAY_ELEMS(section->fields))
> > + order[i] = -1;
> > + return order;
> > +}
> > +
> > static const char *ass_split_section(ASSSplitContext *ctx, const char *buf)
> > {
> > const ASSSection *section = &ass_sections[ctx->current_section];
> > @@ -246,7 +260,7 @@ static const char *ass_split_section(ASSSplitContext *ctx, const char *buf)
> > } else if (section->format_header && !order) {
> > len = strlen(section->format_header);
> > if (strncmp(buf, section->format_header, len) || buf[len] != ':')
> > - return NULL;
> > + goto next_line;
> > buf += len + 1;
> > while (!is_eol(*buf)) {
> > buf = skip_space(buf);
> > @@ -269,6 +283,15 @@ static const char *ass_split_section(ASSSplitContext *ctx, const char *buf)
> > if (!strncmp(buf, section->fields_header, len) && buf[len] == ':') {
> > uint8_t *ptr, *struct_ptr = realloc_section_array(ctx);
> > if (!struct_ptr) return NULL;
> > +
> > + /* No format header line found so far, assume default */
> > + if (!order) {
> > + order = get_default_field_orders(section);
> > + if (!order)
> > + return NULL;
> > + ctx->field_order[ctx->current_section] = order;
> > + }
> > +
> > buf += len + 1;
> > for (i=0; !is_eol(*buf) && i < *number; i++) {
> > int last = i == *number - 1;
> > @@ -298,6 +321,7 @@ static const char *ass_split_section(ASSSplitContext *ctx, const char *buf)
> > }
> > }
> > }
> > +next_line:
> > buf += strcspn(buf, "\n");
> > buf += !!*buf;
> > }
>
> I think you must distinguish between ASS and SSA when doing this.
It's already the case; there are two sections, one for "V4+ Styles" and
one for "V4 Styles". Both sections should have the correct fields names in
.fields after previous commit.
[...]
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20141011/9b225423/attachment.asc>
More information about the ffmpeg-devel
mailing list