Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree filters
@ 2025-03-13 12:18 Leandro Santiago
  2025-03-13 12:20 ` Leandro Santiago
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Leandro Santiago @ 2025-03-13 12:18 UTC (permalink / raw)
  To: ffmpeg-devel

This is a POC/prototype that aims to enable out of tree filters on
FFmpeg.

Here I name them "extra filters".

It introduces the program `jq` as a new build dependency.

To test it, create a directory, for instance, /tmp/my-shiny-filter/ and
inside it, create the following files:

`filter.json`, with the content:

```
{
  "check": "require_pkg_config json json-c json-c/json.h json_c_version_num",
  "symbols": ["ff_vf_foo", "ff_vf_bar"]
}
```

`filter.mak`, with the content:

```
OBJS += vf_shiny.o
LIBOBJS += vf_shiny.o

libavfilter/vf_shiny.o:
        $(CC) $(EXTRA_FILTER_FLAGS) -c -o $@ $(EXTRA_FILTER_FOO_LOCATION)/vf_shiny.c
```

`vf_shiny.c` file, with the content:


```
#include "libavutil/internal.h"                                                                                                                       
#include "avfilter.h"                                                                                                                                 #include "filters.h"                                                                                                                                  
#include "video.h" 

const FFFilter ff_vf_bar = {
    .p.name        = "bar",
    .p.description = NULL_IF_CONFIG_SMALL("Example filter Baz"),
    .p.flags       = AVFILTER_FLAG_METADATA_ONLY,
    FILTER_INPUTS(ff_video_default_filterpad),
    FILTER_OUTPUTS(ff_video_default_filterpad),
};

