FFmpeg  4.4.9
vf_fftfilt.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Arwa Arif <arwaarif1994@gmail.com>
3  * Copyright (c) 2017 Paul B Mahol
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published
9  * by the Free Software Foundation; either version 2.1 of the License,
10  * or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * FFT domain filtering.
25  */
26 
27 #include "libavfilter/internal.h"
28 #include "libavutil/common.h"
29 #include "libavutil/imgutils.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavcodec/avfft.h"
33 #include "libavutil/eval.h"
34 
35 #define MAX_PLANES 4
36 
37 enum EvalMode {
41 };
42 
43 typedef struct FFTFILTContext {
44  const AVClass *class;
45 
46  int eval_mode;
47  int depth;
48  int nb_planes;
51 
62 
63  int dc[MAX_PLANES];
66  double *weight[MAX_PLANES];
67 
68  void (*rdft_horizontal)(struct FFTFILTContext *s, AVFrame *in, int w, int h, int plane);
69  void (*irdft_horizontal)(struct FFTFILTContext *s, AVFrame *out, int w, int h, int plane);
71 
72 static const char *const var_names[] = { "X", "Y", "W", "H", "N", NULL };
74 
75 enum { Y = 0, U, V };
76 
77 #define OFFSET(x) offsetof(FFTFILTContext, x)
78 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
79 
80 static const AVOption fftfilt_options[] = {
81  { "dc_Y", "adjust gain in Y plane", OFFSET(dc[Y]), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1000, FLAGS },
82  { "dc_U", "adjust gain in U plane", OFFSET(dc[U]), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1000, FLAGS },
83  { "dc_V", "adjust gain in V plane", OFFSET(dc[V]), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1000, FLAGS },
84  { "weight_Y", "set luminance expression in Y plane", OFFSET(weight_str[Y]), AV_OPT_TYPE_STRING, {.str = "1"}, 0, 0, FLAGS },
85  { "weight_U", "set chrominance expression in U plane", OFFSET(weight_str[U]), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
86  { "weight_V", "set chrominance expression in V plane", OFFSET(weight_str[V]), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
87  { "eval", "specify when to evaluate expressions", OFFSET(eval_mode), AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_INIT}, 0, EVAL_MODE_NB-1, FLAGS, "eval" },
88  { "init", "eval expressions once during initialization", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_INIT}, .flags = FLAGS, .unit = "eval" },
89  { "frame", "eval expressions per-frame", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags = FLAGS, .unit = "eval" },
90  {NULL},
91 };
92 
94 
95 static inline double lum(void *priv, double x, double y, int plane)
96 {
97  FFTFILTContext *s = priv;
98  if (!s->rdft_vdata[plane])
99  return 0;
100  return s->rdft_vdata[plane][((int)x & (s->rdft_hlen[plane] - 1)) * s->rdft_vlen[plane] +
101  ((int)y & (s->rdft_vlen[plane] - 1))];
102 }
103 
104 static double weight_Y(void *priv, double x, double y) { return lum(priv, x, y, Y); }
105 static double weight_U(void *priv, double x, double y) { return lum(priv, x, y, U); }
106 static double weight_V(void *priv, double x, double y) { return lum(priv, x, y, V); }
107 
108 static void copy_rev (FFTSample *dest, int w, int w2)
109 {
110  int i;
111 
112  for (i = w; i < w + (w2-w)/2; i++)
113  dest[i] = dest[2*w - i - 1];
114 
115  for (; i < w2; i++)
116  dest[i] = dest[w2 - i];
117 }
118 
119 /*Horizontal pass - RDFT*/
120 static void rdft_horizontal8(FFTFILTContext *s, AVFrame *in, int w, int h, int plane)
121 {
122  int i, j;
123 
124  for (i = 0; i < h; i++) {
125  for (j = 0; j < w; j++)
126  s->rdft_hdata[plane][i * s->rdft_hlen[plane] + j] = *(in->data[plane] + in->linesize[plane] * i + j);
127 
128  copy_rev(s->rdft_hdata[plane] + i * s->rdft_hlen[plane], w, s->rdft_hlen[plane]);
129  }
130 
131  for (i = 0; i < h; i++)
132  av_rdft_calc(s->hrdft[plane], s->rdft_hdata[plane] + i * s->rdft_hlen[plane]);
133 }
134 
135 static void rdft_horizontal16(FFTFILTContext *s, AVFrame *in, int w, int h, int plane)
136 {
137  const uint16_t *src = (const uint16_t *)in->data[plane];
138  int linesize = in->linesize[plane] / 2;
139  int i, j;
140 
141  for (i = 0; i < h; i++) {
142  for (j = 0; j < w; j++)
143  s->rdft_hdata[plane][i * s->rdft_hlen[plane] + j] = *(src + linesize * i + j);
144 
145  copy_rev(s->rdft_hdata[plane] + i * s->rdft_hlen[plane], w, s->rdft_hlen[plane]);
146  }
147 
148  for (i = 0; i < h; i++)
149  av_rdft_calc(s->hrdft[plane], s->rdft_hdata[plane] + i * s->rdft_hlen[plane]);
150 }
151 
152 /*Vertical pass - RDFT*/
153 static void rdft_vertical(FFTFILTContext *s, int h, int plane)
154 {
155  int i, j;
156 
157  for (i = 0; i < s->rdft_hlen[plane]; i++) {
158  for (j = 0; j < h; j++)
159  s->rdft_vdata[plane][i * s->rdft_vlen[plane] + j] =
160  s->rdft_hdata[plane][j * s->rdft_hlen[plane] + i];
161  copy_rev(s->rdft_vdata[plane] + i * s->rdft_vlen[plane], h, s->rdft_vlen[plane]);
162  }
163 
164  for (i = 0; i < s->rdft_hlen[plane]; i++)
165  av_rdft_calc(s->vrdft[plane], s->rdft_vdata[plane] + i * s->rdft_vlen[plane]);
166 }
167 /*Vertical pass - IRDFT*/
168 static void irdft_vertical(FFTFILTContext *s, int h, int plane)
169 {
170  int i, j;
171 
172  for (i = 0; i < s->rdft_hlen[plane]; i++)
173  av_rdft_calc(s->ivrdft[plane], s->rdft_vdata[plane] + i * s->rdft_vlen[plane]);
174 
175  for (i = 0; i < s->rdft_hlen[plane]; i++)
176  for (j = 0; j < h; j++)
177  s->rdft_hdata[plane][j * s->rdft_hlen[plane] + i] =
178  s->rdft_vdata[plane][i * s->rdft_vlen[plane] + j];
179 }
180 
181 /*Horizontal pass - IRDFT*/
182 static void irdft_horizontal8(FFTFILTContext *s, AVFrame *out, int w, int h, int plane)
183 {
184  int i, j;
185 
186  for (i = 0; i < h; i++)
187  av_rdft_calc(s->ihrdft[plane], s->rdft_hdata[plane] + i * s->rdft_hlen[plane]);
188 
189  for (i = 0; i < h; i++)
190  for (j = 0; j < w; j++)
191  *(out->data[plane] + out->linesize[plane] * i + j) = av_clip(s->rdft_hdata[plane][i
192  *s->rdft_hlen[plane] + j] * 4 /
193  (s->rdft_hlen[plane] *
194  s->rdft_vlen[plane]), 0, 255);
195 }
196 
197 static void irdft_horizontal16(FFTFILTContext *s, AVFrame *out, int w, int h, int plane)
198 {
199  uint16_t *dst = (uint16_t *)out->data[plane];
200  int linesize = out->linesize[plane] / 2;
201  int max = (1 << s->depth) - 1;
202  int i, j;
203 
204  for (i = 0; i < h; i++)
205  av_rdft_calc(s->ihrdft[plane], s->rdft_hdata[plane] + i * s->rdft_hlen[plane]);
206 
207  for (i = 0; i < h; i++)
208  for (j = 0; j < w; j++)
209  *(dst + linesize * i + j) = av_clip(s->rdft_hdata[plane][i
210  *s->rdft_hlen[plane] + j] * 4 /
211  (s->rdft_hlen[plane] *
212  s->rdft_vlen[plane]), 0, max);
213 }
214 
216 {
217  FFTFILTContext *s = ctx->priv;
218  int ret = 0, plane;
219 
220  if (!s->dc[U] && !s->dc[V]) {
221  s->dc[U] = s->dc[Y];
222  s->dc[V] = s->dc[Y];
223  } else {
224  if (!s->dc[U]) s->dc[U] = s->dc[V];
225  if (!s->dc[V]) s->dc[V] = s->dc[U];
226  }
227 
228  if (!s->weight_str[U] && !s->weight_str[V]) {
229  s->weight_str[U] = av_strdup(s->weight_str[Y]);
230  s->weight_str[V] = av_strdup(s->weight_str[Y]);
231  } else {
232  if (!s->weight_str[U]) s->weight_str[U] = av_strdup(s->weight_str[V]);
233  if (!s->weight_str[V]) s->weight_str[V] = av_strdup(s->weight_str[U]);
234  }
235 
236  for (plane = 0; plane < 3; plane++) {
237  static double (*p[])(void *, double, double) = { weight_Y, weight_U, weight_V };
238  const char *const func2_names[] = {"weight_Y", "weight_U", "weight_V", NULL };
239  double (*func2[])(void *, double, double) = { weight_Y, weight_U, weight_V, p[plane], NULL };
240 
241  ret = av_expr_parse(&s->weight_expr[plane], s->weight_str[plane], var_names,
242  NULL, NULL, func2_names, func2, 0, ctx);
243  if (ret < 0)
244  break;
245  }
246  return ret;
247 }
248 
249 static void do_eval(FFTFILTContext *s, AVFilterLink *inlink, int plane)
250 {
251  double values[VAR_VARS_NB];
252  int i, j;
253 
254  values[VAR_N] = inlink->frame_count_out;
255  values[VAR_W] = s->planewidth[plane];
256  values[VAR_H] = s->planeheight[plane];
257 
258  for (i = 0; i < s->rdft_hlen[plane]; i++) {
259  values[VAR_X] = i;
260  for (j = 0; j < s->rdft_vlen[plane]; j++) {
261  values[VAR_Y] = j;
262  s->weight[plane][i * s->rdft_vlen[plane] + j] =
263  av_expr_eval(s->weight_expr[plane], values, s);
264  }
265  }
266 }
267 
268 static int config_props(AVFilterLink *inlink)
269 {
270  FFTFILTContext *s = inlink->dst->priv;
271  const AVPixFmtDescriptor *desc;
272  int rdft_hbits, rdft_vbits, i, plane;
273 
274  desc = av_pix_fmt_desc_get(inlink->format);
275  s->depth = desc->comp[0].depth;
276  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
277  s->planewidth[0] = s->planewidth[3] = inlink->w;
278  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
279  s->planeheight[0] = s->planeheight[3] = inlink->h;
280 
281  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
282 
283  for (i = 0; i < desc->nb_components; i++) {
284  int w = s->planewidth[i];
285  int h = s->planeheight[i];
286 
287  /* RDFT - Array initialization for Horizontal pass*/
288  for (rdft_hbits = 1; 1 << rdft_hbits < w*10/9; rdft_hbits++);
289  s->rdft_hbits[i] = rdft_hbits;
290  s->rdft_hlen[i] = 1 << rdft_hbits;
291  if (!(s->rdft_hdata[i] = av_malloc_array(h, s->rdft_hlen[i] * sizeof(FFTSample))))
292  return AVERROR(ENOMEM);
293 
294  if (!(s->hrdft[i] = av_rdft_init(s->rdft_hbits[i], DFT_R2C)))
295  return AVERROR(ENOMEM);
296  if (!(s->ihrdft[i] = av_rdft_init(s->rdft_hbits[i], IDFT_C2R)))
297  return AVERROR(ENOMEM);
298 
299  /* RDFT - Array initialization for Vertical pass*/
300  for (rdft_vbits = 1; 1 << rdft_vbits < h*10/9; rdft_vbits++);
301  s->rdft_vbits[i] = rdft_vbits;
302  s->rdft_vlen[i] = 1 << rdft_vbits;
303  if (!(s->rdft_vdata[i] = av_malloc_array(s->rdft_hlen[i], s->rdft_vlen[i] * sizeof(FFTSample))))
304  return AVERROR(ENOMEM);
305 
306  if (!(s->vrdft[i] = av_rdft_init(s->rdft_vbits[i], DFT_R2C)))
307  return AVERROR(ENOMEM);
308  if (!(s->ivrdft[i] = av_rdft_init(s->rdft_vbits[i], IDFT_C2R)))
309  return AVERROR(ENOMEM);
310  }
311 
312  /*Luminance value - Array initialization*/
313  for (plane = 0; plane < 3; plane++) {
314  if(!(s->weight[plane] = av_malloc_array(s->rdft_hlen[plane], s->rdft_vlen[plane] * sizeof(double))))
315  return AVERROR(ENOMEM);
316 
317  if (s->eval_mode == EVAL_MODE_INIT)
318  do_eval(s, inlink, plane);
319  }
320 
321  if (s->depth <= 8) {
322  s->rdft_horizontal = rdft_horizontal8;
323  s->irdft_horizontal = irdft_horizontal8;
324  } else if (s->depth > 8) {
325  s->rdft_horizontal = rdft_horizontal16;
326  s->irdft_horizontal = irdft_horizontal16;
327  } else {
328  return AVERROR_BUG;
329  }
330  return 0;
331 }
332 
333 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
334 {
335  AVFilterContext *ctx = inlink->dst;
336  AVFilterLink *outlink = inlink->dst->outputs[0];
337  FFTFILTContext *s = ctx->priv;
338  AVFrame *out;
339  int i, j, plane;
340 
341  out = ff_get_video_buffer(outlink, inlink->w, inlink->h);
342  if (!out) {
343  av_frame_free(&in);
344  return AVERROR(ENOMEM);
345  }
346 
348 
349  for (plane = 0; plane < s->nb_planes; plane++) {
350  int w = s->planewidth[plane];
351  int h = s->planeheight[plane];
352 
353  if (s->eval_mode == EVAL_MODE_FRAME)
354  do_eval(s, inlink, plane);
355 
356  s->rdft_horizontal(s, in, w, h, plane);
357  rdft_vertical(s, h, plane);
358 
359  /*Change user defined parameters*/
360  for (i = 0; i < s->rdft_hlen[plane]; i++)
361  for (j = 0; j < s->rdft_vlen[plane]; j++)
362  s->rdft_vdata[plane][i * s->rdft_vlen[plane] + j] *=
363  s->weight[plane][i * s->rdft_vlen[plane] + j];
364 
365  s->rdft_vdata[plane][0] += s->rdft_hlen[plane] * s->rdft_vlen[plane] * s->dc[plane];
366 
367  irdft_vertical(s, h, plane);
368  s->irdft_horizontal(s, out, w, h, plane);
369  }
370 
371  av_frame_free(&in);
372  return ff_filter_frame(outlink, out);
373 }
374 
376 {
377  FFTFILTContext *s = ctx->priv;
378  int i;
379  for (i = 0; i < MAX_PLANES; i++) {
380  av_free(s->rdft_hdata[i]);
381  av_free(s->rdft_vdata[i]);
382  av_expr_free(s->weight_expr[i]);
383  av_free(s->weight[i]);
384  av_rdft_end(s->hrdft[i]);
385  av_rdft_end(s->ihrdft[i]);
386  av_rdft_end(s->vrdft[i]);
387  av_rdft_end(s->ivrdft[i]);
388  }
389 }
390 
392 {
393  static const enum AVPixelFormat pixel_fmts_fftfilt[] = {
408  };
409 
410  AVFilterFormats *fmts_list = ff_make_format_list(pixel_fmts_fftfilt);
411  if (!fmts_list)
412  return AVERROR(ENOMEM);
413  return ff_set_common_formats(ctx, fmts_list);
414 }
415 
416 static const AVFilterPad fftfilt_inputs[] = {
417  {
418  .name = "default",
419  .type = AVMEDIA_TYPE_VIDEO,
420  .config_props = config_props,
421  .filter_frame = filter_frame,
422  },
423  { NULL }
424 };
425 
426 static const AVFilterPad fftfilt_outputs[] = {
427  {
428  .name = "default",
429  .type = AVMEDIA_TYPE_VIDEO,
430  },
431  { NULL }
432 };
433 
435  .name = "fftfilt",
436  .description = NULL_IF_CONFIG_SMALL("Apply arbitrary expressions to pixels in frequency domain."),
437  .priv_size = sizeof(FFTFILTContext),
438  .priv_class = &fftfilt_class,
442  .init = initialize,
443  .uninit = uninit,
445 };
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static double(*const func2[])(void *, double, double)
Definition: af_afftfilt.c:121
static const char *const func2_names[]
Definition: af_afftfilt.c:120
EvalMode
Definition: af_volume.h:39
#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-> dc
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
FFT functions.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1099
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
#define av_clip
Definition: common.h:122
#define NULL
Definition: coverity.c:32
#define max(a, b)
Definition: cuda_runtime.h:33
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:339
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:781
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:700
simple arithmetic expression evaluator
int
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_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
void av_rdft_calc(RDFTContext *s, FFTSample *data)
void av_rdft_end(RDFTContext *s)
float FFTSample
Definition: avfft.h:35
@ DFT_R2C
Definition: avfft.h:72
@ IDFT_C2R
Definition: avfft.h:73
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:126
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
#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
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:253
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
for(j=16;j >0;--j)
misc image utilities
int i
Definition: input.c:407
internal API functions
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
const char * desc
Definition: libsvtav1.c:83
uint8_t w
Definition: llviddspenc.c:39
AVOptions.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2613
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:410
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:406
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:398
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:397
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:403
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:404
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:396
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:407
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:408
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:411
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:409
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:412
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
typedef void(RENAME(mix_any_func_type))
Describe the class of an AVClass context structure.
Definition: log.h:67
Definition: eval.c:159
An instance of a filter.
Definition: avfilter.h:341
void * priv
private data for use by the filter
Definition: avfilter.h:356
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
AVOption.
Definition: opt.h:248
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
int planewidth[MAX_PLANES]
Definition: vf_fftfilt.c:49
RDFTContext * vrdft[MAX_PLANES]
Definition: vf_fftfilt.c:53
int planeheight[MAX_PLANES]
Definition: vf_fftfilt.c:50
int rdft_vbits[MAX_PLANES]
Definition: vf_fftfilt.c:57
int dc[MAX_PLANES]
Definition: vf_fftfilt.c:63
void(* irdft_horizontal)(struct FFTFILTContext *s, AVFrame *out, int w, int h, int plane)
Definition: vf_fftfilt.c:69
char * weight_str[MAX_PLANES]
Definition: vf_fftfilt.c:64
size_t rdft_hlen[MAX_PLANES]
Definition: vf_fftfilt.c:58
size_t rdft_vlen[MAX_PLANES]
Definition: vf_fftfilt.c:59
FFTSample * rdft_hdata[MAX_PLANES]
Definition: vf_fftfilt.c:60
RDFTContext * ihrdft[MAX_PLANES]
Definition: vf_fftfilt.c:54
double * weight[MAX_PLANES]
Definition: vf_fftfilt.c:66
RDFTContext * ivrdft[MAX_PLANES]
Definition: vf_fftfilt.c:55
RDFTContext * hrdft[MAX_PLANES]
Definition: vf_fftfilt.c:52
AVExpr * weight_expr[MAX_PLANES]
Definition: vf_fftfilt.c:65
FFTSample * rdft_vdata[MAX_PLANES]
Definition: vf_fftfilt.c:61
int rdft_hbits[MAX_PLANES]
Definition: vf_fftfilt.c:56
void(* rdft_horizontal)(struct FFTFILTContext *s, AVFrame *in, int w, int h, int plane)
Definition: vf_fftfilt.c:68
#define av_free(p)
#define av_malloc_array(a, b)
#define src
Definition: vp8dsp.c:255
FILE * out
Definition: movenc.c:54
AVFormatContext * ctx
Definition: movenc.c:48
static const AVFilterPad fftfilt_outputs[]
Definition: vf_fftfilt.c:426
static void copy_rev(FFTSample *dest, int w, int w2)
Definition: vf_fftfilt.c:108
static void do_eval(FFTFILTContext *s, AVFilterLink *inlink, int plane)
Definition: vf_fftfilt.c:249
static void rdft_horizontal16(FFTFILTContext *s, AVFrame *in, int w, int h, int plane)
Definition: vf_fftfilt.c:135
static av_cold int initialize(AVFilterContext *ctx)
Definition: vf_fftfilt.c:215
static double weight_Y(void *priv, double x, double y)
Definition: vf_fftfilt.c:104
static void rdft_horizontal8(FFTFILTContext *s, AVFrame *in, int w, int h, int plane)
Definition: vf_fftfilt.c:120
static void irdft_horizontal8(FFTFILTContext *s, AVFrame *out, int w, int h, int plane)
Definition: vf_fftfilt.c:182
#define MAX_PLANES
Definition: vf_fftfilt.c:35
static const AVFilterPad fftfilt_inputs[]
Definition: vf_fftfilt.c:416
static int query_formats(AVFilterContext *ctx)
Definition: vf_fftfilt.c:391
static double weight_U(void *priv, double x, double y)
Definition: vf_fftfilt.c:105
#define FLAGS
Definition: vf_fftfilt.c:78
static double weight_V(void *priv, double x, double y)
Definition: vf_fftfilt.c:106
static void irdft_vertical(FFTFILTContext *s, int h, int plane)
Definition: vf_fftfilt.c:168
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_fftfilt.c:333
AVFILTER_DEFINE_CLASS(fftfilt)
@ EVAL_MODE_NB
Definition: vf_fftfilt.c:40
@ EVAL_MODE_FRAME
Definition: vf_fftfilt.c:39
@ EVAL_MODE_INIT
Definition: vf_fftfilt.c:38
@ VAR_H
Definition: vf_fftfilt.c:73
@ VAR_N
Definition: vf_fftfilt.c:73
@ VAR_W
Definition: vf_fftfilt.c:73
@ VAR_VARS_NB
Definition: vf_fftfilt.c:73
@ VAR_X
Definition: vf_fftfilt.c:73
@ VAR_Y
Definition: vf_fftfilt.c:73
static void rdft_vertical(FFTFILTContext *s, int h, int plane)
Definition: vf_fftfilt.c:153
static int config_props(AVFilterLink *inlink)
Definition: vf_fftfilt.c:268
static const char *const var_names[]
Definition: vf_fftfilt.c:72
static const AVOption fftfilt_options[]
Definition: vf_fftfilt.c:80
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_fftfilt.c:375
static void irdft_horizontal16(FFTFILTContext *s, AVFrame *out, int w, int h, int plane)
Definition: vf_fftfilt.c:197
#define OFFSET(x)
Definition: vf_fftfilt.c:77
AVFilter ff_vf_fftfilt
Definition: vf_fftfilt.c:434
@ V
Definition: vf_fftfilt.c:75
@ Y
Definition: vf_fftfilt.c:75
@ U
Definition: vf_fftfilt.c:75
static double lum(void *priv, double x, double y, int plane)
Definition: vf_fftfilt.c:95
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