FFmpeg
vf_libopencv.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Stefano Sabatini
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * libopencv wrapper functions
24  */
25 
26 #include "config.h"
27 #include <opencv2/core/core_c.h>
28 #include <opencv2/imgproc/imgproc_c.h>
29 #include "libavutil/avstring.h"
30 #include "libavutil/common.h"
31 #include "libavutil/file.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/opt.h"
34 #include "avfilter.h"
35 #include "filters.h"
36 #include "formats.h"
37 #include "video.h"
38 
39 static void fill_iplimage_from_frame(IplImage *img, const AVFrame *frame, enum AVPixelFormat pixfmt)
40 {
41  IplImage *tmpimg;
42  int depth, channels_nb;
43 
44  if (pixfmt == AV_PIX_FMT_GRAY8) { depth = IPL_DEPTH_8U; channels_nb = 1; }
45  else if (pixfmt == AV_PIX_FMT_BGRA) { depth = IPL_DEPTH_8U; channels_nb = 4; }
46  else if (pixfmt == AV_PIX_FMT_BGR24) { depth = IPL_DEPTH_8U; channels_nb = 3; }
47  else return;
48 
49  tmpimg = cvCreateImageHeader((CvSize){frame->width, frame->height}, depth, channels_nb);
50  *img = *tmpimg;
51  img->imageData = img->imageDataOrigin = frame->data[0];
52  img->dataOrder = IPL_DATA_ORDER_PIXEL;
53  img->origin = IPL_ORIGIN_TL;
54  img->widthStep = frame->linesize[0];
55 }
56 
57 static void fill_frame_from_iplimage(AVFrame *frame, const IplImage *img, enum AVPixelFormat pixfmt)
58 {
59  frame->linesize[0] = img->widthStep;
60  frame->data[0] = img->imageData;
61 }
62 
63 typedef struct OCVContext {
64  const AVClass *class;
65  char *name;
66  char *params;
67  int (*init)(AVFilterContext *ctx, const char *args);
69  void (*end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg);
70  void *priv;
71 } OCVContext;
72 
73 typedef struct SmoothContext {
74  int type;
75  int param1, param2;
76  double param3, param4;
78 
79 static av_cold int smooth_init(AVFilterContext *ctx, const char *args)
80 {
81  OCVContext *s = ctx->priv;
82  SmoothContext *smooth = s->priv;
83  char type_str[128] = "gaussian";
84 
85  smooth->param1 = 3;
86  smooth->param2 = 0;
87  smooth->param3 = 0.0;
88  smooth->param4 = 0.0;
89 
90  if (args)
91  sscanf(args, "%127[^|]|%d|%d|%lf|%lf", type_str, &smooth->param1, &smooth->param2, &smooth->param3, &smooth->param4);
92 
93  if (!strcmp(type_str, "blur" )) smooth->type = CV_BLUR;
94  else if (!strcmp(type_str, "blur_no_scale")) smooth->type = CV_BLUR_NO_SCALE;
95  else if (!strcmp(type_str, "median" )) smooth->type = CV_MEDIAN;
96  else if (!strcmp(type_str, "gaussian" )) smooth->type = CV_GAUSSIAN;
97  else if (!strcmp(type_str, "bilateral" )) smooth->type = CV_BILATERAL;
98  else {
99  av_log(ctx, AV_LOG_ERROR, "Smoothing type '%s' unknown.\n", type_str);
100  return AVERROR(EINVAL);
101  }
102 
103  if (smooth->param1 < 0 || !(smooth->param1%2)) {
105  "Invalid value '%d' for param1, it has to be a positive odd number\n",
106  smooth->param1);
107  return AVERROR(EINVAL);
108  }
109  if ((smooth->type == CV_BLUR || smooth->type == CV_BLUR_NO_SCALE || smooth->type == CV_GAUSSIAN) &&
110  (smooth->param2 < 0 || (smooth->param2 && !(smooth->param2%2)))) {
112  "Invalid value '%d' for param2, it has to be zero or a positive odd number\n",
113  smooth->param2);
114  return AVERROR(EINVAL);
115  }
116 
117  av_log(ctx, AV_LOG_VERBOSE, "type:%s param1:%d param2:%d param3:%f param4:%f\n",
118  type_str, smooth->param1, smooth->param2, smooth->param3, smooth->param4);
119  return 0;
120 }
121 
122 static void smooth_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
123 {
124  OCVContext *s = ctx->priv;
125  SmoothContext *smooth = s->priv;
126  cvSmooth(inimg, outimg, smooth->type, smooth->param1, smooth->param2, smooth->param3, smooth->param4);
127 }
128 
129 static int read_shape_from_file(int *cols, int *rows, int **values, const char *filename,
130  void *log_ctx)
131 {
132  uint8_t *buf, *p, *pend;
133  size_t size;
134  int ret, i, j, w;
135 
136  if ((ret = av_file_map(filename, &buf, &size, 0, log_ctx)) < 0)
137  return ret;
138 
139  /* prescan file to get the number of lines and the maximum width */
140  w = 0;
141  for (i = 0; i < size; i++) {
142  if (buf[i] == '\n') {
143  if (*rows == INT_MAX) {
144  av_log(log_ctx, AV_LOG_ERROR, "Overflow on the number of rows in the file\n");
146  goto end;
147  }
148  ++(*rows);
149  *cols = FFMAX(*cols, w);
150  w = 0;
151  } else if (w == INT_MAX) {
152  av_log(log_ctx, AV_LOG_ERROR, "Overflow on the number of columns in the file\n");
153  return AVERROR_INVALIDDATA;
154  }
155  w++;
156  }
157  if (*rows > (SIZE_MAX / sizeof(int) / *cols)) {
158  av_log(log_ctx, AV_LOG_ERROR, "File with size %dx%d is too big\n",
159  *rows, *cols);
161  goto end;
162  }
163  if (!(*values = av_calloc(*cols, sizeof(**values) * *rows))) {
164  ret = AVERROR(ENOMEM);
165  goto end;
166  }
167 
168  /* fill *values */
169  p = buf;
170  pend = buf + size-1;
171  for (i = 0; i < *rows; i++) {
172  for (j = 0;; j++) {
173  if (p > pend || *p == '\n') {
174  p++;
175  break;
176  } else
177  (*values)[*cols*i + j] = !!av_isgraph(*(p++));
178  }
179  }
180 
181 end:
182  av_file_unmap(buf, size);
183 
184 #ifdef DEBUG
185  {
186  char *line;
187  if (!(line = av_malloc(*cols + 1)))
188  return AVERROR(ENOMEM);
189  for (i = 0; i < *rows; i++) {
190  for (j = 0; j < *cols; j++)
191  line[j] = (*values)[i * *cols + j] ? '@' : ' ';
192  line[j] = 0;
193  av_log(log_ctx, AV_LOG_DEBUG, "%3d: %s\n", i, line);
194  }
195  av_free(line);
196  }
197 #endif
198 
199  return 0;
200 }
201 
202 static int parse_iplconvkernel(IplConvKernel **kernel, char *buf, void *log_ctx)
203 {
204  char shape_filename[128] = "", shape_str[32] = "rect";
205  int cols = 0, rows = 0, anchor_x = 0, anchor_y = 0, shape = CV_SHAPE_RECT;
206  int *values = NULL, ret = 0;
207 
208  sscanf(buf, "%dx%d+%dx%d/%32[^=]=%127s", &cols, &rows, &anchor_x, &anchor_y, shape_str, shape_filename);
209 
210  if (!strcmp(shape_str, "rect" )) shape = CV_SHAPE_RECT;
211  else if (!strcmp(shape_str, "cross" )) shape = CV_SHAPE_CROSS;
212  else if (!strcmp(shape_str, "ellipse")) shape = CV_SHAPE_ELLIPSE;
213  else if (!strcmp(shape_str, "custom" )) {
214  shape = CV_SHAPE_CUSTOM;
215  if ((ret = read_shape_from_file(&cols, &rows, &values, shape_filename, log_ctx)) < 0)
216  return ret;
217  } else {
218  av_log(log_ctx, AV_LOG_ERROR,
219  "Shape unspecified or type '%s' unknown.\n", shape_str);
220  ret = AVERROR(EINVAL);
221  goto out;
222  }
223 
224  if (rows <= 0 || cols <= 0) {
225  av_log(log_ctx, AV_LOG_ERROR,
226  "Invalid non-positive values for shape size %dx%d\n", cols, rows);
227  ret = AVERROR(EINVAL);
228  goto out;
229  }
230 
231  if (anchor_x < 0 || anchor_y < 0 || anchor_x >= cols || anchor_y >= rows) {
232  av_log(log_ctx, AV_LOG_ERROR,
233  "Shape anchor %dx%d is not inside the rectangle with size %dx%d.\n",
234  anchor_x, anchor_y, cols, rows);
235  ret = AVERROR(EINVAL);
236  goto out;
237  }
238 
239  *kernel = cvCreateStructuringElementEx(cols, rows, anchor_x, anchor_y, shape, values);
240  if (!*kernel) {
241  ret = AVERROR(ENOMEM);
242  goto out;
243  }
244 
245  av_log(log_ctx, AV_LOG_VERBOSE, "Structuring element: w:%d h:%d x:%d y:%d shape:%s\n",
246  rows, cols, anchor_x, anchor_y, shape_str);
247 out:
248  av_freep(&values);
249  return ret;
250 }
251 
252 typedef struct DilateContext {
254  IplConvKernel *kernel;
255 } DilateContext;
256 
257 static av_cold int dilate_init(AVFilterContext *ctx, const char *args)
258 {
259  OCVContext *s = ctx->priv;
260  DilateContext *dilate = s->priv;
261  char default_kernel_str[] = "3x3+0x0/rect";
262  char *kernel_str = NULL;
263  const char *buf = args;
264  int ret;
265 
266  if (args) {
267  kernel_str = av_get_token(&buf, "|");
268 
269  if (!kernel_str)
270  return AVERROR(ENOMEM);
271  }
272 
273  ret = parse_iplconvkernel(&dilate->kernel,
274  (!kernel_str || !*kernel_str) ? default_kernel_str
275  : kernel_str,
276  ctx);
277  av_free(kernel_str);
278  if (ret < 0)
279  return ret;
280 
281  if (!buf || sscanf(buf, "|%d", &dilate->nb_iterations) != 1)
282  dilate->nb_iterations = 1;
283  av_log(ctx, AV_LOG_VERBOSE, "iterations_nb:%d\n", dilate->nb_iterations);
284  if (dilate->nb_iterations <= 0) {
285  av_log(ctx, AV_LOG_ERROR, "Invalid non-positive value '%d' for nb_iterations\n",
286  dilate->nb_iterations);
287  return AVERROR(EINVAL);
288  }
289  return 0;
290 }
291 
293 {
294  OCVContext *s = ctx->priv;
295  DilateContext *dilate = s->priv;
296 
297  cvReleaseStructuringElement(&dilate->kernel);
298 }
299 
300 static void dilate_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
301 {
302  OCVContext *s = ctx->priv;
303  DilateContext *dilate = s->priv;
304  cvDilate(inimg, outimg, dilate->kernel, dilate->nb_iterations);
305 }
306 
307 static void erode_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
308 {
309  OCVContext *s = ctx->priv;
310  DilateContext *dilate = s->priv;
311  cvErode(inimg, outimg, dilate->kernel, dilate->nb_iterations);
312 }
313 
314 typedef struct OCVFilterEntry {
315  const char *name;
316  size_t priv_size;
317  int (*init)(AVFilterContext *ctx, const char *args);
319  void (*end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg);
321 
325  { "smooth", sizeof(SmoothContext), smooth_init, NULL, smooth_end_frame_filter },
326 };
327 
329 {
330  OCVContext *s = ctx->priv;
331  int i;
332 
333  if (!s->name) {
334  av_log(ctx, AV_LOG_ERROR, "No libopencv filter name specified\n");
335  return AVERROR(EINVAL);
336  }
337  for (i = 0; i < FF_ARRAY_ELEMS(ocv_filter_entries); i++) {
339  if (!strcmp(s->name, entry->name)) {
340  s->init = entry->init;
341  s->uninit = entry->uninit;
342  s->end_frame_filter = entry->end_frame_filter;
343 
344  if (!(s->priv = av_mallocz(entry->priv_size)))
345  return AVERROR(ENOMEM);
346  return s->init(ctx, s->params);
347  }
348  }
349 
350  av_log(ctx, AV_LOG_ERROR, "No libopencv filter named '%s'\n", s->name);
351  return AVERROR(EINVAL);
352 }
353 
355 {
356  OCVContext *s = ctx->priv;
357 
358  if (s->uninit)
359  s->uninit(ctx);
360  av_freep(&s->priv);
361 }
362 
364 {
365  AVFilterContext *ctx = inlink->dst;
366  OCVContext *s = ctx->priv;
367  AVFilterLink *outlink= inlink->dst->outputs[0];
368  AVFrame *out;
369  IplImage inimg, outimg;
370 
371  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
372  if (!out) {
373  av_frame_free(&in);
374  return AVERROR(ENOMEM);
375  }
377 
378  fill_iplimage_from_frame(&inimg , in , inlink->format);
379  fill_iplimage_from_frame(&outimg, out, inlink->format);
380  s->end_frame_filter(ctx, &inimg, &outimg);
381  fill_frame_from_iplimage(out, &outimg, inlink->format);
382 
383  av_frame_free(&in);
384 
385  return ff_filter_frame(outlink, out);
386 }
387 
388 #define OFFSET(x) offsetof(OCVContext, x)
389 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
390 static const AVOption ocv_options[] = {
391  { "filter_name", NULL, OFFSET(name), AV_OPT_TYPE_STRING, .flags = FLAGS },
392  { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS },
393  { NULL }
394 };
395 
397 
399  {
400  .name = "default",
401  .type = AVMEDIA_TYPE_VIDEO,
402  .filter_frame = filter_frame,
403  },
404 };
405 
407  {
408  .name = "default",
409  .type = AVMEDIA_TYPE_VIDEO,
410  },
411 };
412 
414  .p.name = "ocv",
415  .p.description = NULL_IF_CONFIG_SMALL("Apply transform using libopencv."),
416  .p.priv_class = &ocv_class,
417  .priv_size = sizeof(OCVContext),
418  .init = init,
419  .uninit = uninit,
423 };
SmoothContext
Definition: vf_libopencv.c:73
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:117
OCVFilterEntry::priv_size
size_t priv_size
Definition: vf_libopencv.c:316
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
FLAGS
#define FLAGS
Definition: vf_libopencv.c:389
entry
#define entry
Definition: aom_film_grain_template.c:66
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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. Frame references ownership and permissions
opt.h
out
FILE * out
Definition: movenc.c:55
parse_iplconvkernel
static int parse_iplconvkernel(IplConvKernel **kernel, char *buf, void *log_ctx)
Definition: vf_libopencv.c:202
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1067
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:263
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
w
uint8_t w
Definition: llviddspenc.c:38
AVOption
AVOption.
Definition: opt.h:429
DilateContext
Definition: vf_libopencv.c:252
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:76
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:220
video.h
OCVFilterEntry
Definition: vf_libopencv.c:314
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
formats.h
OCVContext
Definition: vf_libopencv.c:63
OFFSET
#define OFFSET(x)
Definition: vf_libopencv.c:388
dilate_uninit
static av_cold void dilate_uninit(AVFilterContext *ctx)
Definition: vf_libopencv.c:292
av_file_map
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
Definition: file.c:55
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(ocv)
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:39
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:106
FFFilter
Definition: filters.h:266
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_libopencv.c:328
s
#define s(width, name)
Definition: cbs_vp9.c:198
SmoothContext::param4
double param4
Definition: vf_libopencv.c:76
OCVFilterEntry::init
int(* init)(AVFilterContext *ctx, const char *args)
Definition: vf_libopencv.c:317
smooth_end_frame_filter
static void smooth_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
Definition: vf_libopencv.c:122
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_libopencv.c:363
filters.h
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
ctx
AVFormatContext * ctx
Definition: movenc.c:49
ff_vf_ocv
const FFFilter ff_vf_ocv
Definition: vf_libopencv.c:413
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:264
av_file_unmap
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Definition: file.c:142
SmoothContext::param3
double param3
Definition: vf_libopencv.c:76
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:599
avfilter_vf_ocv_outputs
static const AVFilterPad avfilter_vf_ocv_outputs[]
Definition: vf_libopencv.c:406
DilateContext::kernel
IplConvKernel * kernel
Definition: vf_libopencv.c:254
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
OCVContext::priv
void * priv
Definition: vf_libopencv.c:70
OCVFilterEntry::uninit
void(* uninit)(AVFilterContext *ctx)
Definition: vf_libopencv.c:318
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
OCVContext::init
int(* init)(AVFilterContext *ctx, const char *args)
Definition: vf_libopencv.c:67
dilate_init
static av_cold int dilate_init(AVFilterContext *ctx, const char *args)
Definition: vf_libopencv.c:257
size
int size
Definition: twinvq_data.h:10344
fill_iplimage_from_frame
static void fill_iplimage_from_frame(IplImage *img, const AVFrame *frame, enum AVPixelFormat pixfmt)
Definition: vf_libopencv.c:39
OCVContext::params
char * params
Definition: vf_libopencv.c:66
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_libopencv.c:354
av_isgraph
static av_const int av_isgraph(int c)
Locale-independent conversion of ASCII isgraph.
Definition: avstring.h:210
img
#define img
Definition: vf_colormatrix.c:114
erode_end_frame_filter
static void erode_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
Definition: vf_libopencv.c:307
line
Definition: graph2dot.c:48
SmoothContext::param2
int param2
Definition: vf_libopencv.c:75
dilate_end_frame_filter
static void dilate_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
Definition: vf_libopencv.c:300
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
common.h
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
OCVFilterEntry::name
const char * name
Definition: vf_libopencv.c:315
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:45
SmoothContext::param1
int param1
Definition: vf_libopencv.c:75
FILTER_PIXFMTS
#define FILTER_PIXFMTS(...)
Definition: filters.h:249
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
ret
ret
Definition: filter_design.txt:187
pixfmt
enum AVPixelFormat pixfmt
Definition: kmsgrab.c:367
frame
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 the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
fill_frame_from_iplimage
static void fill_frame_from_iplimage(AVFrame *frame, const IplImage *img, enum AVPixelFormat pixfmt)
Definition: vf_libopencv.c:57
DilateContext::nb_iterations
int nb_iterations
Definition: vf_libopencv.c:253
avfilter_vf_ocv_inputs
static const AVFilterPad avfilter_vf_ocv_inputs[]
Definition: vf_libopencv.c:398
avfilter.h
av_get_token
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:143
values
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 the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return values
Definition: filter_design.txt:264
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
file.h
OCVContext::uninit
void(* uninit)(AVFilterContext *ctx)
Definition: vf_libopencv.c:68
AVFilterContext
An instance of a filter.
Definition: avfilter.h:274
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFFilter::p
AVFilter p
The public AVFilter.
Definition: filters.h:270
OCVFilterEntry::end_frame_filter
void(* end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
Definition: vf_libopencv.c:319
read_shape_from_file
static int read_shape_from_file(int *cols, int *rows, int **values, const char *filename, void *log_ctx)
Definition: vf_libopencv.c:129
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
smooth
static float smooth(DeshakeOpenCLContext *deshake_ctx, float *gauss_kernel, int length, float max_val, AVFifo *values)
Definition: vf_deshake_opencl.c:887
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
OCVContext::end_frame_filter
void(* end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
Definition: vf_libopencv.c:69
SmoothContext::type
int type
Definition: vf_libopencv.c:74
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
ocv_filter_entries
static const OCVFilterEntry ocv_filter_entries[]
Definition: vf_libopencv.c:322
dilate
static int dilate(IPlane *g, IPlane *f, chord_set *SE, LUT *Ty, int y0, int y1)
Definition: vf_morpho.c:465
avstring.h
smooth_init
static av_cold int smooth_init(AVFilterContext *ctx, const char *args)
Definition: vf_libopencv.c:79
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
OCVContext::name
char * name
Definition: vf_libopencv.c:65
ocv_options
static const AVOption ocv_options[]
Definition: vf_libopencv.c:390
line
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted line
Definition: swscale.txt:40