const FFFilter ff_vf_foo = {
    .p.name        = "foo",
    .p.description = NULL_IF_CONFIG_SMALL("Another foo filter"),
    .p.flags       = AVFILTER_FLAG_METADATA_ONLY,
    FILTER_INPUTS(ff_video_default_filterpad),
    FILTER_OUTPUTS(ff_video_default_filterpad),
};
```

Then, from the ffmpeg source tree, run configure specifying where the
extra filter is located:

```
./configure --extra-filter=/tmp/my-shiny-filter
make ffplay
```

Now you can use the filters:

```
./ffplay /path/to/file.webm -vf 'foo,baz'
```

What works:

- Building C based filters with no extra dependencies.
- Multiple filters in the same object file.

What does not work:

- The extra filters will not use the same CC flags used to build the
  built-in filters as I could get it to work yet.
- Due to the above limitation, you cannot include headers of extra
  dependencies, for instance, `json.h` in the example.
- You can pass arbitrary CFLAGS or LDFLAGS in the filter.json file,
  but they should be passed only then building/linking `libavfilter`,
  instead of other libraries.

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.

Signed-off-by: Leandro Santiago <leandrosansilva@gmail.com>
---
 .gitignore               |  3 ++
 configure                | 61 ++++++++++++++++++++++++++++++++++++++++
 libavfilter/Makefile     |  4 +++
 libavfilter/allfilters.c |  1 +
 4 files changed, 69 insertions(+)

diff --git a/.gitignore b/.gitignore
index 9cfc78b414..4963e90191 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,3 +43,6 @@
 /tools/python/__pycache__/
 /libavcodec/vulkan/*.c
 /libavfilter/vulkan/*.c
+/ffbuild/extra-filters.txt
+/ffbuild/extra-filters.mak
+/libavfilter/extra_filters_extern.h
diff --git a/configure b/configure
index 750c99e3b9..6a2adc6c05 100755
--- a/configure
+++ b/configure
@@ -179,6 +179,7 @@ Individual component options:
   --enable-filter=NAME     enable filter NAME
   --disable-filter=NAME    disable filter NAME
   --disable-filters        disable all filters
+  --extra-filter=/foo/bar  add extra filter from directory. This option can be used multiple times
 
 External library support:
 
@@ -1798,6 +1799,7 @@ AVDEVICE_COMPONENTS="
 
 AVFILTER_COMPONENTS="
     filters
+    extra_filters
 "
 
 AVFORMAT_COMPONENTS="
@@ -4382,6 +4384,8 @@ do_random(){
     $action $(rand_list "$@" | awk "BEGIN { srand($random_seed) } \$1 == \"prob\" { prob = \$2; next } rand() < prob { print }")
 }
 
+rm -f ffbuild/extra-filters.txt
+
 # deprecated components (disabled by default)
 disable sonic_encoder sonic_ls_encoder
 
@@ -4457,6 +4461,10 @@ for opt do
                 die_unknown $opt
             fi
         ;;
+        --extra-filter=*)
+            filter_path="${opt#--extra-filter=}"
+            echo "$filter_path" >> ffbuild/extra-filters.txt
+        ;;
         --list-*)
             NAME="${opt#--list-}"
             is_in $NAME $COMPONENT_LIST || die_unknown $opt
@@ -4487,6 +4495,36 @@ for opt do
     esac
 done
 
+find_extra_filters_extern() {
+  # TODO: handle invalid filter
+  while read f; do
+    jq -r '.symbols[]' < "$f/filter.json" | sed 's/^ff_[avfsinkrc]\{2,5\}_\([[:alnum:]_]\{1,\}\)/\1_filter/'
+  done < ffbuild/extra-filters.txt
+}
+
+EXTRA_FILTER_LIST=$(find_extra_filters_extern)
+
+for n in extra_filters; do
+    v=$(toupper ${n%s})_LIST
+    eval enable \$$v
+    eval ${n}_if_any="\$$v"
+done
+
+FILTER_LIST="
+    $FILTER_LIST
+    $EXTRA_FILTER_LIST
+"
+
+AVFILTER_COMPONENTS_LIST="
+    $AVFILTER_COMPONENTS_LIST
+    $EXTRA_FILTER_LIST
+"
+
+ALL_COMPONENTS="
+    $ALL_COMPONENTS
+    $EXTRA_FILTER_LIST
+"
+
 for e in $env; do
     eval "export $e"
 done
@@ -7165,6 +7203,10 @@ enabled rkmpp             && { require_pkg_config rkmpp rockchip_mpp  rockchip/r
                              }
 enabled vapoursynth       && require_headers "vapoursynth/VSScript4.h vapoursynth/VapourSynth4.h"
 
+while read f; do
+  # NOTE: this eval is dangerous, as it allows arbitrary code execution!
+  eval $(jq -r '.check // true' < "$f/filter.json")
+done < ffbuild/extra-filters.txt
 
 if enabled gcrypt; then
     GCRYPT_CONFIG="${cross_prefix}libgcrypt-config"
@@ -8243,6 +8285,12 @@ for entry in $LIBRARY_LIST $PROGRAM_LIST $EXTRALIBS_LIST; do
     eval echo "EXTRALIBS-${entry}=\$${entry}_extralibs" >> ffbuild/config.mak
 done
 
+echo "" > ffbuild/extra-filters.mak
+
+while read f; do
+    echo "include $f/filter.mak" >> ffbuild/extra-filters.mak
+done < ffbuild/extra-filters.txt
+
 cat > $TMPH <<EOF
 /* Automatically generated by configure - do not modify! */
 #ifndef FFMPEG_CONFIG_H
@@ -8330,6 +8378,19 @@ cp_if_changed $TMPH libavutil/avconfig.h
 # ...
 eval "$(sed -n "s/^extern const FFFilter ff_\([avfsinkrc]\{2,5\}\)_\(.*\);/full_filter_name_\2=\1_\2/p" $source_path/libavfilter/allfilters.c)"
 
+rm -f libavfilter/extra_filters_extern.h
+
+# Handle extra filters
+while read f; do
+    eval "$(jq -r '.symbols[]' < "$f/filter.json" | sed 's/^ff_\([avfsinkrc]\{2,5\}\)_\([[:alnum:]]\{1,\}\)$/full_filter_name_\2=\1_\2/')"
+    jq -r '.symbols[]' < "$f/filter.json" | while read symbol; do
+      echo "extern const FFFilter $symbol;" >> libavfilter/extra_filters_extern.h
+      echo "EXTRA_FILTER_$(echo $symbol | sed 's/^ff_[avfsinkrc]\{2,5\}_\([[:alnum:]]\{1,\}\)$/\1/' | tr a-z A-Z)_LOCATION = $f" >> ffbuild/extra-filters.mak
+      echo "LDFLAGS += $(jq -r '.ldflags // ""' < "$f/filter.json")" >> ffbuild/extra-filters.mak
+      echo "CFLAGS += $(jq -r '.cflags // ""' < "$f/filter.json")" >> ffbuild/extra-filters.mak
+    done
+done < ffbuild/extra-filters.txt
+
 # generate the lists of enabled components
 print_enabled_components(){
     file=$1
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 7c0d879ec9..9b22aece3a 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
 
+# extra filters handling
+include $(SRC_PATH)/ffbuild/extra-filters.mak
+EXTRA_FILTER_FLAGS = -I$(PWD) -I$(PWD)/libavfilter $(CPPFLAGS) $(CC_DEPFLAGS)
+
 OBJS-$(HAVE_LIBC_MSVCRT)                     += file_open.o
 OBJS-$(HAVE_THREADS)                         += pthread.o
 
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 740d9ab265..e8565de5b0 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/extra_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".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree filters
  2025-03-13 12:18 [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree filters Leandro Santiago
@ 2025-03-13 12:20 ` Leandro Santiago
  2025-03-14 15:04 ` Michael Niedermayer
  2025-03-14 16:57 ` Lynne
  2 siblings, 0 replies; 9+ messages in thread
