Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Leandro Santiago <leandrosansilva@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] avfilter: Proof of Concept: enable out-of-tree filters
Date: Mon, 24 Mar 2025 17:20:02 +0100
Message-ID: <8bdfe841-080b-49f6-913b-7577d03a1214@gmail.com> (raw)
In-Reply-To: <2477728b-6217-446a-9a15-830f028baea0@gmail.com>

In this iteration I've made the following changes, based on the received feedback:

- No external tools are needed by the build system.

- The external filters should be put in ext/libavfilter. Anything there will be included.

- The build system will execute a file called `configure.sh` in the directory of the external filter. This script has access to the functions and variables defined on `./configure`, as it's included via `.` on sh.

- I will document the "API" for the external filters as soon the approach is approved, but an example of filter can be found at https://gitlab.com/leandrosansilva/ffmpeg-extra-filter-example . If you are unhappy with the example code hosted on gitlab.com, I can move it elsewhere where it gets easier for you to have access to the code.

- Essentially, an external filter is composed by at least a `configure.sh` and a `Makefile`.

I really hope this can be the last iteration, as I ran out of ideas on how to simplify the process, so please let me know your thoughts :-)

Leandro

On 3/24/25 16:56, Leandro Santiago wrote:
> This is a POC/prototype that aims to enable out of tree filters on
> FFmpeg.
>
> Here is how to test it, with an example filter:
>
> ```
> mkdir -p ext/libavfilter
> pushd ext/libavfilter
> git clone https://gitlab.com/leandrosansilva/ffmpeg-extra-filter-example example
> popd
> ```
>
> Then compile ffmpeg as usual:
>
> ```
> ./configure && make && make install
> ```
>
> Now you can use the new filters:
>
> ```
> ffplay /path/to/file.webm -vf 'foo,bar'
> ```
>
> What works:
>
> - Building C based filters with no extra, or simple dependencies.
> - Multiple filters in the same object file.
>
> What was not implemented:
>
> - I believe it would be useful to check if the license of the filter is
>   compatible with the license used to build FFmpeg.
>
> - Only extra filters written in C (maybe C++?) are supported for now.
>   One of my goals is to enable Rust as well.
>
> - Documentation
>
> - There should be a way to have optional dependencies, for filters that
>   can have multiple "backends", for instance, to be chosen at build time.
>
> Signed-off-by: Leandro Santiago <leandrosansilva@gmail.com>
> ---
>  .gitignore               |  3 ++
>  configure                | 60 ++++++++++++++++++++++++++++++++++++++--
>  libavfilter/Makefile     |  4 +++
>  libavfilter/allfilters.c |  1 +
>  4 files changed, 66 insertions(+), 2 deletions(-)
>
> diff --git a/.gitignore b/.gitignore
> index 430abaf91b..7d66dee516 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -44,3 +44,6 @@
>  /tools/python/__pycache__/
>  /libavcodec/vulkan/*.c
>  /libavfilter/vulkan/*.c
> +/ffbuild/external-filters.mak
> +/libavfilter/external_filters_extern.h
> +/ext
> diff --git a/configure b/configure
> index 2fdbe8cbbe..317862fa1a 100755
> --- a/configure
> +++ b/configure
> @@ -1798,6 +1798,7 @@ AVDEVICE_COMPONENTS="
>  
>  AVFILTER_COMPONENTS="
>      filters
> +    external_filters
>  "
>  
>  AVFORMAT_COMPONENTS="
> @@ -4086,7 +4087,7 @@ swscale_deps="avutil"
>  swscale_suggest="libm stdatomic"
>  
>  avcodec_extralibs="pthreads_extralibs iconv_extralibs dxva2_extralibs liblcevc_dec_extralibs lcms2_extralibs"
> -avfilter_extralibs="pthreads_extralibs"
> +avfilter_extralibs="pthreads_extralibs external_filters_extralibs"
>  avutil_extralibs="d3d11va_extralibs d3d12va_extralibs mediacodec_extralibs nanosleep_extralibs pthreads_extralibs vaapi_drm_extralibs vaapi_x11_extralibs vaapi_win32_extralibs vdpau_x11_extralibs"
>  
>  # programs
> @@ -4324,10 +4325,15 @@ ALL_COMPONENTS="
>      $AVFORMAT_COMPONENTS_LIST
>  "
>  
> -for n in $COMPONENT_LIST; do
> +enable_component() {
> +    n="$1"
>      v=$(toupper ${n%s})_LIST
>      eval enable \$$v
>      eval ${n}_if_any="\$$v"
> +}
> +
> +for n in $COMPONENT_LIST; do
> +    enable_component "$n"
>  done
>  
>  enable $ARCH_EXT_LIST
> @@ -7463,6 +7469,56 @@ elif enabled iconv; then
>      check_func_headers iconv.h iconv || check_lib iconv iconv.h iconv -liconv
>  fi
>  
> +# Handle external filters from the directory ext/libavfilter
> +
> +echo "" > libavfilter/external_filters_extern.h
> +echo "" > ffbuild/external-filters.mak
> +
> +EXTERNAL_FILTER_LIST=""
> +
> +# This function is used by the external filters' configure.sh script to register the filters
> +register_external_filter_symbol() {
> +    EXT_FILTER_SYMBOL="$1"
> +    EXTERNAL_FILTER_LIST="$EXTERNAL_FILTER_LIST $(echo $EXT_FILTER_SYMBOL | sed 's/^ff_[avfsinkrc]\{2,5\}_\([[:alnum:]_]\{1,\}\)/\1_filter/')"
> +
> +    eval "$(echo "$EXT_FILTER_SYMBOL" | sed 's/^ff_\([avfsinkrc]\{2,5\}\)_\([[:alnum:]]\{1,\}\)$/full_filter_name_\2=\1_\2/')"
> +
> +    echo "extern const FFFilter $EXT_FILTER_SYMBOL;" >> libavfilter/external_filters_extern.h
> +
> +    echo "EXTERNAL_FILTER_$(\
> +        echo $EXT_FILTER_SYMBOL \
> +        | sed 's/^ff_[avfsinkrc]\{2,5\}_\([[:alnum:]]\{1,\}\)$/\1/' \
> +        | tr a-z A-Z \
> +        )_LOCATION = $CURRENT_EXT_FILTER_LOCATION" >> ffbuild/external-filters.mak
> +}
> +
> +if [ -d "ext/libavfilter" ]; then
> +    for f in ext/libavfilter/*; do
> +        [ -f "$f/configure.sh" ] || die "Mandatory file $f/configure.sh not found"
> +        [ -f "$f/Makefile" ] || die "Mandatory file $f/Makefile not found"
> +        CURRENT_EXT_FILTER_LOCATION="$f"
> +        . "$f/configure.sh" || die "Could not configure external filter at $f"
> +        echo "include $f/Makefile" >> ffbuild/external-filters.mak
> +    done
> +
> +    enable_component external_filters
> +fi
> +
> +FILTER_LIST="
> +    $FILTER_LIST
> +    $EXTERNAL_FILTER_LIST
> +"
> +
> +AVFILTER_COMPONENTS_LIST="
> +    $AVFILTER_COMPONENTS_LIST
> +    $EXTERNAL_FILTER_LIST
> +"
> +
> +ALL_COMPONENTS="
> +    $ALL_COMPONENTS
> +    $EXTERNAL_FILTER_LIST
> +"
> +
>  enabled debug && add_cflags -g"$debuglevel" && add_asflags -g"$debuglevel"
>  
>  # add some useful compiler flags if supported
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 7c0d879ec9..877b24c30f 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -27,6 +27,10 @@ OBJS = allfilters.o                                                     \
>  include $(SRC_PATH)/libavfilter/dnn/Makefile
>  include $(SRC_PATH)/libavfilter/vulkan/Makefile
>  
> +# external filters handling
> +include $(SRC_PATH)/ffbuild/external-filters.mak
> +EXTERNAL_FILTER_FLAGS = -I$(PWD) -I$(PWD)/libavfilter
> +
>  OBJS-$(HAVE_LIBC_MSVCRT)                     += file_open.o
>  OBJS-$(HAVE_THREADS)                         += pthread.o
>  
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 740d9ab265..c2d576e4be 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -621,6 +621,7 @@ extern  const FFFilter ff_vsrc_buffer;
>  extern  const FFFilter ff_asink_abuffer;
>  extern  const FFFilter ff_vsink_buffer;
>  
> +#include "libavfilter/external_filters_extern.h"
>  #include "libavfilter/filter_list.c"
>  
>  
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2025-03-24 16:20 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13 12:18 [FFmpeg-devel] [PATCH] avfilter: POC: " Leandro Santiago
2025-03-13 12:20 ` Leandro Santiago
2025-03-14 15:04 ` Michael Niedermayer
2025-03-14 16:13   ` Leandro Santiago
2025-03-14 20:58     ` Michael Niedermayer
2025-03-14 16:57 ` Lynne
2025-03-14 18:21   ` Nicolas George
2025-03-14 19:43     ` Leandro Santiago
2025-03-14 22:45   ` Soft Works
2025-03-19 13:08 ` [FFmpeg-devel] [PATCH] avfilter: Proof of Concept: " Leandro Santiago
2025-03-24 15:56 ` Leandro Santiago
2025-03-24 16:20   ` Leandro Santiago [this message]
2025-03-25 18:05     ` Ronald S. Bultje
2025-03-26  2:59       ` [FFmpeg-devel] =?gb18030?b?u9i4tKO6ICBbUEFUQ0hdIGF2ZmlsdGVyOiBQ?= =?gb18030?q?roof_of_Concept=3A_enable_out-of-tree_filters?= yangyalei via ffmpeg-devel
2025-03-26  4:26       ` [FFmpeg-devel] [PATCH] avfilter: Proof of Concept: enable out-of-tree filters Zhao Zhili
2025-03-26  6:09       ` softworkz .
2025-03-26 13:51         ` Leandro Santiago
2025-03-26  9:37       ` Leandro Santiago
2025-03-28 21:38     ` Michael Niedermayer
2025-03-28 22:18       ` Nicolas George
2025-03-28 22:23       ` softworkz .
2025-03-29  1:16         ` Michael Niedermayer
2025-03-29  1:45           ` softworkz .
2025-03-29 23:30             ` Michael Niedermayer
2025-03-30  0:51               ` softworkz .
2025-03-30 21:27                 ` Michael Niedermayer
2025-03-30 22:23                   ` softworkz .
2025-03-29 14:52       ` Leandro Santiago
2025-03-30  0:04         ` Michael Niedermayer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8bdfe841-080b-49f6-913b-7577d03a1214@gmail.com \
    --to=leandrosansilva@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git