[vlc-devel] [PATCH] video_filter: add epileptic filter

Steve Lhomme robux4 at ycbcr.xyz
Thu Oct 15 11:15:14 CEST 2020


An extra inverted picture is sent for every picture given.
---
 modules/video_filter/Makefile.am |   2 +
 modules/video_filter/epileptic.c | 115 +++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)
 create mode 100644 modules/video_filter/epileptic.c

diff --git a/modules/video_filter/Makefile.am b/modules/video_filter/Makefile.am
index 7a51d960eb2..26bddf30cb3 100644
--- a/modules/video_filter/Makefile.am
+++ b/modules/video_filter/Makefile.am
@@ -18,6 +18,7 @@ libcanvas_plugin_la_SOURCES = video_filter/canvas.c
 libcolorthres_plugin_la_SOURCES = video_filter/colorthres.c
 libcolorthres_plugin_la_LIBADD = $(LIBM)
 libcroppadd_plugin_la_SOURCES = video_filter/croppadd.c
+libepileptic_plugin_la_SOURCES = video_filter/epileptic.c
 liberase_plugin_la_SOURCES = video_filter/erase.c
 libextract_plugin_la_SOURCES = video_filter/extract.c
 libextract_plugin_la_LIBADD = $(LIBM)
@@ -79,6 +80,7 @@ video_filter_LTLIBRARIES = \
 	libcolorthres_plugin.la \
 	libcroppadd_plugin.la \
 	libedgedetection_plugin.la \
+	libepileptic_plugin.la \
 	liberase_plugin.la \
 	libextract_plugin.la \
 	libgradient_plugin.la \
diff --git a/modules/video_filter/epileptic.c b/modules/video_filter/epileptic.c
new file mode 100644
index 00000000000..f51aff98097
--- /dev/null
+++ b/modules/video_filter/epileptic.c
@@ -0,0 +1,115 @@
+/*****************************************************************************
+ * epileptic.c : Video filter inserting an inverting picture to every frame
+ *****************************************************************************
+ * Copyright © 2020 VLC authors, VideoLAN and VideoLabs
+ *
+ * Authors: Steve Lhomme <robux4 at ycbcr.xyz>
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_filter.h>
+#include <vlc_modules.h>
+
+static int Create(filter_t *);
+
+vlc_module_begin ()
+    set_description( N_("Epileptic effect video filter") )
+    set_shortname( N_("Epileptic effect" ))
+    set_category( CAT_VIDEO )
+    set_subcategory( SUBCAT_VIDEO_VFILTER )
+    add_shortcut( "epileptic" )
+    set_callback_video_filter( Create )
+vlc_module_end ()
+
+typedef struct {
+    filter_t *inverter;
+} filter_sys_t;
+
+static filter_t *CreateInverter(vlc_object_t *object, const video_format_t *fmt)
+{
+    filter_t *filter = vlc_object_create(object, sizeof(*filter));
+    if (!filter)
+        return NULL;
+
+    es_format_InitFromVideo(&filter->fmt_in,  fmt);
+    es_format_InitFromVideo(&filter->fmt_out, fmt);
+
+    filter->p_module = module_need(filter, "video filter", "invert", false);
+    if (!filter->p_module)
+    {
+        vlc_object_delete(filter);
+        return NULL;
+    }
+    assert( filter->ops != NULL );
+    return filter;
+}
+
+static picture_t *Filter(filter_t *p_filter, picture_t *p_pic)
+{
+    filter_sys_t *p_sys = p_filter->p_sys;
+    picture_Hold( p_pic ); // the inverter will release the source
+    picture_t *inverted = p_sys->inverter->ops->filter_video( p_sys->inverter, p_pic );
+    if ( inverted )
+    {
+        inverted->date = p_pic->date + vlc_tick_from_samples( p_filter->fmt_out.video.i_frame_rate_base,
+                                                              p_filter->fmt_out.video.i_frame_rate );
+        vlc_picture_chain_AppendChain( p_pic, inverted );
+    }
+    return p_pic;
+}
+
+static void Close(filter_t *p_filter)
+{
+    filter_sys_t *p_sys = p_filter->p_sys;
+    filter_Close( p_sys->inverter );
+    module_unneed( p_sys->inverter, p_sys->inverter->p_module );
+    vlc_object_delete( p_sys->inverter );
+}
+
+static struct vlc_filter_operations filter_ops = {
+    .filter_video = Filter, .close = Close,
+};
+
+static int Create(filter_t *p_filter)
+{
+    if (!p_filter->b_allow_fmt_out_change)
+        return VLC_EGENERIC;
+
+    filter_sys_t *p_sys = vlc_obj_malloc(VLC_OBJECT(p_filter), sizeof(*p_filter));
+    if (unlikely(p_sys == NULL))
+        return VLC_EGENERIC;
+
+    p_sys->inverter = CreateInverter(VLC_OBJECT(p_filter), &p_filter->fmt_in.video);
+    if (p_sys->inverter == NULL)
+    {
+        vlc_obj_free(VLC_OBJECT(p_filter), p_sys);
+        return VLC_ENOMOD;
+    }
+
+    if (p_filter->fmt_out.video.i_frame_rate)
+        p_filter->fmt_out.video.i_frame_rate *= 2;
+
+    p_filter->p_sys = p_sys;
+    p_filter->ops = &filter_ops;
+
+    return VLC_SUCCESS;
+}
-- 
2.26.2



More information about the vlc-devel mailing list