[FFmpeg-devel] [PATCH v4 09/18] avfilter/subtitles: Add subtitles.c

Soft Works softworkz at hotmail.com
Sat Sep 11 11:25:36 EEST 2021


Signed-off-by: softworkz <softworkz at hotmail.com>
---
 libavfilter/Makefile       |  1 +
 libavfilter/f_interleave.c |  3 ++
 libavfilter/internal.h     |  1 +
 libavfilter/subtitles.c    | 61 ++++++++++++++++++++++++++++++++++++++
 libavfilter/subtitles.h    | 44 +++++++++++++++++++++++++++
 5 files changed, 110 insertions(+)
 create mode 100644 libavfilter/subtitles.c
 create mode 100644 libavfilter/subtitles.h

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index af957a5ac0..a510dd12b4 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/f_interleave.c b/libavfilter/f_interleave.c
index b60e89762f..e8821dceba 100644
--- a/libavfilter/f_interleave.c
+++ b/libavfilter/f_interleave.c
@@ -32,6 +32,7 @@
 #include "filters.h"
 #include "internal.h"
 #include "audio.h"
+#include "subtitles.h"
 #include "video.h"
 
 typedef struct InterleaveContext {
@@ -170,6 +171,8 @@ static av_cold int init(AVFilterContext *ctx)
             inpad.get_buffer.video = ff_null_get_video_buffer; break;
         case AVMEDIA_TYPE_AUDIO:
             inpad.get_buffer.audio = ff_null_get_audio_buffer; break;
+        case AVMEDIA_TYPE_SUBTITLE:
+            inpad.get_buffer.subtitle = ff_null_get_subtitles_buffer; break;
         default:
             av_assert0(0);
         }
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 6ddf024d93..8a9951d20e 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..90ec479e51
--- /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_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.
+*/
+AVFrame *ff_get_subtitles_buffer(AVFilterLink *link, int format);
+
+#endif /* AVFILTER_SUBTITLES_H */
-- 
2.30.2.windows.1



More information about the ffmpeg-devel mailing list