From: Leandro Santiago @ 2025-03-13 12:20 UTC (permalink / raw)
  To: ffmpeg-devel

This is a follow-up to the my previous message:

https://ffmpeg.org/pipermail/ffmpeg-devel/2025-March/340895.html

On 3/13/25 13:18, Leandro Santiago wrote:
> This is a POC/prototype that aims to enable out of tree filters on
> FFmpeg.
>
> Here I name them "extra filters".
>
> It introduces the program `jq` as a new build dependency.
>
> To test it, create a directory, for instance, /tmp/my-shiny-filter/ and
> inside it, create the following files:
>
> `filter.json`, with the content:
>
> ```
> {
>   "check": "require_pkg_config json json-c json-c/json.h json_c_version_num",
>   "symbols": ["ff_vf_foo", "ff_vf_bar"]
> }
> ```
>
> `filter.mak`, with the content:
>
> ```
> OBJS += vf_shiny.o
> LIBOBJS += vf_shiny.o
>
> libavfilter/vf_shiny.o:
>         $(CC) $(EXTRA_FILTER_FLAGS) -c -o $@ $(EXTRA_FILTER_FOO_LOCATION)/vf_shiny.c
> ```
>
> `vf_shiny.c` file, with the content:
>
>
> ```
> #include "libavutil/internal.h"                                                                                                                       
> #include "avfilter.h"                                                                                                                                 #include "filters.h"                                                                                                                                  
> #include "video.h" 
>
> const FFFilter ff_vf_bar = {
>     .p.name        = "bar",
>     .p.description = NULL_IF_CONFIG_SMALL("Example filter Baz"),
>     .p.flags       = AVFILTER_FLAG_METADATA_ONLY,
>     FILTER_INPUTS(ff_video_default_filterpad),
>     FILTER_OUTPUTS(ff_video_default_filterpad),
> };
>
> const FFFilter ff_vf_foo = {
>     .p.name        = "foo",
>     .p.description = NULL_IF_CONFIG_SMALL("Another foo filter"),
>     .p.flags       = AVFILTER_FLAG_METADATA_ONLY,
>     FILTER_INPUTS(ff_video_default_filterpad),
>     FILTER_OUTPUTS(ff_video_default_filterpad),
> };
> ```
>
> Then, from the ffmpeg source tree, run configure specifying where the
> extra filter is located:
>
> ```
> ./configure --extra-filter=/tmp/my-shiny-filter
> make ffplay
> ```
>
> Now you can use the filters:
>
> ```
> ./ffplay /path/to/file.webm -vf 'foo,baz'
> ```
>
> What works:
>
> - Building C based filters with no extra dependencies.
> - Multiple filters in the same object file.
>
> What does not work:
>
> - The extra filters will not use the same CC flags used to build the
>   built-in filters as I could get it to work yet.
> - Due to the above limitation, you cannot include headers of extra
>   dependencies, for instance, `json.h` in the example.
> - You can pass arbitrary CFLAGS or LDFLAGS in the filter.json file,
>   but they should be passed only then building/linking `libavfilter`,
>   instead of other libraries.
>
> 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.
>
> Signed-off-by: Leandro Santiago <leandrosansilva@gmail.com>
> ---
>  .gitignore               |  3 ++
>  configure                | 61 ++++++++++++++++++++++++++++++++++++++++
>  libavfilter/Makefile     |  4 +++
>  libavfilter/allfilters.c |  1 +
>  4 files changed, 69 insertions(+)
>
> diff --git a/.gitignore b/.gitignore
> index 9cfc78b414..4963e90191 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -43,3 +43,6 @@
>  /tools/python/__pycache__/
>  /libavcodec/vulkan/*.c
>  /libavfilter/vulkan/*.c
> +/ffbuild/extra-filters.txt
> +/ffbuild/extra-filters.mak
> +/libavfilter/extra_filters_extern.h
> diff --git a/configure b/configure
> index 750c99e3b9..6a2adc6c05 100755
> --- a/configure
> +++ b/configure
> @@ -179,6 +179,7 @@ Individual component options:
>    --enable-filter=NAME     enable filter NAME
>    --disable-filter=NAME    disable filter NAME
>    --disable-filters        disable all filters
> +  --extra-filter=/foo/bar  add extra filter from directory. This option can be used multiple times
>  
>  External library support:
>  
> @@ -1798,6 +1799,7 @@ AVDEVICE_COMPONENTS="
>  
>  AVFILTER_COMPONENTS="
>      filters
> +    extra_filters
>  "
>  
>  AVFORMAT_COMPONENTS="
> @@ -4382,6 +4384,8 @@ do_random(){
>      $action $(rand_list "$@" | awk "BEGIN { srand($random_seed) } \$1 == \"prob\" { prob = \$2; next } rand() < prob { print }")
>  }
>  
> +rm -f ffbuild/extra-filters.txt
> +
>  # deprecated components (disabled by default)
>  disable sonic_encoder sonic_ls_encoder
>  
> @@ -4457,6 +4461,10 @@ for opt do
>                  die_unknown $opt
>              fi
>          ;;
> +        --extra-filter=*)
> +            filter_path="${opt#--extra-filter=}"
> +            echo "$filter_path" >> ffbuild/extra-filters.txt
> +        ;;
>          --list-*)
>              NAME="${opt#--list-}"
>              is_in $NAME $COMPONENT_LIST || die_unknown $opt
> @@ -4487,6 +4495,36 @@ for opt do
>      esac
>  done
>  
> +find_extra_filters_extern() {
> +  # TODO: handle invalid filter
> +  while read f; do
> +    jq -r '.symbols[]' < "$f/filter.json" | sed 's/^ff_[avfsinkrc]\{2,5\}_\([[:alnum:]_]\{1,\}\)/\1_filter/'
> +  done < ffbuild/extra-filters.txt
> +}
> +
> +EXTRA_FILTER_LIST=$(find_extra_filters_extern)
> +
> +for n in extra_filters; do
> +    v=$(toupper ${n%s})_LIST
> +    eval enable \$$v
> +    eval ${n}_if_any="\$$v"
> +done
> +
> +FILTER_LIST="
> +    $FILTER_LIST
> +    $EXTRA_FILTER_LIST
> +"
> +
> +AVFILTER_COMPONENTS_LIST="
> +    $AVFILTER_COMPONENTS_LIST
> +    $EXTRA_FILTER_LIST
> +"
> +
> +ALL_COMPONENTS="
> +    $ALL_COMPONENTS
> +    $EXTRA_FILTER_LIST
> +"
> +
>  for e in $env; do
>      eval "export $e"
>  done
> @@ -7165,6 +7203,10 @@ enabled rkmpp             && { require_pkg_config rkmpp rockchip_mpp  rockchip/r
>                               }
>  enabled vapoursynth       && require_headers "vapoursynth/VSScript4.h vapoursynth/VapourSynth4.h"
>  
> +while read f; do
> +  # NOTE: this eval is dangerous, as it allows arbitrary code execution!
> +  eval $(jq -r '.check // true' < "$f/filter.json")
> +done < ffbuild/extra-filters.txt
>  
>  if enabled gcrypt; then
>      GCRYPT_CONFIG="${cross_prefix}libgcrypt-config"
> @@ -8243,6 +8285,12 @@ for entry in $LIBRARY_LIST $PROGRAM_LIST $EXTRALIBS_LIST; do
>      eval echo "EXTRALIBS-${entry}=\$${entry}_extralibs" >> ffbuild/config.mak
>  done
>  
> +echo "" > ffbuild/extra-filters.mak
> +
> +while read f; do
> +    echo "include $f/filter.mak" >> ffbuild/extra-filters.mak
> +done < ffbuild/extra-filters.txt
> +
>  cat > $TMPH <<EOF
>  /* Automatically generated by configure - do not modify! */
>  #ifndef FFMPEG_CONFIG_H
> @@ -8330,6 +8378,19 @@ cp_if_changed $TMPH libavutil/avconfig.h
>  # ...
>  eval "$(sed -n "s/^extern const FFFilter ff_\([avfsinkrc]\{2,5\}\)_\(.*\);/full_filter_name_\2=\1_\2/p" $source_path/libavfilter/allfilters.c)"
>  
> +rm -f libavfilter/extra_filters_extern.h
> +
> +# Handle extra filters
> +while read f; do
> +    eval "$(jq -r '.symbols[]' < "$f/filter.json" | sed 's/^ff_\([avfsinkrc]\{2,5\}\)_\([[:alnum:]]\{1,\}\)$/full_filter_name_\2=\1_\2/')"
> +    jq -r '.symbols[]' < "$f/filter.json" | while read symbol; do
> +      echo "extern const FFFilter $symbol;" >> libavfilter/extra_filters_extern.h
> +      echo "EXTRA_FILTER_$(echo $symbol | sed 's/^ff_[avfsinkrc]\{2,5\}_\([[:alnum:]]\{1,\}\)$/\1/' | tr a-z A-Z)_LOCATION = $f" >> ffbuild/extra-filters.mak
> +      echo "LDFLAGS += $(jq -r '.ldflags // ""' < "$f/filter.json")" >> ffbuild/extra-filters.mak
> +      echo "CFLAGS += $(jq -r '.cflags // ""' < "$f/filter.json")" >> ffbuild/extra-filters.mak
> +    done
> +done < ffbuild/extra-filters.txt
> +
>  # generate the lists of enabled components
>  print_enabled_components(){
>      file=$1
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 7c0d879ec9..9b22aece3a 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
>  
> +# extra filters handling
> +include $(SRC_PATH)/ffbuild/extra-filters.mak
> +EXTRA_FILTER_FLAGS = -I$(PWD) -I$(PWD)/libavfilter $(CPPFLAGS) $(CC_DEPFLAGS)
> +
>  OBJS-$(HAVE_LIBC_MSVCRT)                     += file_open.o
>  OBJS-$(HAVE_THREADS)                         += pthread.o
>  
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 740d9ab265..e8565de5b0 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/extra_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".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree filters
  2025-03-13 12:18 [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree filters 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 16:57 ` Lynne
  2 siblings, 1 reply; 9+ messages in thread
From: Michael Niedermayer @ 2025-03-14 15:04 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 1199 bytes --]

Hi

On Thu, Mar 13, 2025 at 01:18:49PM +0100, Leandro Santiago wrote:
> This is a POC/prototype that aims to enable out of tree filters on
> FFmpeg.
> 
> Here I name them "extra filters".
> 

> It introduces the program `jq` as a new build dependency.

I dont think this dependency is needed to achieve linking to filters
in another directory
i think its worth the few hours extra time to find a clean/nice way to do it
with no new depeandancies

also there is the quite intriguing option of using "git merge" to include
external filters
What i mean here is that there could be a script lets call it ffmerge

"ffmerge available" would check some online repository and list whats
compatible with the current checkout

"ffmerge merge shiny_filter" would then merge the shiny filter repository/branch

Advanatge would be that this is more powerfull than just linking external
filters.
Disadvantage is that for this to work care needs to be taken that conflicts
do not occur

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree filters
  2025-03-14 15:04 ` Michael Niedermayer
@ 2025-03-14 16:13   ` Leandro Santiago
  2025-03-14 20:58     ` Michael Niedermayer
  0 siblings, 1 reply; 9+ messages in thread
From: Leandro Santiago @ 2025-03-14 16:13 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


On 3/14/25 16:04, Michael Niedermayer wrote:
> Hi
>
> On Thu, Mar 13, 2025 at 01:18:49PM +0100, Leandro Santiago wrote:
>> This is a POC/prototype that aims to enable out of tree filters on
>> FFmpeg.
>>
>> Here I name them "extra filters".
>>
Thinking now, "extra filters" is not a good name. Maybe "external" or "oot"
>> It introduces the program `jq` as a new build dependency.
> I dont think this dependency is needed to achieve linking to filters
> in another directory
To make it clear, the "extra filters" are linked in the same way the 
current filters are: direct as part libavfilter.(so|a). They are not 
dynamically linked.
> i think its worth the few hours extra time to find a clean/nice way to do it
> with no new depeandancies

I used json as a quick way to define the filter metadata (thus the usage 
of JQ to query them), but I confess it could have been any other format. 
I used json to get the proof of concept done :-)

Ideally it would be written in a native format to the build system, if 
something like CMake or Meson was being used.

Maybe the metadata could even be in a Makefile or spread over multiple 
files with no structure. The use of json was for pure convenience. Would 
you have any format to suggest? Is there anything similar in the 
codebase I could have a look at?

This is an example of metadata file at the moment:

{
"ldflags":"-ljson-c",
"cflags":"-DFOO=234",
"check":"require_pkg_config json json-c json-c/json.h json_c_version_num",
"symbols":["ff_vf_foo","ff_vf_bar"]
}

A simpler way to represent it would be put each field in a different 
pure text file, for instance:

symbols.txt:

ff_vf_foo ff_vf_bar

The most important aspect here is that the filter metadata (symbols, 
names, flags) need to be in a format easy to parse from the `configure` 
script.

I did some improvements on my patch and I managed to get the filter to 
pass extra flags on building.

Although the use of forgejo is not yet official, I am keeping my changes 
on it for now, as I still struggle with the email workflow:

https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/13

The "example" filter can be found at:

https://gitlab.com/leandrosansilva/ffmpeg-extra-filter-example/

To use it, simply clone this repo and build ffmpeg with 
`--extra-filter=/path/to/ffmpeg-extra-filter-example`.

>
> also there is the quite intriguing option of using "git merge" to include
> external filters
> What i mean here is that there could be a script lets call it ffmerge
How would it work when using release tarballs, without git?
> "ffmerge available" would check some online repository and list whats
> compatible with the current checkout
>
> "ffmerge merge shiny_filter" would then merge the shiny filter repository/branch
Wouldn't it put more burden over the devs to maintain such 
catalog/repository and the tooling around it? I am fine with that, I 
just wonder how the community would accept it. Having no filter 
catalog/repo feels to be the simplest step one could take at the moment.
>
> Advanatge would be that this is more powerfull than just linking external
> filters.
> Disadvantage is that for this to work care needs to be taken that conflicts
> do not occur

I see that simply keeping the filter outside and linking them at build 
time put almost no burden on the ffmpeg devs.

As, provided there is no promise of a stable API, it's up to the 
developers of the "extra" filters to make their filters build.

>
> thx
>
> [...]
>
>
> _______________________________________________
> 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".
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree filters
  2025-03-13 12:18 [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree filters Leandro Santiago
  2025-03-13 12:20 ` Leandro Santiago
  2025-03-14 15:04 ` Michael Niedermayer
@ 2025-03-14 16:57 ` Lynne
  2025-03-14 18:21   ` Nicolas George
  2025-03-14 22:45   ` Soft Works
  2 siblings, 2 replies; 9+ messages in thread
From: Lynne @ 2025-03-14 16:57 UTC (permalink / raw)
  To: ffmpeg-devel

On 13/03/2025 13:18, Leandro Santiago wrote:
> This is a POC/prototype that aims to enable out of tree filters on
> FFmpeg.
> 
> Here I name them "extra filters".
> 
> It introduces the program `jq` as a new build dependency.
> 
> To test it, create a directory, for instance, /tmp/my-shiny-filter/ and
> inside it, create the following files:
> 
> `filter.json`, with the content:

This is a pointless patch and a pointlessly complex addition to the 
build system. I wouldn't accept something like this.
Those who for some reason have custom filters simply distribute their 
own branch with properly integrated filters. This also lets them 
upstream it if they want to.
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree filters
  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
  1 sibling, 1 reply; 9+ messages in thread
From: Nicolas George @ 2025-03-14 18:21 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Lynne (HE12025-03-14):
> This is a pointless patch and a pointlessly complex addition to the build
> system. I wouldn't accept something like this.
> Those who for some reason have custom filters simply distribute their own
> branch with properly integrated filters.

That works for third-party from one third-party. This feature helps
users who want to use filters from multiple third-party. With what you
describe, they would have to merge the branches, which might not be
trivial.

On the other hand, the JSON in this makes it look like it was designed
by looking at how fashionable languages NIHed their own f5g package
system.

If instead it was designed by asking “what would a ffmpeg developer do”,
it would just have configure run ext/*/configure and then Makefile
include $(CONFIG_EXT_WHATEVER).

Regards,

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree filters
  2025-03-14 18:21   ` Nicolas George
@ 2025-03-14 19:43     ` Leandro Santiago
  0 siblings, 0 replies; 9+ messages in thread
From: Leandro Santiago @ 2025-03-14 19:43 UTC (permalink / raw)
  To: ffmpeg-devel


On 3/14/25 19:21, Nicolas George wrote:
> Lynne (HE12025-03-14):
>> This is a pointless patch and a pointlessly complex addition to the build
>> system. I wouldn't accept something like this.
>> Those who for some reason have custom filters simply distribute their own
>> branch with properly integrated filters.
> That works for third-party from one third-party. This feature helps
> users who want to use filters from multiple third-party. With what you
> describe, they would have to merge the branches, which might not be
> trivial.
>
> On the other hand, the JSON in this makes it look like it was designed
> by looking at how fashionable languages NIHed their own f5g package
> system.

Thx for the review and to make it clear:

it was not my intention to suggest my implementation (using json and so 
on) as the final one or to be mainlined.

I notice now my lack of netiquette, as it seems I was not clear on 
saying that this is a proof of concept (POC, in the subject): I wanted 
to try something (support for non mainlined filters), and wanted to 
check whether that was possible or not, and finally get feedback.

Using json+jq was the quickest, dirtiest way to accomplished that.

I personally conclude that the POC was successful: I managed to get a 
new filter, not mainlined, to be built into ffmpeg. Next steps would be 
throw the code away and implement it properly

Obviously I need the agreement from you experienced ffmpeg devs for such 
conclusion.

I should probably have called it a RFC or similar. My mistake. I still 
struggle with using the mailing list contribution model, as in a PR/MR 
model I would simply keep a WIP request until it gets to a good shape. 
With the ML model, I feel doing so is very error prone, but this is 
probably my lack of experience with it.

My goal now is to know whether there is any interest from the ffmpeg 
devs on having such feature (regardless of the implementation), as there 
seems to be lots of disagreement.

I am personally interested on it, due to the fact I am writing a filter 
in Rust that is very unlikely to ever me mainlined. Right now I need to 
constantly rebase branches, but I'd be way happier if I could simply 
rely on some "official" support in the ffmpeg codebase to use it.

Another benefit could be moving out some filters that are "not very 
loved" or that tend to "get rotten". My impression/opinion is that the 
DNN stuff could very well be moved out, to evolve independently from the 
main ffmpeg repo. I totally respect the developers who worked on it, to 
be very clear. I benefit from the DNN code and want to keep it working well.

>
> If instead it was designed by asking “what would a ffmpeg developer do”,
> it would just have configure run ext/*/configure and then Makefile
> include $(CONFIG_EXT_WHATEVER).

Thank you for the feedback. I requested some thoughts on the topic a few 
days ago [1], and I see that probably the message was not clear.

I find this `simply run ext/configure approach` interesting and will 
have a look at it and later let you know my findings.

[1] https://ffmpeg.org/pipermail/ffmpeg-devel/2025-March/340895.html

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree filters
  2025-03-14 16:13   ` Leandro Santiago
@ 2025-03-14 20:58     ` Michael Niedermayer
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Niedermayer @ 2025-03-14 20:58 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 1408 bytes --]

On Fri, Mar 14, 2025 at 05:13:23PM +0100, Leandro Santiago wrote:
[...]
> > 
> > also there is the quite intriguing option of using "git merge" to include
> > external filters
> > What i mean here is that there could be a script lets call it ffmerge

> How would it work when using release tarballs, without git?

it would tell the user to run it in a git checkout or an empty directory.
The script would already have the ability to merge external filter repos
so also pulling mainline is no real extra complexity


> > "ffmerge available" would check some online repository and list whats
> > compatible with the current checkout
> > 
> > "ffmerge merge shiny_filter" would then merge the shiny filter repository/branch

> Wouldn't it put more burden over the devs to maintain such
> catalog/repository and the tooling around it? I am fine with that, I just
> wonder how the community would accept it. Having no filter catalog/repo
> feels to be the simplest step one could take at the moment.

theres no need for such catalog. I just think that if external filter
support is added, that someone will then likely start maintaining a catalog
of these filters.


thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws. -- Plato

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree filters
  2025-03-14 16:57 ` Lynne
  2025-03-14 18:21   ` Nicolas George
@ 2025-03-14 22:45   ` Soft Works
  1 sibling, 0 replies; 9+ messages in thread
From: Soft Works @ 2025-03-14 22:45 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Lynne
> Sent: Freitag, 14. März 2025 17:58
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree
> filters
> 
> On 13/03/2025 13:18, Leandro Santiago wrote:
> > This is a POC/prototype that aims to enable out of tree filters on
> > FFmpeg.
> >
> > Here I name them "extra filters".
> >
> > It introduces the program `jq` as a new build dependency.
> >
> > To test it, create a directory, for instance, /tmp/my-shiny-filter/
> and
> > inside it, create the following files:
> >
> > `filter.json`, with the content:
> 
> This is a pointless patch and a pointlessly complex addition to the
> build system. I wouldn't accept something like this.
> Those who for some reason have custom filters simply distribute their
> own branch with properly integrated filters. This also lets them
> upstream it if they want to.
> _______________________________________________

Hi Lynne,

as someone who is using a number of custom filters, I can say that the "own branch with properly integrated filters" approach is a continuing source of trouble when rebasing or trying to apply it to different base branches. Even though these aren't really 3rd party filters, having a mechanism for it would make it much easier to maintain additional filters.
I don't want to argue about the specific approach as other will know better than me, but I'm sure that it's possible to find a nice non-complex way, no?

sw




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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-03-14 22:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-13 12:18 [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree filters 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

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