vf_frei0r.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Stefano Sabatini
3  * This file is part of FFmpeg.
4  *
5  * FFmpeg is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * FFmpeg is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with FFmpeg; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /**
21  * @file
22  * frei0r wrapper
23  */
24 
25 /* #define DEBUG */
26 
27 #include <dlfcn.h>
28 #include <frei0r.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include "config.h"
33 #include "libavutil/avstring.h"
34 #include "libavutil/imgutils.h"
35 #include "libavutil/internal.h"
36 #include "libavutil/mathematics.h"
37 #include "libavutil/mem.h"
38 #include "libavutil/opt.h"
39 #include "libavutil/parseutils.h"
40 #include "avfilter.h"
41 #include "formats.h"
42 #include "internal.h"
43 #include "video.h"
44 
45 typedef f0r_instance_t (*f0r_construct_f)(unsigned int width, unsigned int height);
46 typedef void (*f0r_destruct_f)(f0r_instance_t instance);
47 typedef void (*f0r_deinit_f)(void);
48 typedef int (*f0r_init_f)(void);
49 typedef void (*f0r_get_plugin_info_f)(f0r_plugin_info_t *info);
50 typedef void (*f0r_get_param_info_f)(f0r_param_info_t *info, int param_index);
51 typedef void (*f0r_update_f)(f0r_instance_t instance, double time, const uint32_t *inframe, uint32_t *outframe);
52 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);
53 typedef void (*f0r_set_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index);
54 typedef void (*f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index);
55 
56 typedef struct Frei0rContext {
57  const AVClass *class;
59  void *dl_handle; /* dynamic library handle */
60  f0r_instance_t instance;
61  f0r_plugin_info_t plugin_info;
62 
69 
70  char *dl_name;
71  char *params;
72  char *size;
73  char *framerate;
74 
75  /* only used by the source */
76  int w, h;
78  uint64_t pts;
80 
81 static void *load_sym(AVFilterContext *ctx, const char *sym_name)
82 {
83  Frei0rContext *frei0r = ctx->priv;
84  void *sym = dlsym(frei0r->dl_handle, sym_name);
85  if (!sym)
86  av_log(ctx, AV_LOG_ERROR, "Could not find symbol '%s' in loaded module\n", sym_name);
87  return sym;
88 }
89 
90 static int set_param(AVFilterContext *ctx, f0r_param_info_t info, int index, char *param)
91 {
92  Frei0rContext *frei0r = ctx->priv;
93  union {
94  double d;
95  f0r_param_color_t col;
96  f0r_param_position_t pos;
97  } val;
98  char *tail;
99  uint8_t rgba[4];
100 
101  switch (info.type) {
102  case F0R_PARAM_BOOL:
103  if (!strcmp(param, "y")) val.d = 1.0;
104  else if (!strcmp(param, "n")) val.d = 0.0;
105  else goto fail;
106  break;
107 
108  case F0R_PARAM_DOUBLE:
109  val.d = strtod(param, &tail);
110  if (*tail || val.d == HUGE_VAL)
111  goto fail;
112  break;
113 
114  case F0R_PARAM_COLOR:
115  if (sscanf(param, "%f/%f/%f", &val.col.r, &val.col.g, &val.col.b) != 3) {
116  if (av_parse_color(rgba, param, -1, ctx) < 0)
117  goto fail;
118  val.col.r = rgba[0] / 255.0;
119  val.col.g = rgba[1] / 255.0;
120  val.col.b = rgba[2] / 255.0;
121  }
122  break;
123 
124  case F0R_PARAM_POSITION:
125  if (sscanf(param, "%lf/%lf", &val.pos.x, &val.pos.y) != 2)
126  goto fail;
127  break;
128  }
129 
130  frei0r->set_param_value(frei0r->instance, &val, index);
131  return 0;
132 
133 fail:
134  av_log(ctx, AV_LOG_ERROR, "Invalid value '%s' for parameter '%s'\n",
135  param, info.name);
136  return AVERROR(EINVAL);
137 }
138 
139 static int set_params(AVFilterContext *ctx, const char *params)
140 {
141  Frei0rContext *frei0r = ctx->priv;
142  int i;
143 
144  for (i = 0; i < frei0r->plugin_info.num_params; i++) {
145  f0r_param_info_t info;
146  char *param;
147  int ret;
148 
149  frei0r->get_param_info(&info, i);
150 
151  if (*params) {
152  if (!(param = av_get_token(&params, "|")))
153  return AVERROR(ENOMEM);
154  params++; /* skip ':' */
155  ret = set_param(ctx, info, i, param);
156  av_free(param);
157  if (ret < 0)
158  return ret;
159  }
160 
161  av_log(ctx, AV_LOG_VERBOSE,
162  "idx:%d name:'%s' type:%s explanation:'%s' ",
163  i, info.name,
164  info.type == F0R_PARAM_BOOL ? "bool" :
165  info.type == F0R_PARAM_DOUBLE ? "double" :
166  info.type == F0R_PARAM_COLOR ? "color" :
167  info.type == F0R_PARAM_POSITION ? "position" :
168  info.type == F0R_PARAM_STRING ? "string" : "unknown",
169  info.explanation);
170 
171 #ifdef DEBUG
172  av_log(ctx, AV_LOG_DEBUG, "value:");
173  switch (info.type) {
174  void *v;
175  double d;
176  char s[128];
177  f0r_param_color_t col;
178  f0r_param_position_t pos;
179 
180  case F0R_PARAM_BOOL:
181  v = &d;
182  frei0r->get_param_value(frei0r->instance, v, i);
183  av_log(ctx, AV_LOG_DEBUG, "%s", d >= 0.5 && d <= 1.0 ? "y" : "n");
184  break;
185  case F0R_PARAM_DOUBLE:
186  v = &d;
187  frei0r->get_param_value(frei0r->instance, v, i);
188  av_log(ctx, AV_LOG_DEBUG, "%f", d);
189  break;
190  case F0R_PARAM_COLOR:
191  v = &col;
192  frei0r->get_param_value(frei0r->instance, v, i);
193  av_log(ctx, AV_LOG_DEBUG, "%f/%f/%f", col.r, col.g, col.b);
194  break;
195  case F0R_PARAM_POSITION:
196  v = &pos;
197  frei0r->get_param_value(frei0r->instance, v, i);
198  av_log(ctx, AV_LOG_DEBUG, "%f/%f", pos.x, pos.y);
199  break;
200  default: /* F0R_PARAM_STRING */
201  v = s;
202  frei0r->get_param_value(frei0r->instance, v, i);
203  av_log(ctx, AV_LOG_DEBUG, "'%s'\n", s);
204  break;
205  }
206 #endif
207  av_log(ctx, AV_LOG_VERBOSE, "\n");
208  }
209 
210  return 0;
211 }
212 
213 static int load_path(AVFilterContext *ctx, void **handle_ptr, const char *prefix, const char *name)
214 {
215  char *path = av_asprintf("%s%s%s", prefix, name, SLIBSUF);
216  if (!path)
217  return AVERROR(ENOMEM);
218  av_log(ctx, AV_LOG_DEBUG, "Looking for frei0r effect in '%s'\n", path);
219  *handle_ptr = dlopen(path, RTLD_NOW|RTLD_LOCAL);
220  av_free(path);
221  return 0;
222 }
223 
225  const char *dl_name, int type)
226 {
227  Frei0rContext *frei0r = ctx->priv;
228  f0r_init_f f0r_init;
229  f0r_get_plugin_info_f f0r_get_plugin_info;
230  f0r_plugin_info_t *pi;
231  char *path;
232  int ret = 0;
233 
234  if (!dl_name) {
235  av_log(ctx, AV_LOG_ERROR, "No filter name provided.\n");
236  return AVERROR(EINVAL);
237  }
238 
239  /* see: http://frei0r.dyne.org/codedoc/html/group__pluglocations.html */
240  if ((path = av_strdup(getenv("FREI0R_PATH")))) {
241 #ifdef _WIN32
242  const char *separator = ";";
243 #else
244  const char *separator = ":";
245 #endif
246  char *p, *ptr = NULL;
247  for (p = path; p = av_strtok(p, separator, &ptr); p = NULL) {
248  /* add additional trailing slash in case it is missing */
249  char *p1 = av_asprintf("%s/", p);
250  if (!p1) {
251  ret = AVERROR(ENOMEM);
252  goto check_path_end;
253  }
254  ret = load_path(ctx, &frei0r->dl_handle, p1, dl_name);
255  av_free(p1);
256  if (ret < 0)
257  goto check_path_end;
258  if (frei0r->dl_handle)
259  break;
260  }
261 
262  check_path_end:
263  av_free(path);
264  if (ret < 0)
265  return ret;
266  }
267  if (!frei0r->dl_handle && (path = getenv("HOME"))) {
268  char *prefix = av_asprintf("%s/.frei0r-1/lib/", path);
269  if (!prefix)
270  return AVERROR(ENOMEM);
271  ret = load_path(ctx, &frei0r->dl_handle, prefix, dl_name);
272  av_free(prefix);
273  if (ret < 0)
274  return ret;
275  }
276  if (!frei0r->dl_handle) {
277  ret = load_path(ctx, &frei0r->dl_handle, "/usr/local/lib/frei0r-1/", dl_name);
278  if (ret < 0)
279  return ret;
280  }
281  if (!frei0r->dl_handle) {
282  ret = load_path(ctx, &frei0r->dl_handle, "/usr/lib/frei0r-1/", dl_name);
283  if (ret < 0)
284  return ret;
285  }
286  if (!frei0r->dl_handle) {
287  av_log(ctx, AV_LOG_ERROR, "Could not find module '%s'\n", dl_name);
288  return AVERROR(EINVAL);
289  }
290 
291  if (!(f0r_init = load_sym(ctx, "f0r_init" )) ||
292  !(f0r_get_plugin_info = load_sym(ctx, "f0r_get_plugin_info")) ||
293  !(frei0r->get_param_info = load_sym(ctx, "f0r_get_param_info" )) ||
294  !(frei0r->get_param_value = load_sym(ctx, "f0r_get_param_value")) ||
295  !(frei0r->set_param_value = load_sym(ctx, "f0r_set_param_value")) ||
296  !(frei0r->update = load_sym(ctx, "f0r_update" )) ||
297  !(frei0r->construct = load_sym(ctx, "f0r_construct" )) ||
298  !(frei0r->destruct = load_sym(ctx, "f0r_destruct" )) ||
299  !(frei0r->deinit = load_sym(ctx, "f0r_deinit" )))
300  return AVERROR(EINVAL);
301 
302  if (f0r_init() < 0) {
303  av_log(ctx, AV_LOG_ERROR, "Could not init the frei0r module\n");
304  return AVERROR(EINVAL);
305  }
306 
307  f0r_get_plugin_info(&frei0r->plugin_info);
308  pi = &frei0r->plugin_info;
309  if (pi->plugin_type != type) {
310  av_log(ctx, AV_LOG_ERROR,
311  "Invalid type '%s' for the plugin\n",
312  pi->plugin_type == F0R_PLUGIN_TYPE_FILTER ? "filter" :
313  pi->plugin_type == F0R_PLUGIN_TYPE_SOURCE ? "source" :
314  pi->plugin_type == F0R_PLUGIN_TYPE_MIXER2 ? "mixer2" :
315  pi->plugin_type == F0R_PLUGIN_TYPE_MIXER3 ? "mixer3" : "unknown");
316  return AVERROR(EINVAL);
317  }
318 
319  av_log(ctx, AV_LOG_VERBOSE,
320  "name:%s author:'%s' explanation:'%s' color_model:%s "
321  "frei0r_version:%d version:%d.%d num_params:%d\n",
322  pi->name, pi->author, pi->explanation,
323  pi->color_model == F0R_COLOR_MODEL_BGRA8888 ? "bgra8888" :
324  pi->color_model == F0R_COLOR_MODEL_RGBA8888 ? "rgba8888" :
325  pi->color_model == F0R_COLOR_MODEL_PACKED32 ? "packed32" : "unknown",
326  pi->frei0r_version, pi->major_version, pi->minor_version, pi->num_params);
327 
328  return 0;
329 }
330 
332 {
333  Frei0rContext *frei0r = ctx->priv;
334 
335  return frei0r_init(ctx, frei0r->dl_name, F0R_PLUGIN_TYPE_FILTER);
336 }
337 
338 static av_cold void uninit(AVFilterContext *ctx)
339 {
340  Frei0rContext *frei0r = ctx->priv;
341 
342  if (frei0r->destruct && frei0r->instance)
343  frei0r->destruct(frei0r->instance);
344  if (frei0r->deinit)
345  frei0r->deinit();
346  if (frei0r->dl_handle)
347  dlclose(frei0r->dl_handle);
348 }
349 
350 static int config_input_props(AVFilterLink *inlink)
351 {
352  AVFilterContext *ctx = inlink->dst;
353  Frei0rContext *frei0r = ctx->priv;
354 
355  if (!(frei0r->instance = frei0r->construct(inlink->w, inlink->h))) {
356  av_log(ctx, AV_LOG_ERROR, "Impossible to load frei0r instance\n");
357  return AVERROR(EINVAL);
358  }
359 
360  return set_params(ctx, frei0r->params);
361 }
362 
364 {
365  Frei0rContext *frei0r = ctx->priv;
367 
368  if (frei0r->plugin_info.color_model == F0R_COLOR_MODEL_BGRA8888) {
369  ff_add_format(&formats, AV_PIX_FMT_BGRA);
370  } else if (frei0r->plugin_info.color_model == F0R_COLOR_MODEL_RGBA8888) {
371  ff_add_format(&formats, AV_PIX_FMT_RGBA);
372  } else { /* F0R_COLOR_MODEL_PACKED32 */
373  static const enum AVPixelFormat pix_fmts[] = {
375  };
376  formats = ff_make_format_list(pix_fmts);
377  }
378 
379  if (!formats)
380  return AVERROR(ENOMEM);
381 
382  ff_set_common_formats(ctx, formats);
383  return 0;
384 }
385 
386 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
387 {
388  Frei0rContext *frei0r = inlink->dst->priv;
389  AVFilterLink *outlink = inlink->dst->outputs[0];
390  AVFrame *out;
391 
392  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
393  if (!out) {
394  av_frame_free(&in);
395  return AVERROR(ENOMEM);
396  }
397  av_frame_copy_props(out, in);
398 
399  frei0r->update(frei0r->instance, in->pts * av_q2d(inlink->time_base) * 1000,
400  (const uint32_t *)in->data[0],
401  (uint32_t *)out->data[0]);
402 
403  av_frame_free(&in);
404 
405  return ff_filter_frame(outlink, out);
406 }
407 
408 #define OFFSET(x) offsetof(Frei0rContext, x)
409 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
410 static const AVOption filter_options[] = {
411  { "filter_name", NULL, OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
412  { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS },
413  { NULL },
414 };
415 
416 static const AVClass filter_class = {
417  .class_name = "frei0r",
418  .item_name = av_default_item_name,
419  .option = filter_options,
420  .version = LIBAVUTIL_VERSION_INT,
421 };
422 
424  {
425  .name = "default",
426  .type = AVMEDIA_TYPE_VIDEO,
427  .config_props = config_input_props,
428  .filter_frame = filter_frame,
429  },
430  { NULL }
431 };
432 
434  {
435  .name = "default",
436  .type = AVMEDIA_TYPE_VIDEO,
437  },
438  { NULL }
439 };
440 
442  .name = "frei0r",
443  .description = NULL_IF_CONFIG_SMALL("Apply a frei0r effect."),
444 
445  .query_formats = query_formats,
446  .init = filter_init,
447  .uninit = uninit,
448 
449  .priv_size = sizeof(Frei0rContext),
450  .priv_class = &filter_class,
451 
452  .inputs = avfilter_vf_frei0r_inputs,
453 
454  .outputs = avfilter_vf_frei0r_outputs,
455 };
456 
458 {
459  Frei0rContext *frei0r = ctx->priv;
460  AVRational frame_rate_q;
461 
462  if (av_parse_video_size(&frei0r->w, &frei0r->h, frei0r->size) < 0) {
463  av_log(ctx, AV_LOG_ERROR, "Invalid frame size: '%s'\n", frei0r->size);
464  return AVERROR(EINVAL);
465  }
466 
467  if (av_parse_video_rate(&frame_rate_q, frei0r->framerate) < 0) {
468  av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", frei0r->framerate);
469  return AVERROR(EINVAL);
470  }
471  frei0r->time_base.num = frame_rate_q.den;
472  frei0r->time_base.den = frame_rate_q.num;
473 
474  return frei0r_init(ctx, frei0r->dl_name, F0R_PLUGIN_TYPE_SOURCE);
475 }
476 
477 static int source_config_props(AVFilterLink *outlink)
478 {
479  AVFilterContext *ctx = outlink->src;
480  Frei0rContext *frei0r = ctx->priv;
481 
482  if (av_image_check_size(frei0r->w, frei0r->h, 0, ctx) < 0)
483  return AVERROR(EINVAL);
484  outlink->w = frei0r->w;
485  outlink->h = frei0r->h;
486  outlink->time_base = frei0r->time_base;
487  outlink->sample_aspect_ratio = (AVRational){1,1};
488 
489  if (!(frei0r->instance = frei0r->construct(outlink->w, outlink->h))) {
490  av_log(ctx, AV_LOG_ERROR, "Impossible to load frei0r instance\n");
491  return AVERROR(EINVAL);
492  }
493 
494  return set_params(ctx, frei0r->params);
495 }
496 
497 static int source_request_frame(AVFilterLink *outlink)
498 {
499  Frei0rContext *frei0r = outlink->src->priv;
500  AVFrame *frame = ff_get_video_buffer(outlink, outlink->w, outlink->h);
501 
502  if (!frame)
503  return AVERROR(ENOMEM);
504 
505  frame->sample_aspect_ratio = (AVRational) {1, 1};
506  frame->pts = frei0r->pts++;
507 
508  frei0r->update(frei0r->instance, av_rescale_q(frame->pts, frei0r->time_base, (AVRational){1,1000}),
509  NULL, (uint32_t *)frame->data[0]);
510 
511  return ff_filter_frame(outlink, frame);
512 }
513 
514 static const AVOption src_options[] = {
515  { "size", "Dimensions of the generated video.", OFFSET(size), AV_OPT_TYPE_STRING, { .str = "" }, .flags = FLAGS },
516  { "framerate", NULL, OFFSET(framerate), AV_OPT_TYPE_STRING, { .str = "25" }, .flags = FLAGS },
517  { "filter_name", NULL, OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
518  { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS },
519  { NULL },
520 };
521 
522 static const AVClass src_class = {
523  .class_name = "frei0r_src",
524  .item_name = av_default_item_name,
525  .option = src_options,
526  .version = LIBAVUTIL_VERSION_INT,
527 };
528 
530  {
531  .name = "default",
532  .type = AVMEDIA_TYPE_VIDEO,
533  .request_frame = source_request_frame,
534  .config_props = source_config_props
535  },
536  { NULL }
537 };
538 
540  .name = "frei0r_src",
541  .description = NULL_IF_CONFIG_SMALL("Generate a frei0r source."),
542 
543  .priv_size = sizeof(Frei0rContext),
544  .priv_class = &src_class,
545  .init = source_init,
546  .uninit = uninit,
547 
549 
550  .inputs = NULL,
551 
552  .outputs = avfilter_vsrc_frei0r_src_outputs,
553 };
const char * name
Definition: avisynth_c.h:675
float v
const char * s
Definition: avisynth_c.h:668
AVFilter avfilter_vsrc_frei0r_src
Definition: vf_frei0r.c:539
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:424
static av_cold int filter_init(AVFilterContext *ctx)
Definition: vf_frei0r.c:331
#define FLAGS
Definition: vf_frei0r.c:409
char * dl_name
Definition: vf_frei0r.c:70
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:162
AVOption.
Definition: opt.h:251
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition: parseutils.c:131
av_default_item_name
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
external API header
memory handling functions
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int num
numerator
Definition: rational.h:44
f0r_plugin_info_t plugin_info
Definition: vf_frei0r.c:61
static const AVOption src_options[]
Definition: vf_frei0r.c:514
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
Definition: git-howto.txt:5
void(* f0r_get_plugin_info_f)(f0r_plugin_info_t *info)
Definition: vf_frei0r.c:49
int(* f0r_init_f)(void)
Definition: vf_frei0r.c:48
char * params
Definition: vf_frei0r.c:71
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:143
static const AVFilterPad avfilter_vf_frei0r_outputs[]
Definition: vf_frei0r.c:433
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:308
set threshold d
const char * name
Pad name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:55
f0r_get_param_value_f get_param_value
Definition: vf_frei0r.c:64
uint8_t
it can be given away to ff_start_frame *A reference passed to ff_filter_frame(or the deprecated ff_start_frame) is given away and must no longer be used.*A reference created with avfilter_ref_buffer belongs to the code that created it.*A reference obtained with ff_get_video_buffer or ff_get_audio_buffer belongs to the code that requested it.*A reference given as return value by the get_video_buffer or get_audio_buffer method is given away and must no longer be used.Link reference fields---------------------The AVFilterLink structure has a few AVFilterBufferRef fields.The cur_buf and out_buf were used with the deprecated start_frame/draw_slice/end_frame API and should no longer be used.src_buf
#define av_cold
Definition: attributes.h:78
AVOptions.
static int query_formats(AVFilterContext *ctx)
Definition: vf_frei0r.c:363
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:159
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_frei0r.c:338
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:98
double strtod(const char *, char **)
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
static av_cold int frei0r_init(AVFilterContext *ctx, const char *dl_name, int type)
Definition: vf_frei0r.c:224
void ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:545
char * framerate
Definition: vf_frei0r.c:73
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
Definition: parseutils.c:337
frame
Definition: stft.m:14
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:130
static int load_path(AVFilterContext *ctx, void **handle_ptr, const char *prefix, const char *name)
Definition: vf_frei0r.c:213
AVRational time_base
Definition: vf_frei0r.c:77
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
void(* f0r_update_f)(f0r_instance_t instance, double time, const uint32_t *inframe, uint32_t *outframe)
Definition: vf_frei0r.c:51
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:99
void * priv
private data for use by the filter
Definition: avfilter.h:545
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
static const AVFilterPad avfilter_vsrc_frei0r_src_outputs[]
Definition: vf_frei0r.c:529
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:344
void(* f0r_get_param_info_f)(f0r_param_info_t *info, int param_index)
Definition: vf_frei0r.c:50
void(* f0r_deinit_f)(void)
Definition: vf_frei0r.c:47
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:96
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
Definition: avstring.c:148
char * size
Definition: vf_frei0r.c:72
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:97
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:112
void * dl_handle
Definition: vf_frei0r.c:59
common internal API header
#define AV_LOG_VERBOSE
Definition: log.h:157
struct AVRational AVRational
rational number numerator/denominator
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:231
MIPS optimizations info
Definition: mips.txt:2
struct Frei0rContext Frei0rContext
uint64_t pts
Definition: vf_frei0r.c:78
ret
Definition: avfilter.c:821
static int source_config_props(AVFilterLink *outlink)
Definition: vf_frei0r.c:477
f0r_get_param_info_f get_param_info
Definition: vf_frei0r.c:63
static const AVClass src_class
Definition: vf_frei0r.c:522
f0r_destruct_f destruct
Definition: vf_frei0r.c:67
f0r_update_f update
Definition: vf_frei0r.c:58
static int config_input_props(AVFilterLink *inlink)
Definition: vf_frei0r.c:350
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
static int set_params(AVFilterContext *ctx, const char *params)
Definition: vf_frei0r.c:139
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)
Definition: vf_frei0r.c:52
#define SLIBSUF
Definition: config.h:12
NULL
Definition: eval.c:55
static int width
Definition: tests/utils.c:158
typedef void(RENAME(mix_any_func_type))
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:220
f0r_construct_f construct
Definition: vf_frei0r.c:66
void(* f0r_set_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index)
Definition: vf_frei0r.c:53
static const AVFilterPad avfilter_vf_frei0r_inputs[]
Definition: vf_frei0r.c:423
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:154
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
#define OFFSET(x)
Definition: vf_frei0r.c:408
f0r_instance_t instance
Definition: vf_frei0r.c:60
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:436
int index
Definition: gxfenc.c:89
synthesis window for stochastic i
static const AVClass filter_class
Definition: vf_frei0r.c:416
rational number numerator/denominator
Definition: rational.h:43
const char * name
filter name
Definition: avfilter.h:437
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
misc parsing utilities
#define type
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:539
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok()...
Definition: avstring.c:183
static const AVOption filter_options[]
Definition: vf_frei0r.c:410
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_frei0r.c:386
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:162
f0r_set_param_value_f set_param_value
Definition: vf_frei0r.c:65
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common formats
Definition: swscale.txt:33
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:108
static void * load_sym(AVFilterContext *ctx, const char *sym_name)
Definition: vf_frei0r.c:81
static int set_param(AVFilterContext *ctx, f0r_param_info_t info, int index, char *param)
Definition: vf_frei0r.c:90
int den
denominator
Definition: rational.h:45
AVFilter avfilter_vf_frei0r
Definition: vf_frei0r.c:441
A list of supported formats for one end of a filter link.
Definition: formats.h:64
void(* f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index)
Definition: vf_frei0r.c:54
void(* f0r_destruct_f)(f0r_instance_t instance)
Definition: vf_frei0r.c:46
An instance of a filter.
Definition: avfilter.h:524
static int source_request_frame(AVFilterLink *outlink)
Definition: vf_frei0r.c:497
f0r_deinit_f deinit
Definition: vf_frei0r.c:68
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
f0r_instance_t(* f0r_construct_f)(unsigned int width, unsigned int height)
Definition: vf_frei0r.c:45
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
static av_cold int source_init(AVFilterContext *ctx)
Definition: vf_frei0r.c:457