FFmpeg
f_drawgraph.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Paul B Mahol
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 #include "float.h"
22 
23 #include "libavutil/avstring.h"
24 #include "libavutil/eval.h"
25 #include "libavutil/intreadwrite.h"
26 #include "libavutil/opt.h"
27 #include "avfilter.h"
28 #include "formats.h"
29 #include "internal.h"
30 #include "video.h"
31 
32 typedef struct DrawGraphContext {
33  const AVClass *class;
34 
35  char *key[4];
36  float min, max;
37  char *fg_str[4];
39  uint8_t bg[4];
40  int mode;
41  int slide;
42  int w, h;
44 
46  int x;
47  int prev_y[4];
48  int first[4];
49  float *values[4];
50  int values_size[4];
51  int nb_values;
52  int64_t prev_pts;
54 
55 #define OFFSET(x) offsetof(DrawGraphContext, x)
56 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
57 
58 static const AVOption drawgraph_options[] = {
59  { "m1", "set 1st metadata key", OFFSET(key[0]), AV_OPT_TYPE_STRING, {.str=""}, 0, 0, FLAGS },
60  { "fg1", "set 1st foreground color expression", OFFSET(fg_str[0]), AV_OPT_TYPE_STRING, {.str="0xffff0000"}, 0, 0, FLAGS },
61  { "m2", "set 2nd metadata key", OFFSET(key[1]), AV_OPT_TYPE_STRING, {.str=""}, 0, 0, FLAGS },
62  { "fg2", "set 2nd foreground color expression", OFFSET(fg_str[1]), AV_OPT_TYPE_STRING, {.str="0xff00ff00"}, 0, 0, FLAGS },
63  { "m3", "set 3rd metadata key", OFFSET(key[2]), AV_OPT_TYPE_STRING, {.str=""}, 0, 0, FLAGS },
64  { "fg3", "set 3rd foreground color expression", OFFSET(fg_str[2]), AV_OPT_TYPE_STRING, {.str="0xffff00ff"}, 0, 0, FLAGS },
65  { "m4", "set 4th metadata key", OFFSET(key[3]), AV_OPT_TYPE_STRING, {.str=""}, 0, 0, FLAGS },
66  { "fg4", "set 4th foreground color expression", OFFSET(fg_str[3]), AV_OPT_TYPE_STRING, {.str="0xffffff00"}, 0, 0, FLAGS },
67  { "bg", "set background color", OFFSET(bg), AV_OPT_TYPE_COLOR, {.str="white"}, 0, 0, FLAGS },
68  { "min", "set minimal value", OFFSET(min), AV_OPT_TYPE_FLOAT, {.dbl=-1.}, INT_MIN, INT_MAX, FLAGS },
69  { "max", "set maximal value", OFFSET(max), AV_OPT_TYPE_FLOAT, {.dbl=1.}, INT_MIN, INT_MAX, FLAGS },
70  { "mode", "set graph mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=2}, 0, 2, FLAGS, "mode" },
71  {"bar", "draw bars", OFFSET(mode), AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode"},
72  {"dot", "draw dots", OFFSET(mode), AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode"},
73  {"line", "draw lines", OFFSET(mode), AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "mode"},
74  { "slide", "set slide mode", OFFSET(slide), AV_OPT_TYPE_INT, {.i64=0}, 0, 4, FLAGS, "slide" },
75  {"frame", "draw new frames", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "slide"},
76  {"replace", "replace old columns with new", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "slide"},
77  {"scroll", "scroll from right to left", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "slide"},
78  {"rscroll", "scroll from left to right", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "slide"},
79  {"picture", "display graph in single frame", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, FLAGS, "slide"},
80  { "size", "set graph size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="900x256"}, 0, 0, FLAGS },
81  { "s", "set graph size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="900x256"}, 0, 0, FLAGS },
82  { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS },
83  { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS },
84  { NULL }
85 };
86 
87 static const char *const var_names[] = { "MAX", "MIN", "VAL", NULL };
89 
91 {
92  DrawGraphContext *s = ctx->priv;
93  int ret, i;
94 
95  if (s->max <= s->min) {
96  av_log(ctx, AV_LOG_ERROR, "max is same or lower than min\n");
97  return AVERROR(EINVAL);
98  }
99 
100  for (i = 0; i < 4; i++) {
101  if (s->fg_str[i]) {
102  ret = av_expr_parse(&s->fg_expr[i], s->fg_str[i], var_names,
103  NULL, NULL, NULL, NULL, 0, ctx);
104 
105  if (ret < 0)
106  return ret;
107  }
108  }
109 
110  s->first[0] = s->first[1] = s->first[2] = s->first[3] = 1;
111 
112  if (s->slide == 4) {
113  s->values[0] = av_fast_realloc(NULL, &s->values_size[0], 2000);
114  s->values[1] = av_fast_realloc(NULL, &s->values_size[1], 2000);
115  s->values[2] = av_fast_realloc(NULL, &s->values_size[2], 2000);
116  s->values[3] = av_fast_realloc(NULL, &s->values_size[3], 2000);
117 
118  if (!s->values[0] || !s->values[1] ||
119  !s->values[2] || !s->values[3]) {
120  return AVERROR(ENOMEM);
121  }
122  }
123 
124  return 0;
125 }
126 
128 {
129  AVFilterLink *outlink = ctx->outputs[0];
130  static const enum AVPixelFormat pix_fmts[] = {
133  };
134  int ret;
135 
136  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
137  if ((ret = ff_formats_ref(fmts_list, &outlink->in_formats)) < 0)
138  return ret;
139 
140  return 0;
141 }
142 
144 {
145  int i, j;
146  int bg = AV_RN32(s->bg);
147 
148  for (i = 0; i < out->height; i++)
149  for (j = 0; j < out->width; j++)
150  AV_WN32(out->data[0] + i * out->linesize[0] + j * 4, bg);
151 }
152 
153 static inline void draw_dot(int fg, int x, int y, AVFrame *out)
154 {
155  AV_WN32(out->data[0] + y * out->linesize[0] + x * 4, fg);
156 }
157 
159 {
160  AVFilterContext *ctx = inlink->dst;
161  DrawGraphContext *s = ctx->priv;
162  AVFilterLink *outlink = ctx->outputs[0];
163  AVDictionary *metadata;
165  AVFrame *out = s->out;
166  AVFrame *clone = NULL;
167  int64_t in_pts, out_pts;
168  int i;
169 
170  if (s->slide == 4 && s->nb_values >= s->values_size[0] / sizeof(float)) {
171  float *ptr;
172 
173  ptr = av_fast_realloc(s->values[0], &s->values_size[0], s->values_size[0] * 2);
174  if (!ptr)
175  return AVERROR(ENOMEM);
176  s->values[0] = ptr;
177 
178  ptr = av_fast_realloc(s->values[1], &s->values_size[1], s->values_size[1] * 2);
179  if (!ptr)
180  return AVERROR(ENOMEM);
181  s->values[1] = ptr;
182 
183  ptr = av_fast_realloc(s->values[2], &s->values_size[2], s->values_size[2] * 2);
184  if (!ptr)
185  return AVERROR(ENOMEM);
186  s->values[2] = ptr;
187 
188  ptr = av_fast_realloc(s->values[3], &s->values_size[3], s->values_size[3] * 2);
189  if (!ptr)
190  return AVERROR(ENOMEM);
191  s->values[3] = ptr;
192  }
193 
194  if (s->slide != 4 || s->nb_values == 0) {
195  if (!s->out || s->out->width != outlink->w ||
196  s->out->height != outlink->h) {
197  av_frame_free(&s->out);
198  s->out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
199  out = s->out;
200  if (!s->out) {
201  av_frame_free(&in);
202  return AVERROR(ENOMEM);
203  }
204 
205  clear_image(s, out, outlink);
206  }
207  av_frame_copy_props(out, in);
208  }
209 
210  metadata = in->metadata;
211 
212  for (i = 0; i < 4; i++) {
213  double values[VAR_VARS_NB];
214  int j, y, x, old;
215  uint32_t fg, bg;
216  float vf;
217 
218  if (s->slide == 4)
219  s->values[i][s->nb_values] = NAN;
220 
221  e = av_dict_get(metadata, s->key[i], NULL, 0);
222  if (!e || !e->value)
223  continue;
224 
225  if (av_sscanf(e->value, "%f", &vf) != 1)
226  continue;
227 
228  vf = av_clipf(vf, s->min, s->max);
229 
230  if (s->slide == 4) {
231  s->values[i][s->nb_values] = vf;
232  continue;
233  }
234 
235  values[VAR_MIN] = s->min;
236  values[VAR_MAX] = s->max;
237  values[VAR_VAL] = vf;
238 
239  fg = av_expr_eval(s->fg_expr[i], values, NULL);
240  bg = AV_RN32(s->bg);
241 
242  if (i == 0 && (s->x >= outlink->w || s->slide == 3)) {
243  if (s->slide == 0 || s->slide == 1)
244  s->x = 0;
245 
246  if (s->slide == 2) {
247  s->x = outlink->w - 1;
248  for (j = 0; j < outlink->h; j++) {
249  memmove(out->data[0] + j * out->linesize[0] ,
250  out->data[0] + j * out->linesize[0] + 4,
251  (outlink->w - 1) * 4);
252  }
253  } else if (s->slide == 3) {
254  s->x = 0;
255  for (j = 0; j < outlink->h; j++) {
256  memmove(out->data[0] + j * out->linesize[0] + 4,
257  out->data[0] + j * out->linesize[0],
258  (outlink->w - 1) * 4);
259  }
260  } else if (s->slide == 0) {
261  clear_image(s, out, outlink);
262  }
263  }
264 
265  x = s->x;
266  y = (outlink->h - 1) * (1 - ((vf - s->min) / (s->max - s->min)));
267 
268  switch (s->mode) {
269  case 0:
270  if (i == 0 && (s->slide > 0))
271  for (j = 0; j < outlink->h; j++)
272  draw_dot(bg, x, j, out);
273 
274  old = AV_RN32(out->data[0] + y * out->linesize[0] + x * 4);
275  for (j = y; j < outlink->h; j++) {
276  if (old != bg &&
277  (AV_RN32(out->data[0] + j * out->linesize[0] + x * 4) != old) ||
278  AV_RN32(out->data[0] + FFMIN(j+1, outlink->h - 1) * out->linesize[0] + x * 4) != old) {
279  draw_dot(fg, x, j, out);
280  break;
281  }
282  draw_dot(fg, x, j, out);
283  }
284  break;
285  case 1:
286  if (i == 0 && (s->slide > 0))
287  for (j = 0; j < outlink->h; j++)
288  draw_dot(bg, x, j, out);
289  draw_dot(fg, x, y, out);
290  break;
291  case 2:
292  if (s->first[i]) {
293  s->first[i] = 0;
294  s->prev_y[i] = y;
295  }
296 
297  if (i == 0 && (s->slide > 0)) {
298  for (j = 0; j < y; j++)
299  draw_dot(bg, x, j, out);
300  for (j = outlink->h - 1; j > y; j--)
301  draw_dot(bg, x, j, out);
302  }
303  if (y <= s->prev_y[i]) {
304  for (j = y; j <= s->prev_y[i]; j++)
305  draw_dot(fg, x, j, out);
306  } else {
307  for (j = s->prev_y[i]; j <= y; j++)
308  draw_dot(fg, x, j, out);
309  }
310  s->prev_y[i] = y;
311  break;
312  }
313  }
314 
315  s->nb_values++;
316  s->x++;
317 
318  in_pts = in->pts;
319 
320  av_frame_free(&in);
321 
322  if (s->slide == 4)
323  return 0;
324 
325  out_pts = av_rescale_q(in_pts, inlink->time_base, outlink->time_base);
326 
327  if (out_pts == s->prev_pts)
328  return 0;
329 
330  clone = av_frame_clone(s->out);
331  if (!clone)
332  return AVERROR(ENOMEM);
333 
334  clone->pts = s->prev_pts = out_pts;
335  return ff_filter_frame(outlink, clone);
336 }
337 
338 static int request_frame(AVFilterLink *outlink)
339 {
340  AVFilterContext *ctx = outlink->src;
341  DrawGraphContext *s = ctx->priv;
342  AVFrame *out = s->out;
343  int ret, i, k, step, l;
344 
345  ret = ff_request_frame(ctx->inputs[0]);
346 
347  if (s->slide == 4 && ret == AVERROR_EOF && s->nb_values > 0) {
348  s->x = l = 0;
349  step = ceil(s->nb_values / (float)s->w);
350 
351  for (k = 0; k < s->nb_values; k++) {
352  for (i = 0; i < 4; i++) {
353  double values[VAR_VARS_NB];
354  int j, y, x, old;
355  uint32_t fg, bg;
356  float vf = s->values[i][k];
357 
358  if (isnan(vf))
359  continue;
360 
361  values[VAR_MIN] = s->min;
362  values[VAR_MAX] = s->max;
363  values[VAR_VAL] = vf;
364 
365  fg = av_expr_eval(s->fg_expr[i], values, NULL);
366  bg = AV_RN32(s->bg);
367 
368  x = s->x;
369  y = (outlink->h - 1) * (1 - ((vf - s->min) / (s->max - s->min)));
370 
371  switch (s->mode) {
372  case 0:
373  old = AV_RN32(out->data[0] + y * out->linesize[0] + x * 4);
374  for (j = y; j < outlink->h; j++) {
375  if (old != bg &&
376  (AV_RN32(out->data[0] + j * out->linesize[0] + x * 4) != old) ||
377  AV_RN32(out->data[0] + FFMIN(j+1, outlink->h - 1) * out->linesize[0] + x * 4) != old) {
378  draw_dot(fg, x, j, out);
379  break;
380  }
381  draw_dot(fg, x, j, out);
382  }
383  break;
384  case 1:
385  draw_dot(fg, x, y, out);
386  break;
387  case 2:
388  if (s->first[i]) {
389  s->first[i] = 0;
390  s->prev_y[i] = y;
391  }
392 
393  if (y <= s->prev_y[i]) {
394  for (j = y; j <= s->prev_y[i]; j++)
395  draw_dot(fg, x, j, out);
396  } else {
397  for (j = s->prev_y[i]; j <= y; j++)
398  draw_dot(fg, x, j, out);
399  }
400  s->prev_y[i] = y;
401  break;
402  }
403  }
404 
405  l++;
406  if (l >= step) {
407  l = 0;
408  s->x++;
409  }
410  }
411 
412  s->nb_values = 0;
413  out->pts = 0;
414  ret = ff_filter_frame(ctx->outputs[0], s->out);
415  }
416 
417  return ret;
418 }
419 
420 static int config_output(AVFilterLink *outlink)
421 {
422  DrawGraphContext *s = outlink->src->priv;
423 
424  outlink->w = s->w;
425  outlink->h = s->h;
426  outlink->sample_aspect_ratio = (AVRational){1,1};
427  outlink->frame_rate = s->frame_rate;
428  outlink->time_base = av_inv_q(outlink->frame_rate);
430 
431  return 0;
432 }
433 
435 {
436  DrawGraphContext *s = ctx->priv;
437  int i;
438 
439  for (i = 0; i < 4; i++)
440  av_expr_free(s->fg_expr[i]);
441 
442  if (s->slide != 4)
443  av_frame_free(&s->out);
444 
445  av_freep(&s->values[0]);
446  av_freep(&s->values[1]);
447  av_freep(&s->values[2]);
448  av_freep(&s->values[3]);
449 }
450 
451 #if CONFIG_DRAWGRAPH_FILTER
452 
453 AVFILTER_DEFINE_CLASS(drawgraph);
454 
455 static const AVFilterPad drawgraph_inputs[] = {
456  {
457  .name = "default",
458  .type = AVMEDIA_TYPE_VIDEO,
459  .filter_frame = filter_frame,
460  },
461  { NULL }
462 };
463 
464 static const AVFilterPad drawgraph_outputs[] = {
465  {
466  .name = "default",
467  .type = AVMEDIA_TYPE_VIDEO,
468  .config_props = config_output,
469  .request_frame = request_frame,
470  },
471  { NULL }
472 };
473 
475  .name = "drawgraph",
476  .description = NULL_IF_CONFIG_SMALL("Draw a graph using input video metadata."),
477  .priv_size = sizeof(DrawGraphContext),
478  .priv_class = &drawgraph_class,
480  .init = init,
481  .uninit = uninit,
482  .inputs = drawgraph_inputs,
483  .outputs = drawgraph_outputs,
484 };
485 
486 #endif // CONFIG_DRAWGRAPH_FILTER
487 
488 #if CONFIG_ADRAWGRAPH_FILTER
489 
490 #define adrawgraph_options drawgraph_options
491 AVFILTER_DEFINE_CLASS(adrawgraph);
492 
493 static const AVFilterPad adrawgraph_inputs[] = {
494  {
495  .name = "default",
496  .type = AVMEDIA_TYPE_AUDIO,
497  .filter_frame = filter_frame,
498  },
499  { NULL }
500 };
501 
502 static const AVFilterPad adrawgraph_outputs[] = {
503  {
504  .name = "default",
505  .type = AVMEDIA_TYPE_VIDEO,
506  .config_props = config_output,
507  .request_frame = request_frame,
508  },
509  { NULL }
510 };
511 
513  .name = "adrawgraph",
514  .description = NULL_IF_CONFIG_SMALL("Draw a graph using input audio metadata."),
515  .priv_size = sizeof(DrawGraphContext),
516  .priv_class = &adrawgraph_class,
518  .init = init,
519  .uninit = uninit,
520  .inputs = adrawgraph_inputs,
521  .outputs = adrawgraph_outputs,
522 };
523 #endif // CONFIG_ADRAWGRAPH_FILTER
#define NULL
Definition: coverity.c:32
static av_cold int init(AVFilterContext *ctx)
Definition: f_drawgraph.c:90
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
static void draw_dot(int fg, int x, int y, AVFrame *out)
Definition: f_drawgraph.c:153
AVOption.
Definition: opt.h:246
AVFrame * out
Definition: f_drawgraph.c:45
Main libavfilter public API header.
static const char *const var_names[]
Definition: f_drawgraph.c:87
AVFilter ff_vf_drawgraph
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition: eval.c:685
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: f_drawgraph.c:158
int values_size[4]
Definition: f_drawgraph.c:50
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
const char * name
Pad name.
Definition: internal.h:60
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1075
static const AVOption drawgraph_options[]
Definition: f_drawgraph.c:58
uint8_t
#define av_cold
Definition: attributes.h:82
AVOptions.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:388
Definition: eval.c:157
static void clear_image(DrawGraphContext *s, AVFrame *out, AVFilterLink *outlink)
Definition: f_drawgraph.c:143
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
char * key[4]
Definition: f_drawgraph.c:35
#define AVERROR_EOF
End of file.
Definition: error.h:55
AVDictionary * metadata
metadata.
Definition: frame.h:581
static av_cold void uninit(AVFilterContext *ctx)
Definition: f_drawgraph.c:434
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:54
static int request_frame(AVFilterLink *outlink)
Definition: f_drawgraph.c:338
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
AVRational frame_rate
Definition: f_drawgraph.c:43
static int config_output(AVFilterLink *outlink)
Definition: f_drawgraph.c:420
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
int width
Definition: frame.h:353
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
float * values[4]
Definition: f_drawgraph.c:49
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
void * priv
private data for use by the filter
Definition: avfilter.h:353
uint8_t bg[4]
Definition: f_drawgraph.c:39
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
Definition: avsscanf.c:962
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
#define NAN
Definition: mathematics.h:64
#define FFMIN(a, b)
Definition: common.h:96
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:439
AVFormatContext * ctx
Definition: movenc.c:48
#define FLAGS
Definition: f_drawgraph.c:56
#define s(width, name)
Definition: cbs_vp9.c:257
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
Definition: mem.c:476
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:541
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
AVFilter ff_avf_adrawgraph
#define OFFSET(x)
Definition: f_drawgraph.c:55
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:336
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:326
AVExpr * fg_expr[4]
Definition: f_drawgraph.c:38
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
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
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
Rational number (pair of numerator and denominator).
Definition: rational.h:58
#define isnan(x)
Definition: libm.h:340
offset must point to AVRational
Definition: opt.h:236
const char * name
Filter name.
Definition: avfilter.h:148
int64_t prev_pts
Definition: f_drawgraph.c:52
offset must point to two consecutive integers
Definition: opt.h:233
#define AV_RN32(p)
Definition: intreadwrite.h:364
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:309
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
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
#define AV_WN32(p, v)
Definition: intreadwrite.h:376
static int query_formats(AVFilterContext *ctx)
Definition: f_drawgraph.c:127
char * value
Definition: dict.h:87
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:766
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:314
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:338
int height
Definition: frame.h:353
char * fg_str[4]
Definition: f_drawgraph.c:37
#define av_freep(p)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:407
internal API functions
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
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
mode
Use these values in ebur128_init (or&#39;ed).
Definition: ebur128.h:83
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:659
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
simple arithmetic expression evaluator