From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id BBF7949F14
	for <ffmpegdev@gitmailbox.com>; Mon, 24 Mar 2025 15:56:14 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1063F687BD7;
	Mon, 24 Mar 2025 17:56:10 +0200 (EET)
Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com
 [209.85.128.46])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C016A68097C
 for <ffmpeg-devel@ffmpeg.org>; Mon, 24 Mar 2025 17:56:02 +0200 (EET)
Received: by mail-wm1-f46.google.com with SMTP id
 5b1f17b1804b1-43948f77f1aso30386995e9.0
 for <ffmpeg-devel@ffmpeg.org>; Mon, 24 Mar 2025 08:56:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1742831762; x=1743436562; darn=ffmpeg.org;
 h=content-transfer-encoding:in-reply-to:content-language:references
 :to:subject:from:user-agent:mime-version:date:message-id:from:to:cc
 :subject:date:message-id:reply-to;
 bh=xAPKMCUuBiFdqURmQG6BAHDp8anoy3/pPm6x6ewuyos=;
 b=mJm92lHzDj2HTPPV5uwS+s2/mVXqXnTrVLM0LP85dh9mLE2poXL1WXR5OInIvbsxMz
 7vvJBKUmb+dOoDHG6bCEboBT6sWC6LLz9s5iYDHEfb0YjMk4iiOVAsADEeuh7mP0Jqsz
 ebQUm6eXXt2jHCIrmmwuhkvvSb2EXhpQxGn1LHkKdRdkPXiRxQ6C8pqDUz9gG3kbNHBZ
 kvdIfotqNb2djoAGOtRdZa+OH+BSVZvoIOSaVwaUd6ekpcMd0/9bT4eAB1nuvmPEMldk
 QNDFJKF+fKLelf7VGk1DP3IB0ZR5KhEb6EER5V3klObulRO2FvceWDys5p8lAQXVBcLN
 6WHA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1742831762; x=1743436562;
 h=content-transfer-encoding:in-reply-to:content-language:references
 :to:subject:from:user-agent:mime-version:date:message-id
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=xAPKMCUuBiFdqURmQG6BAHDp8anoy3/pPm6x6ewuyos=;
 b=fUivIwOvLnlAs6/MCxMcc5m0qQQvtz4Bn1d0HEnlcHMG7XGzPm7O8XHy6P1MFsO7Y3
 d4iXrMtC9r9AfmH1k24vYl1tZhH9+/aJ2WkyHbId7hZTgpb/15miFj07E75MxKSo9ZaM
 6wuCrCDLNVcritncVsX+dJsnqCu/mZzEMK8COsEZRcpczbromNk0OOeFHrpzXI6weoty
 ZAqI2sSSvYqUkhEb/i0ILahqyM7VvjaTCViGdiaz9OM4r6ITsfvqljiSyQMPN7illFyR
 2xCZBqdmFdzm7mKQ8oq0Ljl04UXqkbsPBRMeL+Cp0UfRinlv405q+jsNjJo2MikS5uq+
 3b4A==
X-Gm-Message-State: AOJu0YxLfckgvbvffD5/jNkooqCLCodOxKKT2ouqlCrfbOk2ti5ceYrM
 kAPA/kltoxRGBiGKkFMjXBEhxkPXZOAevwvf52uhPOoCAJj8e5iepOoYcSmY
X-Gm-Gg: ASbGnctt1a1d2lzSxF/YY2jGkciHh1h+EQFH3/JRXC9WSeh3Sys4ZV+t/FZps5lCnoW
 ybhBxQcF1KWMD/RpqpdzL9kapfQ/xrlrIFgQUhs6GcZ1HN/ABkXlUuQPg8Q5r5gLtl8KZHsleGj
 ptW8I36fOiI3pY5fmRIXOYsUKIWUdtpiPW5u3C3srumDdgFLAOKicrS55mfp6bSGoe28w/3xjen
 k/oYzAVq1XRmTSbE69C/k8ke6YjCc+ZVsx2jrMP2NnCNq9UJLNwjllgDvSTdcor2lz9jAX9VRyC
 pU1vVMKylNVLn0m0z1V29aX8vRdlhpBbr1JV65sBp+9p1agJu6IyHpRW5+7T/QtumcOwSGmwqU1
 rlj7rdZ1eyfr1mcNBgFyDNao=
X-Google-Smtp-Source: AGHT+IEGWtcsUNaAek98fRqBvetaWBY7E28NIP8uT/OeiCAMQAGshwie024oCRll7q+R8mfD4gtkgw==
X-Received: by 2002:a5d:59a6:0:b0:390:f6aa:4e72 with SMTP id
 ffacd0b85a97d-3997f8fabdbmr11398300f8f.18.1742831761697; 
 Mon, 24 Mar 2025 08:56:01 -0700 (PDT)
Received: from ?IPV6:2001:9e8:1da6:4200:189b:8e2c:55b0:b44b?
 ([2001:9e8:1da6:4200:189b:8e2c:55b0:b44b])
 by smtp.gmail.com with ESMTPSA id
 ffacd0b85a97d-3997f9efc9bsm11111884f8f.87.2025.03.24.08.56.00
 for <ffmpeg-devel@ffmpeg.org>
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Mon, 24 Mar 2025 08:56:00 -0700 (PDT)
Message-ID: <2477728b-6217-446a-9a15-830f028baea0@gmail.com>
Date: Mon, 24 Mar 2025 16:56:00 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
From: Leandro Santiago <leandrosansilva@gmail.com>
To: ffmpeg-devel@ffmpeg.org
References: <6bef7ee3-6e0b-496a-9018-ce02d5e8cd63@gmail.com>
Content-Language: en-US
In-Reply-To: <6bef7ee3-6e0b-496a-9018-ce02d5e8cd63@gmail.com>
Subject: [FFmpeg-devel] [PATCH] avfilter: Proof of Concept: enable
 out-of-tree filters
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/2477728b-6217-446a-9a15-830f028baea0@gmail.com/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

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"
 
 
-- 
2.48.1

_______________________________________________
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".