[FFmpeg-devel] [PATCH 2/9] avfilter/subtitles: Add subtitles.c

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Fri Aug 20 06:10:06 EEST 2021


Soft Works:
> Signed-off-by: softworkz <softworkz at hotmail.com>
> ---
>  libavfilter/Makefile    |  1 +
>  libavfilter/internal.h  |  8 ++++++
>  libavfilter/subtitles.c | 61 +++++++++++++++++++++++++++++++++++++++++
>  libavfilter/subtitles.h | 42 ++++++++++++++++++++++++++++
>  4 files changed, 112 insertions(+)
>  create mode 100644 libavfilter/subtitles.c
>  create mode 100644 libavfilter/subtitles.h
> 
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 102ce7beff..db32cf1265 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -19,6 +19,7 @@ OBJS = allfilters.o                                                     \
>         framequeue.o                                                     \
>         graphdump.o                                                      \
>         graphparser.o                                                    \
> +       subtitles.o                                                          \

Weird alignment.

>         video.o                                                          \
>  
>  OBJS-$(HAVE_THREADS)                         += pthread.o
> diff --git a/libavfilter/internal.h b/libavfilter/internal.h
> index a0aa32af4d..4f9aedf151 100644
> --- a/libavfilter/internal.h
> +++ b/libavfilter/internal.h
> @@ -87,6 +87,14 @@ struct AVFilterPad {
>          AVFrame *(*audio)(AVFilterLink *link, int nb_samples);
>      } get_buffer;
>  
> +    /**
> +     * Callback function to get a subtitle buffer. If NULL, the filter system will
> +     * use ff_default_get_subtitle_buffer().
> +     *
> +     * Input subtitle pads only.
> +     */
> +    AVFrame *(*get_subtitle_buffer)(AVFilterLink *link, int format);
> +

While there is no git-conflict with my patch, there is a conflict in
spirit: This pad has one type and only needs one get_buffer callback. In
other words, put it in the union above.

>      /**
>       * Filtering callback. This is where a filter receives a frame with
>       * audio/video data and should do its processing.
> diff --git a/libavfilter/subtitles.c b/libavfilter/subtitles.c
> new file mode 100644
> index 0000000000..188ff1289c
> --- /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 = NULL;
> +
> +    // TODO:
> +    //frame = ff_frame_pool_get(link->frame_pool);
> +
> +    frame = av_frame_alloc();
> +    if (!frame)
> +        return NULL;
> +
> +    frame->format = format;
> +    frame->type = AVMEDIA_TYPE_SUBTITLE;
> +
> +    return frame;
> +}
> +
> +AVFrame *ff_get_subtitles_buffer(AVFilterLink *link, int format)
> +{
> +    AVFrame *ret = NULL;
> +
> +    if (link->dstpad->get_subtitle_buffer)
> +        ret = link->dstpad->get_subtitle_buffer(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..b964b61c37
> --- /dev/null
> +++ b/libavfilter/subtitles.h
> @@ -0,0 +1,42 @@
> +/*
> + * 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
> + * @return               The subtitles format.

I suppose this is supposed to be the documentation for format.

> + */
> +AVFrame *ff_get_subtitles_buffer(AVFilterLink *link, int format);
> +
> +#endif /* AVFILTER_SUBTITLES_H */
> 



More information about the ffmpeg-devel mailing list