[vlc-commits] [Git][videolan/vlc][master] 2 commits: video_filter: port opencv_wrapper module to C++

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Thu May 14 17:03:50 UTC 2026



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
59de6d1b by Brandon Li at 2026-05-14T18:53:12+02:00
video_filter: port opencv_wrapper module to C++

Co-authored-by: Stefan Brüns <stefan.bruens at rwth-aachen.de>

- - - - -
163d5862 by Brandon Li at 2026-05-14T18:53:12+02:00
configure: detect opencv4 via pkg-config

Co-authored-by: Stefan Brüns <stefan.bruens at rwth-aachen.de>

- - - - -


5 changed files:

- configure.ac
- modules/video_filter/Makefile.am
- modules/video_filter/meson.build
- modules/video_filter/opencv_wrapper.c → modules/video_filter/opencv_wrapper.cpp
- po/POTFILES.in


Changes:

=====================================
configure.ac
=====================================
@@ -2228,7 +2228,30 @@ PKG_ENABLE_MODULES_VLC([BLURAY], [libbluray], [libbluray >= 1.1.0], (libbluray f
 dnl
 dnl  OpenCV wrapper and example filters
 dnl
-PKG_ENABLE_MODULES_VLC([OPENCV], [opencv_example opencv_wrapper], [opencv > 2.0], (OpenCV (computer vision) filter), [auto])
+AC_ARG_ENABLE(opencv, [AS_HELP_STRING([--enable-opencv], [OpenCV (computer vision) filter (default auto)])])
+AS_IF([test "${enable_opencv}" != "no"], [
+  have_opencv="no"
+  PKG_CHECK_MODULES([OPENCV], [opencv4], [
+    have_opencv="yes"
+  ], [
+    PKG_CHECK_MODULES([OPENCV], [opencv > 2.0], [
+      have_opencv="yes"
+    ], [
+      AS_IF([test -n "${enable_opencv}"], [
+        AC_MSG_ERROR([${OPENCV_PKG_ERRORS}.])
+      ])
+    ])
+  ])
+  AS_IF([test "${have_opencv}" != "no"], [
+    VLC_ADD_PLUGIN([opencv_example opencv_wrapper])
+    VLC_ADD_LIBS([opencv_example opencv_wrapper], [$OPENCV_LIBS])
+    VLC_ADD_CXXFLAGS([opencv_example opencv_wrapper], [$OPENCV_CFLAGS])
+  ], [
+    AC_MSG_WARN([${OPENCV_PKG_ERRORS}.])
+    enable_opencv="no"
+  ])
+])
+AM_CONDITIONAL(HAVE_OPENCV, [test "$enable_opencv" != "no"])
 
 dnl
 dnl OpenCV4 + sam3 (SAM3 segmentation filter)


=====================================
modules/video_filter/Makefile.am
=====================================
@@ -225,7 +225,7 @@ video_filter_PLUGINS += libglblend_plugin.la
 endif
 endif
 
-libopencv_wrapper_plugin_la_SOURCES = video_filter/opencv_wrapper.c
+libopencv_wrapper_plugin_la_SOURCES = video_filter/opencv_wrapper.cpp
 libopencv_wrapper_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(OPENCV_CFLAGS)
 libopencv_wrapper_plugin_la_LIBADD = $(OPENCV_LIBS)
 libopencv_wrapper_plugin_la_LDFLAGS = $(AM_LDFLAGS) $(video_filter_RPATH)


=====================================
modules/video_filter/meson.build
=====================================
@@ -409,7 +409,7 @@ opencv_dep = dependency('opencv4',
 
 vlc_modules += {
     'name' : 'opencv_wrapper',
-    'sources' : files('opencv_wrapper.c'),
+    'sources' : files('opencv_wrapper.cpp'),
     'dependencies' : [m_lib, opencv_dep],
     'enabled' : opencv_dep.found()
 }


=====================================
modules/video_filter/opencv_wrapper.c → modules/video_filter/opencv_wrapper.cpp
=====================================
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * opencv_wrapper.c : OpenCV wrapper video filter
+ * opencv_wrapper.cpp : OpenCV wrapper video filter
  *****************************************************************************
  * Copyright (C) 2006-2012 VLC authors and VideoLAN
  * Copyright (C) 2012 Edward Wang
@@ -30,6 +30,8 @@
 # include "config.h"
 #endif
 
+#include <new>
+
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_vout.h>
@@ -88,6 +90,8 @@ vlc_module_begin ()
 vlc_module_end ()
 
 
+namespace {
+
 /*****************************************************************************
  * wrapper_output_t: what video is output
  *****************************************************************************/
@@ -114,7 +118,7 @@ enum internal_chroma_t
  * This structure is part of the video output thread descriptor.
  * It describes the opencv_wrapper specific properties of an output thread.
  *****************************************************************************/
-typedef struct
+struct filter_sys_t
 {
     image_handler_t *p_image;
 
@@ -133,7 +137,9 @@ typedef struct
     filter_t *p_opencv;
 
     picture_t hacked_pic;
-} filter_sys_t;
+};
+
+} // namespace
 
 /*****************************************************************************
  * Create: allocates opencv_wrapper video thread output method
@@ -146,8 +152,8 @@ static int Create( filter_t* p_filter )
     char *psz_chroma, *psz_output;
 
     /* Allocate structure */
-    p_sys = malloc( sizeof( filter_sys_t ) );
-    if( p_sys == NULL )
+    p_sys = new (std::nothrow) filter_sys_t;
+    if( !p_sys )
         return VLC_ENOMEM;
 
     /* Load the internal OpenCV filter.
@@ -159,9 +165,9 @@ static int Create( filter_t* p_filter )
      * We don't need to set up video formats for this filter as it not
      * actually using a picture_t.
      */
-    p_sys->p_opencv = vlc_object_create( p_filter, sizeof(filter_t) );
+    p_sys->p_opencv = vlc_object_create<filter_t>( p_filter );
     if( !p_sys->p_opencv ) {
-        free( p_sys );
+        delete p_sys;
         return VLC_ENOMEM;
     }
 
@@ -178,7 +184,7 @@ static int Create( filter_t* p_filter )
         msg_Err( p_filter, "can't open internal opencv filter: %s", psz_inner_name );
         free( psz_inner_name );
         vlc_object_delete(p_sys->p_opencv);
-        free( p_sys );
+        delete p_sys;
 
         return VLC_ENOENT;
     }
@@ -245,11 +251,15 @@ static int Create( filter_t* p_filter )
     msg_Dbg( p_filter, "opencv_wrapper successfully started" );
 #endif
 
-    static const struct vlc_filter_operations filter_ops =
-    {
-        .filter_video = Filter, .close = Destroy,
-    };
-    p_filter->ops = &filter_ops;
+    static const struct FilterOperationInitializer {
+        struct vlc_filter_operations ops {};
+        FilterOperationInitializer()
+        {
+            ops.filter_video = Filter;
+            ops.close        = Destroy;
+        };
+    } filter_ops;
+    p_filter->ops = &filter_ops.ops;
     p_filter->p_sys = p_sys;
 
     return VLC_SUCCESS;
@@ -262,13 +272,13 @@ static int Create( filter_t* p_filter )
  *****************************************************************************/
 static void Destroy( filter_t* p_filter )
 {
-    filter_sys_t *p_sys = p_filter->p_sys;
+    filter_sys_t *p_sys = static_cast<filter_sys_t *>(p_filter->p_sys);
     ReleaseImages( p_filter );
 
     // Release the internal OpenCV filter.
     vlc_filter_Delete( p_sys->p_opencv );
 
-    free( p_sys );
+    delete p_sys;
 }
 
 /*****************************************************************************
@@ -276,7 +286,7 @@ static void Destroy( filter_t* p_filter )
  *****************************************************************************/
 static void ReleaseImages( filter_t* p_filter )
 {
-    filter_sys_t* p_sys = p_filter->p_sys;
+    filter_sys_t* p_sys = static_cast<filter_sys_t *>(p_filter->p_sys);
 
     for( int i = 0; i < VOUT_MAX_PLANES; i++ )
     {
@@ -312,7 +322,7 @@ static void VlcPictureToIplImage( filter_t* p_filter, picture_t* p_in )
     // input video size
     CvSize sz = cvSize(p_in->format.i_width, p_in->format.i_height);
     video_format_t fmt_out;
-    filter_sys_t* p_sys = p_filter->p_sys;
+    filter_sys_t* p_sys = static_cast<filter_sys_t *>(p_filter->p_sys);
 
     memset( &fmt_out, 0, sizeof(video_format_t) );
 
@@ -397,7 +407,7 @@ static void VlcPictureToIplImage( filter_t* p_filter, picture_t* p_in )
  *****************************************************************************/
 static picture_t* Filter( filter_t* p_filter, picture_t* p_pic )
 {
-    filter_sys_t *p_sys = p_filter->p_sys;
+    filter_sys_t *p_sys = static_cast<filter_sys_t *>(p_filter->p_sys);
     picture_t* p_outpic = filter_NewPicture( p_filter );
     if( p_outpic == NULL ) {
         msg_Err( p_filter, "couldn't get a p_outpic!" );


=====================================
po/POTFILES.in
=====================================
@@ -1323,7 +1323,7 @@ modules/video_filter/motionblur.c
 modules/video_filter/motiondetect.c
 modules/video_filter/oldmovie.c
 modules/video_filter/opencv_example.cpp
-modules/video_filter/opencv_wrapper.c
+modules/video_filter/opencv_wrapper.cpp
 modules/video_filter/posterize.c
 modules/video_filter/postproc.c
 modules/video_filter/psychedelic.c



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/04e596de5cb46bee1bc804aa048030828e9f98f2...163d5862c36d3158eeb65466e44d99d3da7b5133

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/04e596de5cb46bee1bc804aa048030828e9f98f2...163d5862c36d3158eeb65466e44d99d3da7b5133
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list