FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_fftfilt.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Arwa Arif <arwaarif1994@gmail.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published
8  * by the Free Software Foundation; either version 2.1 of the License,
9  * 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  * FFT domain filtering.
24  */
25 
26 #include "libavfilter/internal.h"
27 #include "libavutil/common.h"
28 #include "libavutil/imgutils.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/pixdesc.h"
31 #include "libavcodec/avfft.h"
32 #include "libavutil/eval.h"
33 
34 #define MAX_PLANES 4
35 
36 enum EvalMode {
40 };
41 
42 typedef struct FFTFILTContext {
43  const AVClass *class;
44 
45  int eval_mode;
46  int depth;
47  int nb_planes;
50 
61 
62  int dc[MAX_PLANES];
65  double *weight[MAX_PLANES];
66 
68 
69 static const char *const var_names[] = { "X", "Y", "W", "H", "N", NULL };
71 
72 enum { Y = 0, U, V };
73 
74 #define OFFSET(x) offsetof(FFTFILTContext, x)
75 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
76 
77 static const AVOption fftfilt_options[] = {
78  { "dc_Y", "adjust gain in Y plane", OFFSET(dc[Y]), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1000, FLAGS },
79  { "dc_U", "adjust gain in U plane", OFFSET(dc[U]), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1000, FLAGS },
80  { "dc_V", "adjust gain in V plane", OFFSET(dc[V]), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1000, FLAGS },
81  { "weight_Y", "set luminance expression in Y plane", OFFSET(weight_str[Y]), AV_OPT_TYPE_STRING, {.str = "1"}, CHAR_MIN, CHAR_MAX, FLAGS },
82  { "weight_U", "set chrominance expression in U plane", OFFSET(weight_str[U]), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
83  { "weight_V", "set chrominance expression in V plane", OFFSET(weight_str[V]), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
84  { "eval", "specify when to evaluate expressions", OFFSET(eval_mode), AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_INIT}, 0, EVAL_MODE_NB-1, FLAGS, "eval" },
85  { "init", "eval expressions once during initialization", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_INIT}, .flags = FLAGS, .unit = "eval" },
86  { "frame", "eval expressions per-frame", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags = FLAGS, .unit = "eval" },
87  {NULL},
88 };
89 
90 AVFILTER_DEFINE_CLASS(fftfilt);
91 
92 static inline double lum(void *priv, double x, double y, int plane)
93 {
94  FFTFILTContext *s = priv;
95  return s->rdft_vdata[plane][(int)x * s->rdft_vlen[plane] + (int)y];
96 }
97 
98 static double weight_Y(void *priv, double x, double y) { return lum(priv, x, y, Y); }
99 static double weight_U(void *priv, double x, double y) { return lum(priv, x, y, U); }
100 static double weight_V(void *priv, double x, double y) { return lum(priv, x, y, V); }
101 
102 static void copy_rev (FFTSample *dest, int w, int w2)
103 {
104  int i;
105 
106  for (i = w; i < w + (w2-w)/2; i++)
107  dest[i] = dest[2*w - i - 1];
108 
109  for (; i < w2; i++)
110  dest[i] = dest[w2 - i];
111 }
112 
113 /*Horizontal pass - RDFT*/
114 static void rdft_horizontal(FFTFILTContext *s, AVFrame *in, int w, int h, int plane)
115 {
116  int i, j;
117 
118  for (i = 0; i < h; i++) {
119  for (j = 0; j < w; j++)
120  s->rdft_hdata[plane][i * s->rdft_hlen[plane] + j] = *(in->data[plane] + in->linesize[plane] * i + j);
121 
122  copy_rev(s->rdft_hdata[plane] + i * s->rdft_hlen[plane], w, s->rdft_hlen[plane]);
123  }
124 
125  for (i = 0; i < h; i++)
126  av_rdft_calc(s->hrdft[plane], s->rdft_hdata[plane] + i * s->rdft_hlen[plane]);
127 }
128 
129 /*Vertical pass - RDFT*/
130 static void rdft_vertical(FFTFILTContext *s, int h, int plane)
131 {
132  int i, j;
133 
134  for (i = 0; i < s->rdft_hlen[plane]; i++) {
135  for (j = 0; j < h; j++)
136  s->rdft_vdata[plane][i * s->rdft_vlen[plane] + j] =
137  s->rdft_hdata[plane][j * s->rdft_hlen[plane] + i];
138  copy_rev(s->rdft_vdata[plane] + i * s->rdft_vlen[plane], h, s->rdft_vlen[plane]);
139  }
140 
141  for (i = 0; i < s->rdft_hlen[plane]; i++)
142  av_rdft_calc(s->vrdft[plane], s->rdft_vdata[plane] + i * s->rdft_vlen[plane]);
143 }
144 /*Vertical pass - IRDFT*/
145 static void irdft_vertical(FFTFILTContext *s, int h, int plane)
146 {
147  int i, j;
148 
149  for (i = 0; i < s->rdft_hlen[plane]; i++)
150  av_rdft_calc(s->ivrdft[plane], s->rdft_vdata[plane] + i * s->rdft_vlen[plane]);
151 
152  for (i = 0; i < s->rdft_hlen[plane]; i++)
153  for (j = 0; j < h; j++)
154  s->rdft_hdata[plane][j * s->rdft_hlen[plane] + i] =
155  s->rdft_vdata[plane][i * s->rdft_vlen[plane] + j];
156 }
157 
158 /*Horizontal pass - IRDFT*/
159 static void irdft_horizontal(FFTFILTContext *s, AVFrame *out, int w, int h, int plane)
160 {
161  int i, j;
162 
163  for (i = 0; i < h; i++)
164  av_rdft_calc(s->ihrdft[plane], s->rdft_hdata[plane] + i * s->rdft_hlen[plane]);
165 
166  for (i = 0; i < h; i++)
167  for (j = 0; j < w; j++)
168  *(out->data[plane] + out->linesize[plane] * i + j) = av_clip(s->rdft_hdata[plane][i
169  *s->rdft_hlen[plane] + j] * 4 /
170  (s->rdft_hlen[plane] *
171  s->rdft_vlen[plane]), 0, 255);
172 }
173 
175 {
176  FFTFILTContext *s = ctx->priv;
177  int ret = 0, plane;
178 
179  if (!s->dc[U] && !s->dc[V]) {
180  s->dc[U] = s->dc[Y];
181  s->dc[V] = s->dc[Y];
182  } else {
183  if (!s->dc[U]) s->dc[U] = s->dc[V];
184  if (!s->dc[V]) s->dc[V] = s->dc[U];
185  }
186 
187  if (!s->weight_str[U] && !s->weight_str[V]) {
188  s->weight_str[U] = av_strdup(s->weight_str[Y]);
189  s->weight_str[V] = av_strdup(s->weight_str[Y]);
190  } else {
191  if (!s->weight_str[U]) s->weight_str[U] = av_strdup(s->weight_str[V]);
192  if (!s->weight_str[V]) s->weight_str[V] = av_strdup(s->weight_str[U]);
193  }
194 
195  for (plane = 0; plane < 3; plane++) {
196  static double (*p[])(void *, double, double) = { weight_Y, weight_U, weight_V };
197  const char *const func2_names[] = {"weight_Y", "weight_U", "weight_V", NULL };
198  double (*func2[])(void *, double, double) = { weight_Y, weight_U, weight_V, p[plane], NULL };
199 
201  NULL, NULL, func2_names, func2, 0, ctx);
202  if (ret < 0)
203  break;
204  }
205  return ret;
206 }
207 
208 static void do_eval(FFTFILTContext *s, AVFilterLink *inlink, int plane)
209 {
210  double values[VAR_VARS_NB];
211  int i, j;
212 
213  values[VAR_N] = inlink->frame_count_out;
214  values[VAR_W] = s->planewidth[plane];
215  values[VAR_H] = s->planeheight[plane];
216 
217  for (i = 0; i < s->rdft_hlen[plane]; i++) {
218  values[VAR_X] = i;
219  for (j = 0; j < s->rdft_vlen[plane]; j++) {
220  values[VAR_Y] = j;
221  s->weight[plane][i * s->rdft_vlen[plane] + j] =
222  av_expr_eval(s->weight_expr[plane], values, s);
223  }
224  }
225 }
226 
227 static int config_props(AVFilterLink *inlink)
228 {
229  FFTFILTContext *s = inlink->dst->priv;
230  const AVPixFmtDescriptor *desc;
231  int rdft_hbits, rdft_vbits, i, plane;
232 
233  desc = av_pix_fmt_desc_get(inlink->format);
234  s->depth = desc->comp[0].depth;
235  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
236  s->planewidth[0] = s->planewidth[3] = inlink->w;
237  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
238  s->planeheight[0] = s->planeheight[3] = inlink->h;
239 
241 
242  for (i = 0; i < desc->nb_components; i++) {
243  int w = s->planewidth[i];
244  int h = s->planeheight[i];
245 
246  /* RDFT - Array initialization for Horizontal pass*/
247  for (rdft_hbits = 1; 1 << rdft_hbits < w*10/9; rdft_hbits++);
248  s->rdft_hbits[i] = rdft_hbits;
249  s->rdft_hlen[i] = 1 << rdft_hbits;
250  if (!(s->rdft_hdata[i] = av_malloc_array(h, s->rdft_hlen[i] * sizeof(FFTSample))))
251  return AVERROR(ENOMEM);
252 
253  if (!(s->hrdft[i] = av_rdft_init(s->rdft_hbits[i], DFT_R2C)))
254  return AVERROR(ENOMEM);
255  if (!(s->ihrdft[i] = av_rdft_init(s->rdft_hbits[i], IDFT_C2R)))
256  return AVERROR(ENOMEM);
257 
258  /* RDFT - Array initialization for Vertical pass*/
259  for (rdft_vbits = 1; 1 << rdft_vbits < h*10/9; rdft_vbits++);
260  s->rdft_vbits[i] = rdft_vbits;
261  s->rdft_vlen[i] = 1 << rdft_vbits;
262  if (!(s->rdft_vdata[i] = av_malloc_array(s->rdft_hlen[i], s->rdft_vlen[i] * sizeof(FFTSample))))
263  return AVERROR(ENOMEM);
264 
265  if (!(s->vrdft[i] = av_rdft_init(s->rdft_vbits[i], DFT_R2C)))
266  return AVERROR(ENOMEM);
267  if (!(s->ivrdft[i] = av_rdft_init(s->rdft_vbits[i], IDFT_C2R)))
268  return AVERROR(ENOMEM);
269  }
270 
271  /*Luminance value - Array initialization*/
272  for (plane = 0; plane < 3; plane++) {
273  if(!(s->weight[plane] = av_malloc_array(s->rdft_hlen[plane], s->rdft_vlen[plane] * sizeof(double))))
274  return AVERROR(ENOMEM);
275 
276  if (s->eval_mode == EVAL_MODE_INIT)
277  do_eval(s, inlink, plane);
278  }
279  return 0;
280 }
281 
282 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
283 {
284  AVFilterContext *ctx = inlink->dst;
285  AVFilterLink *outlink = inlink->dst->outputs[0];
286  FFTFILTContext *s = ctx->priv;
287  AVFrame *out;
288  int i, j, plane;
289 
290  out = ff_get_video_buffer(outlink, inlink->w, inlink->h);
291  if (!out) {
292  av_frame_free(&in);
293  return AVERROR(ENOMEM);
294  }
295 
296  av_frame_copy_props(out, in);
297 
298  for (plane = 0; plane < s->nb_planes; plane++) {
299  int w = s->planewidth[plane];
300  int h = s->planeheight[plane];
301 
302  if (s->eval_mode == EVAL_MODE_FRAME)
303  do_eval(s, inlink, plane);
304 
305  rdft_horizontal(s, in, w, h, plane);
306  rdft_vertical(s, h, plane);
307 
308  /*Change user defined parameters*/
309  for (i = 0; i < s->rdft_hlen[plane]; i++)
310  for (j = 0; j < s->rdft_vlen[plane]; j++)
311  s->rdft_vdata[plane][i * s->rdft_vlen[plane] + j] *=
312  s->weight[plane][i * s->rdft_vlen[plane] + j];
313 
314  s->rdft_vdata[plane][0] += s->rdft_hlen[plane] * s->rdft_vlen[plane] * s->dc[plane];
315 
316  irdft_vertical(s, h, plane);
317  irdft_horizontal(s, out, w, h, plane);
318  }
319 
320  av_frame_free(&in);
321  return ff_filter_frame(outlink, out);
322 }
323 
325 {
326  FFTFILTContext *s = ctx->priv;
327  int i;
328  for (i = 0; i < MAX_PLANES; i++) {
329  av_free(s->rdft_hdata[i]);
330  av_free(s->rdft_vdata[i]);
331  av_expr_free(s->weight_expr[i]);
332  av_free(s->weight[i]);
333  av_rdft_end(s->hrdft[i]);
334  av_rdft_end(s->ihrdft[i]);
335  av_rdft_end(s->vrdft[i]);
336  av_rdft_end(s->ivrdft[i]);
337  }
338 }
339 
341 {
342  static const enum AVPixelFormat pixel_fmts_fftfilt[] = {
348  };
349 
350  AVFilterFormats *fmts_list = ff_make_format_list(pixel_fmts_fftfilt);
351  if (!fmts_list)
352  return AVERROR(ENOMEM);
353  return ff_set_common_formats(ctx, fmts_list);
354 }
355 
356 static const AVFilterPad fftfilt_inputs[] = {
357  {
358  .name = "default",
359  .type = AVMEDIA_TYPE_VIDEO,
360  .config_props = config_props,
361  .filter_frame = filter_frame,
362  },
363  { NULL }
364 };
365 
366 static const AVFilterPad fftfilt_outputs[] = {
367  {
368  .name = "default",
369  .type = AVMEDIA_TYPE_VIDEO,
370  },
371  { NULL }
372 };
373 
375  .name = "fftfilt",
376  .description = NULL_IF_CONFIG_SMALL("Apply arbitrary expressions to pixels in frequency domain."),
377  .priv_size = sizeof(FFTFILTContext),
378  .priv_class = &fftfilt_class,
379  .inputs = fftfilt_inputs,
380  .outputs = fftfilt_outputs,
382  .init = initialize,
383  .uninit = uninit,
385 };
int plane
Definition: avisynth_c.h:422
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2419
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
AVOption.
Definition: opt.h:246
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
misc image utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2459
const char * desc
Definition: nvenc.c:60
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static void rdft_vertical(FFTFILTContext *s, int h, int plane)
Definition: vf_fftfilt.c:130
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:672
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:92
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
static void irdft_vertical(FFTFILTContext *s, int h, int plane)
Definition: vf_fftfilt.c:145
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
#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:125
RDFTContext * hrdft[MAX_PLANES]
Definition: vf_fftfilt.c:51
const char * name
Pad name.
Definition: internal.h:60
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1151
int planewidth[MAX_PLANES]
Definition: vf_fftfilt.c:48
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
#define av_cold
Definition: attributes.h:82
AVOptions.
size_t rdft_vlen[MAX_PLANES]
Definition: vf_fftfilt.c:58
static void copy_rev(FFTSample *dest, int w, int w2)
Definition: vf_fftfilt.c:102
Definition: eval.c:150
FFTSample * rdft_vdata[MAX_PLANES]
Definition: vf_fftfilt.c:60
static int flags
Definition: log.c:57
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:75
AVFILTER_DEFINE_CLASS(fftfilt)
static const char *const var_names[]
Definition: vf_fftfilt.c:69
static const AVFilterPad fftfilt_inputs[]
Definition: vf_fftfilt.c:356
A filter pad used for either input or output.
Definition: internal.h:54
Definition: vf_fftfilt.c:72
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:568
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
size_t rdft_hlen[MAX_PLANES]
Definition: vf_fftfilt.c:57
#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:163
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
void * priv
private data for use by the filter
Definition: avfilter.h:353
Definition: avfft.h:73
float FFTSample
Definition: avfft.h:35
static double weight_V(void *priv, double x, double y)
Definition: vf_fftfilt.c:100
void av_rdft_calc(RDFTContext *s, FFTSample *data)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
static const AVOption fftfilt_options[]
Definition: vf_fftfilt.c:77
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
int rdft_vbits[MAX_PLANES]
Definition: vf_fftfilt.c:56
char * weight_str[MAX_PLANES]
Definition: vf_fftfilt.c:63
static double lum(void *priv, double x, double y, int plane)
Definition: vf_fftfilt.c:92
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:74
AVFormatContext * ctx
Definition: movenc.c:48
static void irdft_horizontal(FFTFILTContext *s, AVFrame *out, int w, int h, int plane)
Definition: vf_fftfilt.c:159
#define OFFSET(x)
Definition: vf_fftfilt.c:74
#define FLAGS
Definition: vf_fftfilt.c:75
Definition: avfft.h:72
void av_rdft_end(RDFTContext *s)
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:389
EvalMode
Definition: af_volume.h:39
int planeheight[MAX_PLANES]
Definition: vf_fftfilt.c:49
RDFTContext * vrdft[MAX_PLANES]
Definition: vf_fftfilt.c:52
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:379
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:237
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:327
Definition: vf_fftfilt.c:72
static void do_eval(FFTFILTContext *s, AVFilterLink *inlink, int plane)
Definition: vf_fftfilt.c:208
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:232
double * weight[MAX_PLANES]
Definition: vf_fftfilt.c:65
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
FFT functions.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static int config_props(AVFilterLink *inlink)
Definition: vf_fftfilt.c:227
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
static double weight_U(void *priv, double x, double y)
Definition: vf_fftfilt.c:99
const char * name
Filter name.
Definition: avfilter.h:148
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static int query_formats(AVFilterContext *ctx)
Definition: vf_fftfilt.c:340
AVFilter ff_vf_fftfilt
Definition: vf_fftfilt.c:374
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:215
int rdft_hbits[MAX_PLANES]
Definition: vf_fftfilt.c:55
static double weight_Y(void *priv, double x, double y)
Definition: vf_fftfilt.c:98
int
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
Y , 8bpp.
Definition: pixfmt.h:70
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_fftfilt.c:324
common internal and external API header
Definition: vf_fftfilt.c:72
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:76
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_fftfilt.c:282
int dc[MAX_PLANES]
Definition: vf_fftfilt.c:62
AVExpr * weight_expr[MAX_PLANES]
Definition: vf_fftfilt.c:64
#define av_free(p)
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:727
FFTSample * rdft_hdata[MAX_PLANES]
Definition: vf_fftfilt.c:59
A list of supported formats for one end of a filter link.
Definition: formats.h:64
static const AVFilterPad fftfilt_outputs[]
Definition: vf_fftfilt.c:366
An instance of a filter.
Definition: avfilter.h:338
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> dc
RDFTContext * ihrdft[MAX_PLANES]
Definition: vf_fftfilt.c:53
FILE * out
Definition: movenc.c:54
static av_cold int initialize(AVFilterContext *ctx)
Definition: vf_fftfilt.c:174
static void rdft_horizontal(FFTFILTContext *s, AVFrame *in, int w, int h, int plane)
Definition: vf_fftfilt.c:114
#define av_malloc_array(a, b)
internal API functions
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:603
RDFTContext * ivrdft[MAX_PLANES]
Definition: vf_fftfilt.c:54
simple arithmetic expression evaluator
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
#define MAX_PLANES
Definition: vf_fftfilt.c:34