[FFmpeg-devel] [PATCH v8 03/13] avfilter/subtitles: Add subtitles.c for subtitle frame allocation

Soft Works softworkz at hotmail.com
Wed Sep 22 03:08:47 EEST 2021



> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> On Behalf Of Andreas
> Rheinhardt
> Sent: Wednesday, 22 September 2021 02:00
> To: ffmpeg-devel at ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v8 03/13] avfilter/subtitles: Add
> subtitles.c for subtitle frame allocation
> 
> Soft Works:
> > Analog to avfilter/video.c and avfilter/audio.c
> >
> > Signed-off-by: softworkz <softworkz at hotmail.com>
> > ---
> >  libavfilter/Makefile    |  1 +
> >  libavfilter/avfilter.c  |  4 +++
> >  libavfilter/internal.h  |  1 +
> >  libavfilter/subtitles.c | 61 +++++++++++++++++++++++++++++++++++++++++
> >  libavfilter/subtitles.h | 44 +++++++++++++++++++++++++++++
> >  5 files changed, 111 insertions(+)
> >  create mode 100644 libavfilter/subtitles.c
> >  create mode 100644 libavfilter/subtitles.h
> >
> > diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> > index f059f3fef8..041d3c5382 100644
> > --- a/libavfilter/Makefile
> > +++ b/libavfilter/Makefile
> > @@ -19,6 +19,7 @@ OBJS = allfilters.o
> \
> >         framequeue.o                                                     \
> >         graphdump.o                                                      \
> >         graphparser.o                                                    \
> > +       subtitles.o                                                      \
> >         video.o                                                          \
> >
> >  OBJS-$(HAVE_THREADS)                         += pthread.o
> > diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> > index f325918021..ef349a67f9 100644
> > --- a/libavfilter/avfilter.c
> > +++ b/libavfilter/avfilter.c
> > @@ -43,6 +43,7 @@
> >  #include "formats.h"
> >  #include "framepool.h"
> >  #include "internal.h"
> > +#include "subtitles.h"
> >
> >  #include "libavutil/ffversion.h"
> >  const char av_filter_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
> > @@ -1476,6 +1477,9 @@ int ff_inlink_make_frame_writable(AVFilterLink *link,
> AVFrame **rframe)
> >      case AVMEDIA_TYPE_AUDIO:
> >          out = ff_get_audio_buffer(link, frame->nb_samples);
> >          break;
> > +    case AVMEDIA_TYPE_SUBTITLE:
> > +        out = ff_get_subtitles_buffer(link, link->format);
> > +        break;
> >      default:
> >          return AVERROR(EINVAL);
> >      }
> > diff --git a/libavfilter/internal.h b/libavfilter/internal.h
> > index e7c154aff0..8977dda2b3 100644
> > --- a/libavfilter/internal.h
> > +++ b/libavfilter/internal.h
> > @@ -90,6 +90,7 @@ struct AVFilterPad {
> >      union {
> >          AVFrame *(*video)(AVFilterLink *link, int w, int h);
> >          AVFrame *(*audio)(AVFilterLink *link, int nb_samples);
> > +        AVFrame *(*subtitle)(AVFilterLink *link, int format);
> >      } get_buffer;
> >
> >      /**
> > diff --git a/libavfilter/subtitles.c b/libavfilter/subtitles.c
> > new file mode 100644
> > index 0000000000..fd2e7c3c0f
> > --- /dev/null
> > +++ b/libavfilter/subtitles.c
> > @@ -0,0 +1,61 @@
> > +/*
> > + * Copyright (c) 2021 softworkz
> > + *
> > + * 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 "libavutil/common.h"
> > +
> > +#include "subtitles.h"
> > +#include "avfilter.h"
> > +#include "internal.h"
> > +
> > +
> > +AVFrame *ff_null_get_subtitles_buffer(AVFilterLink *link, int format)
> > +{
> > +    return ff_get_subtitles_buffer(link->dst->outputs[0], format);
> > +}
> > +
> > +AVFrame *ff_default_get_subtitles_buffer(AVFilterLink *link, int format)
> > +{
> > +    AVFrame *frame;
> > +
> > +    frame = av_frame_alloc();
> > +    if (!frame)
> > +        return NULL;
> > +
> > +    frame->format = format;
> > +    frame->type = AVMEDIA_TYPE_SUBTITLE;
> > +
> > +    if (av_frame_get_buffer2(frame, 0) < 0)
> 
> Leak.

Right. Thanks!

> 
> > +        return NULL;
> > +
> > +    return frame;
> > +}
> > +
> > +AVFrame *ff_get_subtitles_buffer(AVFilterLink *link, int format)
> > +{
> > +    AVFrame *ret = NULL;
> > +
> > +    if (link->dstpad->get_buffer.subtitle)
> > +        ret = link->dstpad->get_buffer.subtitle(link, format);
> > +
> > +    if (!ret)
> > +        ret = ff_default_get_subtitles_buffer(link, format);
> > +
> > +    return ret;
> > +}
> > diff --git a/libavfilter/subtitles.h b/libavfilter/subtitles.h
> > new file mode 100644
> > index 0000000000..d3d5491652
> > --- /dev/null
> > +++ b/libavfilter/subtitles.h
> > @@ -0,0 +1,44 @@
> > +/*
> > + * Copyright (c) 2021 softworkz
> > + *
> > + * 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 AVFILTER_SUBTITLES_H
> > +#define AVFILTER_SUBTITLES_H
> > +
> > +#include "avfilter.h"
> > +#include "internal.h"
> > +
> > +/** default handler for get_subtitles_buffer() for subtitle inputs */
> > +AVFrame *ff_default_get_subtitles_buffer(AVFilterLink *link, int format);
> > +
> > +/** get_subtitles_buffer() handler for filters which simply pass subtitles
> along */
> > +AVFrame *ff_null_get_subtitles_buffer(AVFilterLink *link, int format);
> > +
> > +/**
> > + * Request a subtitles buffer with a specific set of permissions.
> > + *
> > + * @param link           the output link to the filter from which the
> buffer will
> > + *                       be requested
> > + * @param format         The subtitles format.
> > + * @return               A reference to the subtitles. This must be
> unreferenced with
> > + *                       avfilter_unref_buffer when you are finished with
> it.
> 
> avfilter_unref_buffer?

I adopted this from audio.h and video.h. Actually a few more things 
are wrong here - not only the doc strings, even the naming of 
those functions..

softworkz



More information about the ffmpeg-devel mailing list