[FFmpeg-devel] [PATCH 2/2] add ASS encoder and decoder

Aurelien Jacobs aurel
Sat Nov 13 15:45:13 CET 2010


On Wed, Nov 10, 2010 at 02:48:45AM +0100, Michael Niedermayer wrote:
> On Wed, Nov 10, 2010 at 01:29:15AM +0100, Aurelien Jacobs wrote:
> > On Tue, Nov 09, 2010 at 07:25:52PM +0100, Michael Niedermayer wrote:
> > > On Mon, Nov 08, 2010 at 12:54:25AM +0100, Aurelien Jacobs wrote:
> > > > On Sun, Oct 24, 2010 at 07:13:01PM +0200, Michael Niedermayer wrote:
> > > > > On Sat, Oct 16, 2010 at 05:31:27PM +0200, Aurelien Jacobs wrote:
> > > > > > ---
> > > > > >  libavcodec/Makefile    |    2 +
> > > > > >  libavcodec/allcodecs.c |    1 +
> > > > > >  libavcodec/ass.c       |   37 +++++++++++++++++++++++++
> > > > > >  libavcodec/ass.h       |   30 ++++++++++++++++++++
> > > > > >  libavcodec/assdec.c    |   50 +++++++++++++++++++++++++++++++++
> > > > > >  libavcodec/assenc.c    |   71 ++++++++++++++++++++++++++++++++++++++++++++++++
> > > > > >  6 files changed, 191 insertions(+), 0 deletions(-)
> > > > > >  create mode 100644 libavcodec/ass.c
> > > > > >  create mode 100644 libavcodec/ass.h
> > > > > >  create mode 100644 libavcodec/assdec.c
> > > > > >  create mode 100644 libavcodec/assenc.c
> > > > > > 
> > > > > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> > > > > > index 385ae02..d4afc0b 100644
> > > > > > --- a/libavcodec/Makefile
> > > > > > +++ b/libavcodec/Makefile
> > > > > > @@ -66,6 +66,8 @@ OBJS-$(CONFIG_AMV_DECODER)             += sp5xdec.o mjpegdec.o mjpeg.o
> > > > > >  OBJS-$(CONFIG_ANM_DECODER)             += anm.o
> > > > > >  OBJS-$(CONFIG_ANSI_DECODER)            += ansi.o cga_data.o
> > > > > >  OBJS-$(CONFIG_APE_DECODER)             += apedec.o
> > > > > > +OBJS-$(CONFIG_ASS_DECODER)             += assdec.o
> > > > > > +OBJS-$(CONFIG_ASS_ENCODER)             += assenc.o
> > > > > >  OBJS-$(CONFIG_ASV1_DECODER)            += asv1.o mpeg12data.o
> > > > > >  OBJS-$(CONFIG_ASV1_ENCODER)            += asv1.o mpeg12data.o
> > > > > >  OBJS-$(CONFIG_ASV2_DECODER)            += asv1.o mpeg12data.o
> > > > > > diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> > > > > > index 89614ab..b42935c 100644
> > > > > > --- a/libavcodec/allcodecs.c
> > > > > > +++ b/libavcodec/allcodecs.c
> > > > > > @@ -341,6 +341,7 @@ void avcodec_register_all(void)
> > > > > >      REGISTER_ENCDEC  (ADPCM_YAMAHA, adpcm_yamaha);
> > > > > >  
> > > > > >      /* subtitles */
> > > > > > +    REGISTER_ENCDEC  (ASS, ass);
> > > > > >      REGISTER_ENCDEC  (DVBSUB, dvbsub);
> > > > > >      REGISTER_ENCDEC  (DVDSUB, dvdsub);
> > > > > >      REGISTER_DECODER (PGSSUB, pgssub);
> > > > > > diff --git a/libavcodec/ass.c b/libavcodec/ass.c
> > > > > > new file mode 100644
> > > > > > index 0000000..36650c1
> > > > > > --- /dev/null
> > > > > > +++ b/libavcodec/ass.c
> > > > > > @@ -0,0 +1,37 @@
> > > > > > +/*
> > > > > > + * SSA/ASS common funtions
> > > > > > + * Copyright (c) 2010  Aurelien Jacobs <aurel at gnuage.org>
> > > > > > + *
> > > > > > + * This file is part of FFmpeg.
> > > > > > + *
> > > > > > + * FFmpeg is free software; you can redistribute it and/or
> > > > > > + * modify it under the terms of the GNU Lesser General Public
> > > > > > + * License as published by the Free Software Foundation; either
> > > > > > + * version 2.1 of the License, or (at your option) any later version.
> > > > > > + *
> > > > > > + * FFmpeg is distributed in the hope that it will be useful,
> > > > > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > > > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > > > > > + * Lesser General Public License for more details.
> > > > > > + *
> > > > > > + * You should have received a copy of the GNU Lesser General Public
> > > > > > + * License along with FFmpeg; if not, write to the Free Software
> > > > > > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> > > > > > + */
> > > > > > +
> > > > > > +#include "avcodec.h"
> > > > > > +#include "ass.h"
> > > > > > +
> > > > > > +int ff_ass_subtitle(AVSubtitle *sub, int *data_size, const char *dialog,
> > > > > > +                    int duration)
> > > > > > +{
> > > > > > +    memset(sub, 0, sizeof(*sub));
> > > > > > +    sub->end_display_time = 10 * duration;
> > > > > > +    sub->rects     = av_mallocz(sizeof(*sub->rects));
> > > > > > +    sub->rects[0]  = av_mallocz(sizeof(AVSubtitleRect));
> > > > > > +    sub->num_rects = 1;
> > > > > > +    sub->rects[0]->type = SUBTITLE_ASS;
> > > > > > +    sub->rects[0]->ass  = av_strdup(dialog);
> > > > > > +    *data_size = 1;
> > > > > > +    return 0;
> > > > > > +}
> > > > > > diff --git a/libavcodec/ass.h b/libavcodec/ass.h
> > > > > > new file mode 100644
> > > > > > index 0000000..00ad504
> > > > > > --- /dev/null
> > > > > > +++ b/libavcodec/ass.h
> > > > > > @@ -0,0 +1,30 @@
> > > > > > +/*
> > > > > > + * SSA/ASS common funtions
> > > > > > + * Copyright (c) 2010  Aurelien Jacobs <aurel at gnuage.org>
> > > > > > + *
> > > > > > + * This file is part of FFmpeg.
> > > > > > + *
> > > > > > + * FFmpeg is free software; you can redistribute it and/or
> > > > > > + * modify it under the terms of the GNU Lesser General Public
> > > > > > + * License as published by the Free Software Foundation; either
> > > > > > + * version 2.1 of the License, or (at your option) any later version.
> > > > > > + *
> > > > > > + * FFmpeg is distributed in the hope that it will be useful,
> > > > > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > > > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > > > > > + * Lesser General Public License for more details.
> > > > > > + *
> > > > > > + * You should have received a copy of the GNU Lesser General Public
> > > > > > + * License along with FFmpeg; if not, write to the Free Software
> > > > > > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> > > > > > + */
> > > > > > +
> > > > > > +#ifndef AVCODEC_ASS_H
> > > > > > +#define AVCODEC_ASS_H
> > > > > > +
> > > > > > +#include "avcodec.h"
> > > > > > +
> > > > > 
> > > > > > +int ff_ass_subtitle(AVSubtitle *sub, int *data_size, const char *dialog,
> > > > > > +                    int duration);
> > > > > 
> > > > > global functions should be documented, always IMHO
> > > > 
> > > > OK.
> > > > 
> > > > I took this opportunity to make this shared function more versatile and
> > > > more useful for other decoders (which I'm currently working on).
> > > > 
> > > > Aurel
> > > >  Makefile    |    2 +
> > > >  allcodecs.c |    1 
> > > >  ass.c       |   68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > > >  ass.h       |   53 ++++++++++++++++++++++++++++++++++++++++++++++
> > > >  assdec.c    |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > > >  assenc.c    |   68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > > >  6 files changed, 255 insertions(+)
> > > > 5e1fe4c1b65d3b526bda4518936839fb7f02a422  ass_enc_dec.diff
> > > > commit 56aade3d85939478b6ef05dd249936292041fddc
> > > > Author: Aurelien Jacobs <aurel at gnuage.org>
> > > > Date:   Mon Aug 30 15:00:57 2010 +0200
> > > > 
> > > >     add ASS encoder and decoder
> > > > 
> > > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> > > > index 385ae02..d4afc0b 100644
> > > > --- a/libavcodec/Makefile
> > > > +++ b/libavcodec/Makefile
> > > > @@ -66,6 +66,8 @@ OBJS-$(CONFIG_AMV_DECODER)             += sp5xdec.o mjpegdec.o mjpeg.o
> > > >  OBJS-$(CONFIG_ANM_DECODER)             += anm.o
> > > >  OBJS-$(CONFIG_ANSI_DECODER)            += ansi.o cga_data.o
> > > >  OBJS-$(CONFIG_APE_DECODER)             += apedec.o
> > > > +OBJS-$(CONFIG_ASS_DECODER)             += assdec.o
> > > > +OBJS-$(CONFIG_ASS_ENCODER)             += assenc.o
> > > >  OBJS-$(CONFIG_ASV1_DECODER)            += asv1.o mpeg12data.o
> > > >  OBJS-$(CONFIG_ASV1_ENCODER)            += asv1.o mpeg12data.o
> > > >  OBJS-$(CONFIG_ASV2_DECODER)            += asv1.o mpeg12data.o
> > > > diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> > > > index 89614ab..b42935c 100644
> > > > --- a/libavcodec/allcodecs.c
> > > > +++ b/libavcodec/allcodecs.c
> > > > @@ -341,6 +341,7 @@ void avcodec_register_all(void)
> > > >      REGISTER_ENCDEC  (ADPCM_YAMAHA, adpcm_yamaha);
> > > >  
> > > >      /* subtitles */
> > > > +    REGISTER_ENCDEC  (ASS, ass);
> > > >      REGISTER_ENCDEC  (DVBSUB, dvbsub);
> > > >      REGISTER_ENCDEC  (DVDSUB, dvdsub);
> > > >      REGISTER_DECODER (PGSSUB, pgssub);
> > > > diff --git a/libavcodec/ass.c b/libavcodec/ass.c
> > > > new file mode 100644
> > > > index 0000000..d771cb9
> > > > --- /dev/null
> > > > +++ b/libavcodec/ass.c
> > > > @@ -0,0 +1,68 @@
> > > > +/*
> > > > + * SSA/ASS common funtions
> > > > + * Copyright (c) 2010  Aurelien Jacobs <aurel at gnuage.org>
> > > > + *
> > > > + * This file is part of FFmpeg.
> > > > + *
> > > > + * FFmpeg is free software; you can redistribute it and/or
> > > > + * modify it under the terms of the GNU Lesser General Public
> > > > + * License as published by the Free Software Foundation; either
> > > > + * version 2.1 of the License, or (at your option) any later version.
> > > > + *
> > > > + * FFmpeg is distributed in the hope that it will be useful,
> > > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > > > + * Lesser General Public License for more details.
> > > > + *
> > > > + * You should have received a copy of the GNU Lesser General Public
> > > > + * License along with FFmpeg; if not, write to the Free Software
> > > > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> > > > + */
> > > > +
> > > > +#include "avcodec.h"
> > > > +#include "ass.h"
> > > > +
> > > 
> > > > +void ff_ass_init(AVSubtitle *sub)
> > > > +{
> > > > +    memset(sub, 0, sizeof(*sub));
> > > > +}
> > > 
> > > why not call memset() directly ?
> > 
> > I hesitated between the 2 solutions, but having a dedicated function
> > looked slightly better. It will be called by a whole bunch of decoders
> > which don't need to know about AVSubtitle internals.
> > If a new field is added to AVSubtitle that need to be initialized to
> > something else than 0, it will be much easier to update this
> > ff_ass_init() function, than to update all the decoders...
> > 
> > So I still stlightly prefer having this wrapper function, but if you
> > strongly dislike it, I will inline it into the decoders.
> 
> do as you prefer

Applied.

Aurel



More information about the ffmpeg-devel mailing list