See thread:
Subject: [FFmpeg-devel] [POC] frei0r wrapper
Date: Tue, 24 Aug 2010 21:37:32 +0200
Originally committed as revision 25165 to svn://svn.ffmpeg.org/ffmpeg/trunk
... | ... |
@@ -162,6 +162,7 @@ Configuration options: |
162 | 162 |
External library support: |
163 | 163 |
--enable-avisynth enable reading of AVISynth script files [no] |
164 | 164 |
--enable-bzlib enable bzlib [autodetect] |
165 |
+ --enable-frei0r enable frei0r video filtering |
|
165 | 166 |
--enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no] |
166 | 167 |
--enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no] |
167 | 168 |
--enable-libopencv enable video filtering via libopencv [no] |
... | ... |
@@ -873,6 +874,7 @@ CONFIG_LIST=" |
873 | 873 |
ffprobe |
874 | 874 |
ffserver |
875 | 875 |
fft |
876 |
+ frei0r |
|
876 | 877 |
golomb |
877 | 878 |
gpl |
878 | 879 |
gray |
... | ... |
@@ -1050,6 +1052,7 @@ HAVE_LIST=" |
1050 | 1050 |
poll_h |
1051 | 1051 |
setrlimit |
1052 | 1052 |
strerror_r |
1053 |
+ strtok_r |
|
1053 | 1054 |
struct_addrinfo |
1054 | 1055 |
struct_ipv6_mreq |
1055 | 1056 |
struct_sockaddr_in6 |
... | ... |
@@ -1383,6 +1386,9 @@ vfwcap_indev_extralibs="-lavicap32" |
1383 | 1383 |
x11_grab_device_indev_deps="x11grab XShmCreateImage" |
1384 | 1384 |
x11_grab_device_indev_extralibs="-lX11 -lXext -lXfixes" |
1385 | 1385 |
|
1386 |
+# filters |
|
1387 |
+frei0r_filter_deps="frei0r dlopen strtok_r" |
|
1388 |
+ |
|
1386 | 1389 |
# protocols |
1387 | 1390 |
gopher_protocol_deps="network" |
1388 | 1391 |
http_protocol_deps="network" |
... | ... |
@@ -2647,6 +2653,7 @@ check_func mkstemp |
2647 | 2647 |
check_func ${malloc_prefix}posix_memalign && enable posix_memalign |
2648 | 2648 |
check_func setrlimit |
2649 | 2649 |
check_func strerror_r |
2650 |
+check_func strtok_r |
|
2650 | 2651 |
check_func_headers io.h setmode |
2651 | 2652 |
check_func_headers lzo/lzo1x.h lzo1x_999_compress |
2652 | 2653 |
check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi |
... | ... |
@@ -2720,6 +2727,7 @@ check_mathfunc truncf |
2720 | 2720 |
|
2721 | 2721 |
# these are off by default, so fail if requested and not available |
2722 | 2722 |
enabled avisynth && require2 vfw32 "windows.h vfw.h" AVIFileInit -lavifil32 |
2723 |
+enabled frei0r && { check_header frei0r.h || die "ERROR: frei0r.h header not found"; } |
|
2723 | 2724 |
enabled libdirac && add_cflags $(pkg-config --cflags dirac) && |
2724 | 2725 |
require libdirac libdirac_decoder/dirac_parser.h dirac_decoder_init $(pkg-config --libs dirac) && |
2725 | 2726 |
require libdirac libdirac_encoder/dirac_encoder.h dirac_encoder_init $(pkg-config --libs dirac) |
... | ... |
@@ -3012,6 +3020,7 @@ echo "threading support ${thread_type-no}" |
3012 | 3012 |
echo "SDL support ${sdl-no}" |
3013 | 3013 |
echo "Sun medialib support ${mlib-no}" |
3014 | 3014 |
echo "AVISynth enabled ${avisynth-no}" |
3015 |
+echo "frei0r enabled ${frei0r-no}" |
|
3015 | 3016 |
echo "libdc1394 support ${libdc1394-no}" |
3016 | 3017 |
echo "libdirac enabled ${libdirac-no}" |
3017 | 3018 |
echo "libfaac enabled ${libfaac-no}" |
... | ... |
@@ -81,6 +81,56 @@ The following command: |
81 | 81 |
|
82 | 82 |
will convert the input video to the format "yuv420p". |
83 | 83 |
|
84 |
+@section frei0r |
|
85 |
+ |
|
86 |
+Apply a frei0r effect to the input video. |
|
87 |
+ |
|
88 |
+To enable compilation of this filter you need to install the frei0r |
|
89 |
+header and configure FFmpeg with --enable-frei0r. |
|
90 |
+ |
|
91 |
+The filter supports the syntax: |
|
92 |
+@example |
|
93 |
+@var{filter_name}:@var{param1}:@var{param2}:...:@var{paramN} |
|
94 |
+@end example |
|
95 |
+ |
|
96 |
+@var{filter_name} is the name to the frei0r effect to load. If the |
|
97 |
+environment variable @env{FREI0R_PATH} is defined, the frei0r effect |
|
98 |
+is searched in each one of the directories specified by the colon |
|
99 |
+separated list in @env{FREIOR_PATH}, otherwise in the standard frei0r |
|
100 |
+paths, which are in this order: @file{HOME/.frei0r-1/lib/}, |
|
101 |
+@file{/usr/local/lib/frei0r-1/}, @file{/usr/lib/frei0r-1/}. |
|
102 |
+ |
|
103 |
+@var{param1}, @var{param2}, ... , @var{paramN} specify the parameters |
|
104 |
+for the frei0r effect. |
|
105 |
+ |
|
106 |
+A frei0r effect parameter can be a boolean (whose values are specified |
|
107 |
+with "y" and "n"), a double, a color (specified by the syntax |
|
108 |
+@var{R}/@var{G}/@var{B}, @var{R}, @var{G}, and @var{B} being float |
|
109 |
+numbers from 0.0 to 1.0) or by an @code{av_parse_color()} color |
|
110 |
+description), a position (specified by the syntax @var{X}/@var{Y}, |
|
111 |
+@var{X} and @var{Y} being float numbers) and a string. |
|
112 |
+ |
|
113 |
+The number and kind of parameters depend on the loaded effect. If an |
|
114 |
+effect parameter is not specified the default value is set. |
|
115 |
+ |
|
116 |
+Some examples follow: |
|
117 |
+@example |
|
118 |
+# apply the distort0r effect, set the first two double parameters |
|
119 |
+frei0r=distort0r:0.5:0.01 |
|
120 |
+ |
|
121 |
+# apply the colordistance effect, takes a color as first parameter |
|
122 |
+frei0r=colordistance:0.2/0.3/0.4 |
|
123 |
+frei0r=colordistance:violet |
|
124 |
+frei0r=colordistance:0x112233 |
|
125 |
+ |
|
126 |
+# apply the perspective effect, specify the top left and top right |
|
127 |
+# image positions |
|
128 |
+frei0r=perspective:0.2/0.2:0.8/0.2 |
|
129 |
+@end example |
|
130 |
+ |
|
131 |
+For more information see: |
|
132 |
+@url{http://piksel.org/frei0r} |
|
133 |
+ |
|
84 | 134 |
@section hflip |
85 | 135 |
|
86 | 136 |
Flip the input video horizontally. |
... | ... |
@@ -20,6 +20,7 @@ OBJS-$(CONFIG_ASPECT_FILTER) += vf_aspect.o |
20 | 20 |
OBJS-$(CONFIG_CROP_FILTER) += vf_crop.o |
21 | 21 |
OBJS-$(CONFIG_FIFO_FILTER) += vf_fifo.o |
22 | 22 |
OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o |
23 |
+OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o |
|
23 | 24 |
OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o |
24 | 25 |
OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o |
25 | 26 |
OBJS-$(CONFIG_NULL_FILTER) += vf_null.o |
... | ... |
@@ -40,6 +40,7 @@ void avfilter_register_all(void) |
40 | 40 |
REGISTER_FILTER (CROP, crop, vf); |
41 | 41 |
REGISTER_FILTER (FIFO, fifo, vf); |
42 | 42 |
REGISTER_FILTER (FORMAT, format, vf); |
43 |
+ REGISTER_FILTER (FREI0R, frei0r, vf); |
|
43 | 44 |
REGISTER_FILTER (HFLIP, hflip, vf); |
44 | 45 |
REGISTER_FILTER (NOFORMAT, noformat, vf); |
45 | 46 |
REGISTER_FILTER (NULL, null, vf); |
... | ... |
@@ -25,7 +25,7 @@ |
25 | 25 |
#include "libavutil/avutil.h" |
26 | 26 |
|
27 | 27 |
#define LIBAVFILTER_VERSION_MAJOR 1 |
28 |
-#define LIBAVFILTER_VERSION_MINOR 39 |
|
28 |
+#define LIBAVFILTER_VERSION_MINOR 40 |
|
29 | 29 |
#define LIBAVFILTER_VERSION_MICRO 0 |
30 | 30 |
|
31 | 31 |
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ |
32 | 32 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,363 @@ |
0 |
+/* |
|
1 |
+ * copyright (c) 2010 Stefano Sabatini |
|
2 |
+ * This file is part of FFmpeg. |
|
3 |
+ * |
|
4 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
5 |
+ * modify it under the terms of the GNU Lesser General Public |
|
6 |
+ * License as published by the Free Software Foundation; either |
|
7 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
8 |
+ * |
|
9 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
10 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 |
+ * Lesser General Public License for more details. |
|
13 |
+ * |
|
14 |
+ * You should have received a copy of the GNU Lesser General Public |
|
15 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
16 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
17 |
+ */ |
|
18 |
+ |
|
19 |
+/** |
|
20 |
+ * @file |
|
21 |
+ * frei0r wrapper |
|
22 |
+ */ |
|
23 |
+ |
|
24 |
+/* #define DEBUG */ |
|
25 |
+ |
|
26 |
+#include <dlfcn.h> |
|
27 |
+#include <frei0r.h> |
|
28 |
+#include "avfilter.h" |
|
29 |
+#include "parseutils.h" |
|
30 |
+ |
|
31 |
+typedef f0r_instance_t (*f0r_construct_f)(unsigned int width, unsigned int height); |
|
32 |
+typedef void (*f0r_destruct_f)(f0r_instance_t instance); |
|
33 |
+typedef void (*f0r_deinit_f)(void); |
|
34 |
+typedef int (*f0r_init_f)(void); |
|
35 |
+typedef void (*f0r_get_plugin_info_f)(f0r_plugin_info_t *info); |
|
36 |
+typedef void (*f0r_get_param_info_f)(f0r_param_info_t *info, int param_index); |
|
37 |
+typedef void (*f0r_update_f)(f0r_instance_t instance, double time, const uint32_t *inframe, uint32_t *outframe); |
|
38 |
+typedef void (*f0r_update2_f)(f0r_instance_t instance, double time, const uint32_t *inframe1, const uint32_t *inframe2, const uint32_t *inframe3, uint32_t *outframe); |
|
39 |
+typedef void (*f0r_set_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index); |
|
40 |
+typedef void (*f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index); |
|
41 |
+ |
|
42 |
+typedef struct Frei0rContext { |
|
43 |
+ f0r_update_f update; |
|
44 |
+ void *dl_handle; /* dynamic library handle */ |
|
45 |
+ f0r_instance_t instance; |
|
46 |
+ f0r_plugin_info_t plugin_info; |
|
47 |
+ |
|
48 |
+ f0r_get_param_info_f get_param_info; |
|
49 |
+ f0r_get_param_value_f get_param_value; |
|
50 |
+ f0r_set_param_value_f set_param_value; |
|
51 |
+ f0r_construct_f construct; |
|
52 |
+ f0r_destruct_f destruct; |
|
53 |
+ f0r_deinit_f deinit; |
|
54 |
+ char params[256]; |
|
55 |
+} Frei0rContext; |
|
56 |
+ |
|
57 |
+static void *load_sym(AVFilterContext *ctx, const char *sym_name) |
|
58 |
+{ |
|
59 |
+ Frei0rContext *frei0r = ctx->priv; |
|
60 |
+ void *sym = dlsym(frei0r->dl_handle, sym_name); |
|
61 |
+ if (!sym) |
|
62 |
+ av_log(ctx, AV_LOG_ERROR, "Could not find symbol '%s' in loaded module\n", sym_name); |
|
63 |
+ return sym; |
|
64 |
+} |
|
65 |
+ |
|
66 |
+static int set_param(AVFilterContext *ctx, f0r_param_info_t info, int index, char *param) |
|
67 |
+{ |
|
68 |
+ Frei0rContext *frei0r = ctx->priv; |
|
69 |
+ union { |
|
70 |
+ double d; |
|
71 |
+ f0r_param_color_t col; |
|
72 |
+ f0r_param_position_t pos; |
|
73 |
+ } val; |
|
74 |
+ char *tail; |
|
75 |
+ uint8_t rgba[4]; |
|
76 |
+ |
|
77 |
+ switch (info.type) { |
|
78 |
+ case F0R_PARAM_BOOL: |
|
79 |
+ if (!strcmp(param, "y")) val.d = 1.0; |
|
80 |
+ else if (!strcmp(param, "n")) val.d = 0.0; |
|
81 |
+ else goto fail; |
|
82 |
+ break; |
|
83 |
+ |
|
84 |
+ case F0R_PARAM_DOUBLE: |
|
85 |
+ val.d = strtod(param, &tail); |
|
86 |
+ if (*tail || val.d == HUGE_VAL) |
|
87 |
+ goto fail; |
|
88 |
+ break; |
|
89 |
+ |
|
90 |
+ case F0R_PARAM_COLOR: |
|
91 |
+ if (sscanf(param, "%f/%f/%f", &val.col.r, &val.col.g, &val.col.b) != 3) { |
|
92 |
+ if (av_parse_color(rgba, param, ctx) < 0) |
|
93 |
+ goto fail; |
|
94 |
+ val.col.r = rgba[0] / 255.0; |
|
95 |
+ val.col.g = rgba[1] / 255.0; |
|
96 |
+ val.col.b = rgba[2] / 255.0; |
|
97 |
+ } |
|
98 |
+ break; |
|
99 |
+ |
|
100 |
+ case F0R_PARAM_POSITION: |
|
101 |
+ if (sscanf(param, "%lf/%lf", &val.pos.x, &val.pos.y) != 2) |
|
102 |
+ goto fail; |
|
103 |
+ break; |
|
104 |
+ } |
|
105 |
+ |
|
106 |
+ frei0r->set_param_value(frei0r->instance, &val, index); |
|
107 |
+ return 0; |
|
108 |
+ |
|
109 |
+fail: |
|
110 |
+ av_log(ctx, AV_LOG_ERROR, "Invalid value '%s' for parameter '%s'\n", |
|
111 |
+ param, info.name); |
|
112 |
+ return AVERROR(EINVAL); |
|
113 |
+} |
|
114 |
+ |
|
115 |
+static int set_params(AVFilterContext *ctx, const char *params) |
|
116 |
+{ |
|
117 |
+ Frei0rContext *frei0r = ctx->priv; |
|
118 |
+ int i; |
|
119 |
+ |
|
120 |
+ for (i = 0; i < frei0r->plugin_info.num_params; i++) { |
|
121 |
+ f0r_param_info_t info; |
|
122 |
+ char *param; |
|
123 |
+ int ret; |
|
124 |
+ |
|
125 |
+ frei0r->get_param_info(&info, i); |
|
126 |
+ |
|
127 |
+ if (*params) { |
|
128 |
+ if (!(param = av_get_token(¶ms, ":"))) |
|
129 |
+ return AVERROR(ENOMEM); |
|
130 |
+ params++; /* skip ':' */ |
|
131 |
+ ret = set_param(ctx, info, i, param); |
|
132 |
+ av_free(param); |
|
133 |
+ if (ret < 0) |
|
134 |
+ return ret; |
|
135 |
+ } |
|
136 |
+ |
|
137 |
+ av_log(ctx, AV_LOG_INFO, |
|
138 |
+ "idx:%d name:'%s' type:%s explanation:'%s' ", |
|
139 |
+ i, info.name, |
|
140 |
+ info.type == F0R_PARAM_BOOL ? "bool" : |
|
141 |
+ info.type == F0R_PARAM_DOUBLE ? "double" : |
|
142 |
+ info.type == F0R_PARAM_COLOR ? "color" : |
|
143 |
+ info.type == F0R_PARAM_POSITION ? "position" : |
|
144 |
+ info.type == F0R_PARAM_STRING ? "string" : "unknown", |
|
145 |
+ info.explanation); |
|
146 |
+ |
|
147 |
+#ifdef DEBUG |
|
148 |
+ av_log(ctx, AV_LOG_INFO, "value:"); |
|
149 |
+ switch (info.type) { |
|
150 |
+ void *v; |
|
151 |
+ double d; |
|
152 |
+ char s[128]; |
|
153 |
+ f0r_param_color_t col; |
|
154 |
+ f0r_param_position_t pos; |
|
155 |
+ |
|
156 |
+ case F0R_PARAM_BOOL: |
|
157 |
+ v = &d; |
|
158 |
+ frei0r->get_param_value(frei0r->instance, v, i); |
|
159 |
+ av_log(ctx, AV_LOG_INFO, "%s", d >= 0.5 && d <= 1.0 ? "y" : "n"); |
|
160 |
+ break; |
|
161 |
+ case F0R_PARAM_DOUBLE: |
|
162 |
+ v = &d; |
|
163 |
+ frei0r->get_param_value(frei0r->instance, v, i); |
|
164 |
+ av_log(ctx, AV_LOG_INFO, "%f", d); |
|
165 |
+ break; |
|
166 |
+ case F0R_PARAM_COLOR: |
|
167 |
+ v = &col; |
|
168 |
+ frei0r->get_param_value(frei0r->instance, v, i); |
|
169 |
+ av_log(ctx, AV_LOG_INFO, "%f/%f/%f", col.r, col.g, col.b); |
|
170 |
+ break; |
|
171 |
+ case F0R_PARAM_POSITION: |
|
172 |
+ v = &pos; |
|
173 |
+ frei0r->get_param_value(frei0r->instance, v, i); |
|
174 |
+ av_log(ctx, AV_LOG_INFO, "%lf/%lf", pos.x, pos.y); |
|
175 |
+ break; |
|
176 |
+ default: /* F0R_PARAM_STRING */ |
|
177 |
+ v = s; |
|
178 |
+ frei0r->get_param_value(frei0r->instance, v, i); |
|
179 |
+ av_log(ctx, AV_LOG_INFO, "'%s'\n", s); |
|
180 |
+ break; |
|
181 |
+ } |
|
182 |
+#endif |
|
183 |
+ av_log(ctx, AV_LOG_INFO, "\n"); |
|
184 |
+ } |
|
185 |
+ |
|
186 |
+ return 0; |
|
187 |
+} |
|
188 |
+ |
|
189 |
+static void *load_path(AVFilterContext *ctx, const char *prefix, const char *name) |
|
190 |
+{ |
|
191 |
+ char path[1024]; |
|
192 |
+ |
|
193 |
+ snprintf(path, sizeof(path), "%s%s.so", prefix, name); |
|
194 |
+ av_log(ctx, AV_LOG_DEBUG, "Looking for frei0r effect in '%s'\n", path); |
|
195 |
+ return dlopen(path, RTLD_NOW|RTLD_LOCAL); |
|
196 |
+} |
|
197 |
+ |
|
198 |
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) |
|
199 |
+{ |
|
200 |
+ Frei0rContext *frei0r = ctx->priv; |
|
201 |
+ f0r_init_f f0r_init; |
|
202 |
+ f0r_get_plugin_info_f f0r_get_plugin_info; |
|
203 |
+ f0r_plugin_info_t *pi; |
|
204 |
+ char dl_name[1024], *path; |
|
205 |
+ |
|
206 |
+ *frei0r->params = 0; |
|
207 |
+ |
|
208 |
+ if (args) |
|
209 |
+ sscanf(args, "%1023[^:]:%255c", dl_name, frei0r->params); |
|
210 |
+ |
|
211 |
+ /* see: http://piksel.org/frei0r/1.2/spec/1.2/spec/group__pluglocations.html */ |
|
212 |
+ if ((path = av_strdup(getenv("FREI0R_PATH")))) { |
|
213 |
+ char *p, *ptr = NULL; |
|
214 |
+ for (p = path; p = strtok_r(p, ":", &ptr); p = NULL) |
|
215 |
+ if (frei0r->dl_handle = load_path(ctx, p, dl_name)) |
|
216 |
+ break; |
|
217 |
+ av_free(path); |
|
218 |
+ } |
|
219 |
+ if (!frei0r->dl_handle && (path = av_strdup(getenv("HOME")))) { |
|
220 |
+ char prefix[1024]; |
|
221 |
+ snprintf(prefix, sizeof(prefix), "%s/.frei0r-1/lib/", path); |
|
222 |
+ frei0r->dl_handle = load_path(ctx, prefix, dl_name); |
|
223 |
+ av_free(path); |
|
224 |
+ } |
|
225 |
+ if (!frei0r->dl_handle) |
|
226 |
+ frei0r->dl_handle = load_path(ctx, "/usr/local/lib/frei0r-1/", dl_name); |
|
227 |
+ if (!frei0r->dl_handle) |
|
228 |
+ frei0r->dl_handle = load_path(ctx, "/usr/lib/frei0r-1/", dl_name); |
|
229 |
+ if (!frei0r->dl_handle) { |
|
230 |
+ av_log(ctx, AV_LOG_ERROR, "Could not find module '%s'\n", dl_name); |
|
231 |
+ return AVERROR(EINVAL); |
|
232 |
+ } |
|
233 |
+ |
|
234 |
+ if (!(f0r_init = load_sym(ctx, "f0r_init" )) || |
|
235 |
+ !(f0r_get_plugin_info = load_sym(ctx, "f0r_get_plugin_info")) || |
|
236 |
+ !(frei0r->get_param_info = load_sym(ctx, "f0r_get_param_info" )) || |
|
237 |
+ !(frei0r->get_param_value = load_sym(ctx, "f0r_get_param_value")) || |
|
238 |
+ !(frei0r->set_param_value = load_sym(ctx, "f0r_set_param_value")) || |
|
239 |
+ !(frei0r->update = load_sym(ctx, "f0r_update" )) || |
|
240 |
+ !(frei0r->construct = load_sym(ctx, "f0r_construct" )) || |
|
241 |
+ !(frei0r->destruct = load_sym(ctx, "f0r_destruct" )) || |
|
242 |
+ !(frei0r->deinit = load_sym(ctx, "f0r_deinit" ))) |
|
243 |
+ return AVERROR(EINVAL); |
|
244 |
+ |
|
245 |
+ if (f0r_init() < 0) { |
|
246 |
+ av_log(ctx, AV_LOG_ERROR, "Could not init the frei0r module"); |
|
247 |
+ return AVERROR(EINVAL); |
|
248 |
+ } |
|
249 |
+ |
|
250 |
+ f0r_get_plugin_info(&frei0r->plugin_info); |
|
251 |
+ pi = &frei0r->plugin_info; |
|
252 |
+ if (pi->plugin_type != F0R_PLUGIN_TYPE_FILTER) { |
|
253 |
+ av_log(ctx, AV_LOG_ERROR, |
|
254 |
+ "Invalid type '%s' for the plugin, a filter plugin was expected\n", |
|
255 |
+ pi->plugin_type == F0R_PLUGIN_TYPE_SOURCE ? "source" : |
|
256 |
+ pi->plugin_type == F0R_PLUGIN_TYPE_MIXER2 ? "mixer2" : |
|
257 |
+ pi->plugin_type == F0R_PLUGIN_TYPE_MIXER3 ? "mixer3" : "unknown"); |
|
258 |
+ return AVERROR(EINVAL); |
|
259 |
+ } |
|
260 |
+ |
|
261 |
+ av_log(ctx, AV_LOG_INFO, |
|
262 |
+ "name:%s author:'%s' explanation:'%s' color_model:%s " |
|
263 |
+ "frei0r_version:%d version:%d.%d num_params:%d\n", |
|
264 |
+ pi->name, pi->author, pi->explanation, |
|
265 |
+ pi->color_model == F0R_COLOR_MODEL_BGRA8888 ? "bgra8888" : |
|
266 |
+ pi->color_model == F0R_COLOR_MODEL_RGBA8888 ? "rgba8888" : |
|
267 |
+ pi->color_model == F0R_COLOR_MODEL_PACKED32 ? "packed32" : "unknown", |
|
268 |
+ pi->frei0r_version, pi->major_version, pi->minor_version, pi->num_params); |
|
269 |
+ |
|
270 |
+ return 0; |
|
271 |
+} |
|
272 |
+ |
|
273 |
+static av_cold void uninit(AVFilterContext *ctx) |
|
274 |
+{ |
|
275 |
+ Frei0rContext *frei0r = ctx->priv; |
|
276 |
+ |
|
277 |
+ if (frei0r->destruct) |
|
278 |
+ frei0r->destruct(frei0r->instance); |
|
279 |
+ if (frei0r->deinit) |
|
280 |
+ frei0r->deinit(); |
|
281 |
+ if (frei0r->dl_handle) |
|
282 |
+ dlclose(frei0r->dl_handle); |
|
283 |
+ |
|
284 |
+ memset(frei0r, 0, sizeof(*frei0r)); |
|
285 |
+} |
|
286 |
+ |
|
287 |
+static int config_input_props(AVFilterLink *inlink) |
|
288 |
+{ |
|
289 |
+ AVFilterContext *ctx = inlink->dst; |
|
290 |
+ Frei0rContext *frei0r = ctx->priv; |
|
291 |
+ |
|
292 |
+ if (!(frei0r->instance = frei0r->construct(inlink->w, inlink->h))) { |
|
293 |
+ av_log(ctx, AV_LOG_ERROR, "Impossible to load frei0r instance"); |
|
294 |
+ return AVERROR(EINVAL); |
|
295 |
+ } |
|
296 |
+ |
|
297 |
+ return set_params(ctx, frei0r->params); |
|
298 |
+} |
|
299 |
+ |
|
300 |
+static int query_formats(AVFilterContext *ctx) |
|
301 |
+{ |
|
302 |
+ Frei0rContext *frei0r = ctx->priv; |
|
303 |
+ AVFilterFormats *formats = NULL; |
|
304 |
+ |
|
305 |
+ if (frei0r->plugin_info.color_model == F0R_COLOR_MODEL_BGRA8888) { |
|
306 |
+ avfilter_add_format(&formats, PIX_FMT_BGRA); |
|
307 |
+ } else if (frei0r->plugin_info.color_model == F0R_COLOR_MODEL_RGBA8888) { |
|
308 |
+ avfilter_add_format(&formats, PIX_FMT_RGBA); |
|
309 |
+ } else { /* F0R_COLOR_MODEL_PACKED32 */ |
|
310 |
+ static const enum PixelFormat pix_fmts[] = { |
|
311 |
+ PIX_FMT_BGRA, PIX_FMT_ARGB, PIX_FMT_ABGR, PIX_FMT_ARGB, PIX_FMT_NONE |
|
312 |
+ }; |
|
313 |
+ formats = avfilter_make_format_list(pix_fmts); |
|
314 |
+ } |
|
315 |
+ |
|
316 |
+ if (!formats) |
|
317 |
+ return AVERROR(ENOMEM); |
|
318 |
+ |
|
319 |
+ avfilter_set_common_formats(ctx, formats); |
|
320 |
+ return 0; |
|
321 |
+} |
|
322 |
+ |
|
323 |
+static void null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { } |
|
324 |
+ |
|
325 |
+static void end_frame(AVFilterLink *inlink) |
|
326 |
+{ |
|
327 |
+ Frei0rContext *frei0r = inlink->dst->priv; |
|
328 |
+ AVFilterLink *outlink = inlink->dst->outputs[0]; |
|
329 |
+ AVFilterBufferRef *inpicref = inlink->cur_buf; |
|
330 |
+ AVFilterBufferRef *outpicref = outlink->out_buf; |
|
331 |
+ |
|
332 |
+ frei0r->update(frei0r->instance, (double)inpicref->pts / AV_TIME_BASE, |
|
333 |
+ (const uint32_t *)inpicref->data[0], |
|
334 |
+ (uint32_t *)outpicref->data[0]); |
|
335 |
+ avfilter_unref_buffer(inpicref); |
|
336 |
+ avfilter_draw_slice(outlink, 0, outlink->h, 1); |
|
337 |
+ avfilter_end_frame(outlink); |
|
338 |
+ avfilter_unref_buffer(outpicref); |
|
339 |
+} |
|
340 |
+ |
|
341 |
+AVFilter avfilter_vf_frei0r = { |
|
342 |
+ .name = "frei0r", |
|
343 |
+ .description = NULL_IF_CONFIG_SMALL("Apply a frei0r effect."), |
|
344 |
+ |
|
345 |
+ .query_formats = query_formats, |
|
346 |
+ .init = init, |
|
347 |
+ .uninit = uninit, |
|
348 |
+ |
|
349 |
+ .priv_size = sizeof(Frei0rContext), |
|
350 |
+ |
|
351 |
+ .inputs = (AVFilterPad[]) {{ .name = "default", |
|
352 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
353 |
+ .draw_slice = null_draw_slice, |
|
354 |
+ .config_props = config_input_props, |
|
355 |
+ .end_frame = end_frame, |
|
356 |
+ .min_perms = AV_PERM_READ }, |
|
357 |
+ { .name = NULL}}, |
|
358 |
+ |
|
359 |
+ .outputs = (AVFilterPad[]) {{ .name = "default", |
|
360 |
+ .type = AVMEDIA_TYPE_VIDEO, }, |
|
361 |
+ { .name = NULL}}, |
|
362 |
+}; |