FFmpeg  4.4.9
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 #if HAVE_OPENCV2_CORE_CORE_C_H
28 #include <opencv2/core/core_c.h>
29 #include <opencv2/imgproc/imgproc_c.h>
30 #else
31 #include <opencv/cv.h>
32 #include <opencv/cxcore.h>
33 #endif
34 #include "libavutil/avstring.h"
35 #include "libavutil/common.h"
36 #include "libavutil/file.h"
37 #include "libavutil/opt.h"
38 #include "avfilter.h"
39 #include "formats.h"
40 #include "internal.h"
41 #include "video.h"
42 
43 static void fill_iplimage_from_frame(IplImage **_img, const AVFrame *frame, enum AVPixelFormat pixfmt)
44 {
45  IplImage *img;
46  int depth, channels_nb;
47 
48  if (pixfmt == AV_PIX_FMT_GRAY8) { depth = IPL_DEPTH_8U; channels_nb = 1; }
49  else if (pixfmt == AV_PIX_FMT_BGRA) { depth = IPL_DEPTH_8U; channels_nb = 4; }
50  else if (pixfmt == AV_PIX_FMT_BGR24) { depth = IPL_DEPTH_8U; channels_nb = 3; }
51  else return;
52 
53  *_img = img = cvCreateImageHeader((CvSize){frame->width, frame->height}, depth, channels_nb);
54  img->imageData = img->imageDataOrigin = frame->data[0];
55  img->dataOrder = IPL_DATA_ORDER_PIXEL;
56  img->origin = IPL_ORIGIN_TL;
57  img->widthStep = frame->linesize[0];
58 }
59 
60 static void fill_frame_from_iplimage(AVFrame *frame, const IplImage *img, enum AVPixelFormat pixfmt)
61 {
62  frame->linesize[0] = img->widthStep;
63  frame->data[0] = img->imageData;
64 }
65 
67 {
68  static const enum AVPixelFormat pix_fmts[] = {
70  };
72  if (!fmts_list)
73  return AVERROR(ENOMEM);
74  return ff_set_common_formats(ctx, fmts_list);
75 }
76 
77 typedef struct OCVContext {
78  const AVClass *class;
79  char *name;
80  char *params;
81  int (*init)(AVFilterContext *ctx, const char *args);
83  void (*end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg);
84  void *priv;
85 } OCVContext;
86 
87 typedef struct SmoothContext {
88  int type;
89  int param1, param2;
90  double param3, param4;
92 
93 static av_cold int smooth_init(AVFilterContext *ctx, const char *args)
94 {
95  OCVContext *s = ctx->priv;
96  SmoothContext *smooth = s->priv;
97  char type_str[128] = "gaussian";
98 
99  smooth->param1 = 3;
100  smooth->param2 = 0;
101  smooth->param3 = 0.0;
102  smooth->param4 = 0.0;
103 
104  if (args)
105  sscanf(args, "%127[^|]|%d|%d|%lf|%lf", type_str, &smooth->param1, &smooth->param2, &smooth->param3, &smooth->param4);
106 
107  if (!strcmp(type_str, "blur" )) smooth->type = CV_BLUR;
108  else if (!strcmp(type_str, "blur_no_scale")) smooth->type = CV_BLUR_NO_SCALE;
109  else if (!strcmp(type_str, "median" )) smooth->type = CV_MEDIAN;
110  else if (!strcmp(type_str, "gaussian" )) smooth->type = CV_GAUSSIAN;
111  else if (!strcmp(type_str, "bilateral" )) smooth->type = CV_BILATERAL;
112  else {
113  av_log(ctx, AV_LOG_ERROR, "Smoothing type '%s' unknown.\n", type_str);
114  return AVERROR(EINVAL);
115  }
116 
117  if (smooth->param1 < 0 || !(smooth->param1%2)) {
119  "Invalid value '%d' for param1, it has to be a positive odd number\n",
120  smooth->param1);
121  return AVERROR(EINVAL);
122  }
123  if ((smooth->type == CV_BLUR || smooth->type == CV_BLUR_NO_SCALE || smooth->type == CV_GAUSSIAN) &&
124  (smooth->param2 < 0 || (smooth->param2 && !(smooth->param2%2)))) {
126  "Invalid value '%d' for param2, it has to be zero or a positive odd number\n",
127  smooth->param2);
128  return AVERROR(EINVAL);
129  }
130 
131  av_log(ctx, AV_LOG_VERBOSE, "type:%s param1:%d param2:%d param3:%f param4:%f\n",
132  type_str, smooth->param1, smooth->param2, smooth->param3, smooth->param4);
133  return 0;
134 }
135 
136 static void smooth_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
137 {
138  OCVContext *s = ctx->priv;
139  SmoothContext *smooth = s->priv;
140  cvSmooth(inimg, outimg, smooth->type, smooth->param1, smooth->param2, smooth->param3, smooth->param4);
141 }
142 
143 static int read_shape_from_file(int *cols, int *rows, int **values, const char *filename,
144  void *log_ctx)
145 {
146  uint8_t *buf, *p, *pend;
147  size_t size, i;
148  int ret, j, w;
149 
150  if ((ret = av_file_map(filename, &buf, &size, 0, log_ctx)) < 0)
151  return ret;
152 
153  /* the file alone defines the size of the shape */
154  *cols = *rows = 0;
155 
156  /* prescan file to get the number of lines and the maximum width */
157  w = 0;
158  for (i = 0; i < size; i++) {
159  if (buf[i] == '\n') {
160  if (*rows == INT_MAX) {
161  av_log(log_ctx, AV_LOG_ERROR, "Overflow on the number of rows in the file\n");
162  ret = AVERROR_INVALIDDATA;
163  goto end;
164  }
165  ++(*rows);
166  *cols = FFMAX(*cols, w);
167  w = 0;
168  } else if (w == INT_MAX) {
169  av_log(log_ctx, AV_LOG_ERROR, "Overflow on the number of columns in the file\n");
170  ret = AVERROR_INVALIDDATA;
171  goto end;
172  } else
173  w++;
174  }
175  if (*cols == 0) {
176  av_log(log_ctx, AV_LOG_ERROR, "No columns in the shape file\n");
177  ret = AVERROR_INVALIDDATA;
178  goto end;
179  }
180  if (*rows > (SIZE_MAX / sizeof(int) / *cols)) {
181  av_log(log_ctx, AV_LOG_ERROR, "File with size %dx%d is too big\n",
182  *rows, *cols);
183  ret = AVERROR_INVALIDDATA;
184  goto end;
185  }
186  if (!(*values = av_mallocz_array(sizeof(int) * *rows, *cols))) {
187  ret = AVERROR(ENOMEM);
188  goto end;
189  }
190 
191  /* fill *values */
192  p = buf;
193  pend = buf + size-1;
194  for (i = 0; i < *rows; i++) {
195  for (j = 0;; j++) {
196  if (p > pend)
197  break;
198  if (*p == '\n') {
199  p++;
200  break;
201  } else
202  (*values)[*cols*i + j] = !!av_isgraph(*(p++));
203  }
204  }
205 
206 end:
207  av_file_unmap(buf, size);
208  if (ret < 0)
209  return ret;
210 
211 #ifdef DEBUG
212  {
213  char *line;
214  if (!(line = av_malloc(*cols + 1)))
215  return AVERROR(ENOMEM);
216  for (i = 0; i < *rows; i++) {
217  for (j = 0; j < *cols; j++)
218  line[j] = (*values)[i * *cols + j] ? '@' : ' ';
219  line[j] = 0;
220  av_log(log_ctx, AV_LOG_DEBUG, "%3zu: %s\n", i, line);
221  }
222  av_free(line);
223  }
224 #endif
225 
226  return 0;
227 }
228 
229 static int parse_iplconvkernel(IplConvKernel **kernel, char *buf, void *log_ctx)
230 {
231  char shape_filename[128] = "", shape_str[32] = "rect";
232  int cols = 0, rows = 0, anchor_x = 0, anchor_y = 0, shape = CV_SHAPE_RECT;
233  int *values = NULL, ret = 0;
234 
235  sscanf(buf, "%dx%d+%dx%d/%31[^=]=%127s", &cols, &rows, &anchor_x, &anchor_y, shape_str, shape_filename);
236 
237  if (!strcmp(shape_str, "rect" )) shape = CV_SHAPE_RECT;
238  else if (!strcmp(shape_str, "cross" )) shape = CV_SHAPE_CROSS;
239  else if (!strcmp(shape_str, "ellipse")) shape = CV_SHAPE_ELLIPSE;
240  else if (!strcmp(shape_str, "custom" )) {
241  shape = CV_SHAPE_CUSTOM;
242  if ((ret = read_shape_from_file(&cols, &rows, &values, shape_filename, log_ctx)) < 0)
243  goto out;
244  } else {
245  av_log(log_ctx, AV_LOG_ERROR,
246  "Shape unspecified or type '%s' unknown.\n", shape_str);
247  ret = AVERROR(EINVAL);
248  goto out;
249  }
250 
251  if (rows <= 0 || cols <= 0) {
252  av_log(log_ctx, AV_LOG_ERROR,
253  "Invalid non-positive values for shape size %dx%d\n", cols, rows);
254  ret = AVERROR(EINVAL);
255  goto out;
256  }
257 
258  if (rows > (INT_MAX - sizeof(IplConvKernel) - 32) / sizeof(int) / cols) {
259  av_log(log_ctx, AV_LOG_ERROR, "Shape size %dx%d is too big\n", cols, rows);
260  ret = AVERROR(EINVAL);
261  goto out;
262  }
263 
264  if (anchor_x < 0 || anchor_y < 0 || anchor_x >= cols || anchor_y >= rows) {
265  av_log(log_ctx, AV_LOG_ERROR,
266  "Shape anchor %dx%d is not inside the rectangle with size %dx%d.\n",
267  anchor_x, anchor_y, cols, rows);
268  ret = AVERROR(EINVAL);
269  goto out;
270  }
271 
272  *kernel = cvCreateStructuringElementEx(cols, rows, anchor_x, anchor_y, shape, values);
273  if (!*kernel) {
274  ret = AVERROR(ENOMEM);
275  goto out;
276  }
277 
278  av_log(log_ctx, AV_LOG_VERBOSE, "Structuring element: w:%d h:%d x:%d y:%d shape:%s\n",
279  rows, cols, anchor_x, anchor_y, shape_str);
280 out:
281  av_freep(&values);
282  return ret;
283 }
284 
285 typedef struct DilateContext {
287  IplConvKernel *kernel;
288 } DilateContext;
289 
290 static av_cold int dilate_init(AVFilterContext *ctx, const char *args)
291 {
292  OCVContext *s = ctx->priv;
293  DilateContext *dilate = s->priv;
294  char default_kernel_str[] = "3x3+0x0/rect";
295  char *kernel_str = NULL;
296  const char *buf = args;
297  int ret;
298 
299  if (args) {
300  kernel_str = av_get_token(&buf, "|");
301 
302  if (!kernel_str)
303  return AVERROR(ENOMEM);
304  }
305 
306  ret = parse_iplconvkernel(&dilate->kernel,
307  (!kernel_str || !*kernel_str) ? default_kernel_str
308  : kernel_str,
309  ctx);
310  av_free(kernel_str);
311  if (ret < 0)
312  return ret;
313 
314  if (!buf || sscanf(buf, "|%d", &dilate->nb_iterations) != 1)
315  dilate->nb_iterations = 1;
316  av_log(ctx, AV_LOG_VERBOSE, "iterations_nb:%d\n", dilate->nb_iterations);
317  if (dilate->nb_iterations <= 0) {
318  av_log(ctx, AV_LOG_ERROR, "Invalid non-positive value '%d' for nb_iterations\n",
319  dilate->nb_iterations);
320  return AVERROR(EINVAL);
321  }
322  return 0;
323 }
324 
326 {
327  OCVContext *s = ctx->priv;
328  DilateContext *dilate = s->priv;
329 
330  if (!dilate)
331  return;
332  cvReleaseStructuringElement(&dilate->kernel);
333 }
334 
335 static void dilate_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
336 {
337  OCVContext *s = ctx->priv;
338  DilateContext *dilate = s->priv;
339  cvDilate(inimg, outimg, dilate->kernel, dilate->nb_iterations);
340 }
341 
342 static void erode_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
343 {
344  OCVContext *s = ctx->priv;
345  DilateContext *dilate = s->priv;
346  cvErode(inimg, outimg, dilate->kernel, dilate->nb_iterations);
347 }
348 
349 typedef struct OCVFilterEntry {
350  const char *name;
351  size_t priv_size;
352  int (*init)(AVFilterContext *ctx, const char *args);
354  void (*end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg);
356 
360  { "smooth", sizeof(SmoothContext), smooth_init, NULL, smooth_end_frame_filter },
361 };
362 
364 {
365  OCVContext *s = ctx->priv;
366  int i;
367 
368  if (!s->name) {
369  av_log(ctx, AV_LOG_ERROR, "No libopencv filter name specified\n");
370  return AVERROR(EINVAL);
371  }
372  for (i = 0; i < FF_ARRAY_ELEMS(ocv_filter_entries); i++) {
373  const OCVFilterEntry *entry = &ocv_filter_entries[i];
374  if (!strcmp(s->name, entry->name)) {
375  s->init = entry->init;
376  s->uninit = entry->uninit;
377  s->end_frame_filter = entry->end_frame_filter;
378 
379  if (!(s->priv = av_mallocz(entry->priv_size)))
380  return AVERROR(ENOMEM);
381  return s->init(ctx, s->params);
382  }
383  }
384 
385  av_log(ctx, AV_LOG_ERROR, "No libopencv filter named '%s'\n", s->name);
386  return AVERROR(EINVAL);
387 }
388 
390 {
391  OCVContext *s = ctx->priv;
392 
393  if (s->uninit)
394  s->uninit(ctx);
395  av_freep(&s->priv);
396 }
397 
398 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
399 {
400  AVFilterContext *ctx = inlink->dst;
401  OCVContext *s = ctx->priv;
402  AVFilterLink *outlink= inlink->dst->outputs[0];
403  AVFrame *out;
404  IplImage *inimg, *outimg;
405 
406  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
407  if (!out) {
408  av_frame_free(&in);
409  return AVERROR(ENOMEM);
410  }
412 
413  fill_iplimage_from_frame(&inimg , in , inlink->format);
414  fill_iplimage_from_frame(&outimg, out, inlink->format);
415  s->end_frame_filter(ctx, inimg, outimg);
416  fill_frame_from_iplimage(out, outimg, inlink->format);
417 
418  av_frame_free(&in);
419  cvReleaseImageHeader(&inimg);
420  cvReleaseImageHeader(&outimg);
421 
422  return ff_filter_frame(outlink, out);
423 }
424 
425 #define OFFSET(x) offsetof(OCVContext, x)
426 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
427 static const AVOption ocv_options[] = {
428  { "filter_name", NULL, OFFSET(name), AV_OPT_TYPE_STRING, .flags = FLAGS },
429  { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS },
430  { NULL }
431 };
432 
434 
436  {
437  .name = "default",
438  .type = AVMEDIA_TYPE_VIDEO,
439  .filter_frame = filter_frame,
440  },
441  { NULL }
442 };
443 
445  {
446  .name = "default",
447  .type = AVMEDIA_TYPE_VIDEO,
448  },
449  { NULL }
450 };
451 
453  .name = "ocv",
454  .description = NULL_IF_CONFIG_SMALL("Apply transform using libopencv."),
455  .priv_size = sizeof(OCVContext),
456  .priv_class = &ocv_class,
458  .init = init,
459  .uninit = uninit,
462 };
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
#define av_cold
Definition: attributes.h:88
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=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);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_AARCH64) ff_audio_convert_init_aarch64(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_log(ac->avr, AV_LOG_TRACE, "%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-> in
uint8_t
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1099
Main libavfilter public API header.
#define s(width, name)
Definition: cbs_vp9.c:257
common internal and external API header
#define FFMAX(a, b)
Definition: common.h:103
#define NULL
Definition: coverity.c:32
static AVFrame * frame
int
Misc file utilities.
int 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:587
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:210
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
Definition: mem.c:190
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
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:151
static av_const int av_isgraph(int c)
Locale-independent conversion of ASCII isgraph.
Definition: avstring.h:219
int i
Definition: input.c:407
enum AVPixelFormat pixfmt
Definition: kmsgrab.c:365
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Definition: file.c:144
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:53
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
uint8_t w
Definition: llviddspenc.c:39
AVOptions.
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
const char * name
Definition: qsvenc.c:46
typedef void(RENAME(mix_any_func_type))
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
Definition: log.h:67
An instance of a filter.
Definition: avfilter.h:341
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:353
A list of supported formats for one end of a filter link.
Definition: formats.h:65
A filter pad used for either input or output.
Definition: internal.h:54
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int width
Definition: frame.h:376
int height
Definition: frame.h:376
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
AVOption.
Definition: opt.h:248
IplConvKernel * kernel
Definition: vf_libopencv.c:287
int(* init)(AVFilterContext *ctx, const char *args)
Definition: vf_libopencv.c:81
void(* uninit)(AVFilterContext *ctx)
Definition: vf_libopencv.c:82
void * priv
Definition: vf_libopencv.c:84
char * params
Definition: vf_libopencv.c:80
void(* end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
Definition: vf_libopencv.c:83
char * name
Definition: vf_libopencv.c:79
void(* end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
Definition: vf_libopencv.c:354
const char * name
Definition: vf_libopencv.c:350
void(* uninit)(AVFilterContext *ctx)
Definition: vf_libopencv.c:353
int(* init)(AVFilterContext *ctx, const char *args)
Definition: vf_libopencv.c:352
Definition: graph2dot.c:48
#define av_free(p)
#define av_freep(p)
#define av_malloc(s)
#define av_log(a,...)
FILE * out
Definition: movenc.c:54
AVFormatContext * ctx
Definition: movenc.c:48
int size
#define img
static float smooth(DeshakeOpenCLContext *deshake_ctx, float *gauss_kernel, int length, float max_val, AVFifoBuffer *values)
static av_cold int smooth_init(AVFilterContext *ctx, const char *args)
Definition: vf_libopencv.c:93
static const AVOption ocv_options[]
Definition: vf_libopencv.c:427
static const AVFilterPad avfilter_vf_ocv_outputs[]
Definition: vf_libopencv.c:444
AVFILTER_DEFINE_CLASS(ocv)
static void dilate_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
Definition: vf_libopencv.c:335
static const AVFilterPad avfilter_vf_ocv_inputs[]
Definition: vf_libopencv.c:435
static int query_formats(AVFilterContext *ctx)
Definition: vf_libopencv.c:66
static void erode_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
Definition: vf_libopencv.c:342
#define FLAGS
Definition: vf_libopencv.c:426
static const OCVFilterEntry ocv_filter_entries[]
Definition: vf_libopencv.c:357
static int parse_iplconvkernel(IplConvKernel **kernel, char *buf, void *log_ctx)
Definition: vf_libopencv.c:229
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_libopencv.c:398
static void fill_frame_from_iplimage(AVFrame *frame, const IplImage *img, enum AVPixelFormat pixfmt)
Definition: vf_libopencv.c:60
static av_cold int dilate_init(AVFilterContext *ctx, const char *args)
Definition: vf_libopencv.c:290
static av_cold int init(AVFilterContext *ctx)
Definition: vf_libopencv.c:363
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_libopencv.c:389
static int read_shape_from_file(int *cols, int *rows, int **values, const char *filename, void *log_ctx)
Definition: vf_libopencv.c:143
#define OFFSET(x)
Definition: vf_libopencv.c:425
static av_cold void dilate_uninit(AVFilterContext *ctx)
Definition: vf_libopencv.c:325
AVFilter ff_vf_ocv
Definition: vf_libopencv.c:452
static void fill_iplimage_from_frame(IplImage **_img, const AVFrame *frame, enum AVPixelFormat pixfmt)
Definition: vf_libopencv.c:43
static void smooth_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
Definition: vf_libopencv.c:136
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:104