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 typedef struct {
37  const AVClass *class;
38 
40  int rdft_hbits[MAX_PLANES];
41  int rdft_vbits[MAX_PLANES];
42  size_t rdft_hlen[MAX_PLANES];
43  size_t rdft_vlen[MAX_PLANES];
44  FFTSample *rdft_hdata[MAX_PLANES];
45  FFTSample *rdft_vdata[MAX_PLANES];
46 
47  int dc[MAX_PLANES];
48  char *weight_str[MAX_PLANES];
49  AVExpr *weight_expr[MAX_PLANES];
50  double *weight[MAX_PLANES];
51 
53 
54 static const char *const var_names[] = { "X", "Y", "W", "H", NULL };
56 
57 enum { Y = 0, U, V };
58 
59 #define OFFSET(x) offsetof(FFTFILTContext, x)
60 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
61 
62 static const AVOption fftfilt_options[] = {
63  { "dc_Y", "adjust gain in Y plane", OFFSET(dc[Y]), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1000, FLAGS },
64  { "dc_U", "adjust gain in U plane", OFFSET(dc[U]), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1000, FLAGS },
65  { "dc_V", "adjust gain in V plane", OFFSET(dc[V]), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1000, FLAGS },
66  { "weight_Y", "set luminance expression in Y plane", OFFSET(weight_str[Y]), AV_OPT_TYPE_STRING, {.str = "1"}, CHAR_MIN, CHAR_MAX, FLAGS },
67  { "weight_U", "set chrominance expression in U plane", OFFSET(weight_str[U]), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
68  { "weight_V", "set chrominance expression in V plane", OFFSET(weight_str[V]), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
69  {NULL},
70 };
71 
72 AVFILTER_DEFINE_CLASS(fftfilt);
73 
74 static inline double lum(void *priv, double x, double y, int plane)
75 {
76  FFTFILTContext *fftfilt = priv;
77  return fftfilt->rdft_vdata[plane][(int)x * fftfilt->rdft_vlen[plane] + (int)y];
78 }
79 
80 static double weight_Y(void *priv, double x, double y) { return lum(priv, x, y, Y); }
81 static double weight_U(void *priv, double x, double y) { return lum(priv, x, y, U); }
82 static double weight_V(void *priv, double x, double y) { return lum(priv, x, y, V); }
83 
84 static void copy_rev (FFTSample *dest, int w, int w2)
85 {
86  int i;
87 
88  for (i = w; i < w + (w2-w)/2; i++)
89  dest[i] = dest[2*w - i - 1];
90 
91  for (; i < w2; i++)
92  dest[i] = dest[w2 - i];
93 }
94 
95 /*Horizontal pass - RDFT*/
96 static void rdft_horizontal(FFTFILTContext *fftfilt, AVFrame *in, int w, int h, int plane)
97 {
98  int i, j;
99  fftfilt->rdft = av_rdft_init(fftfilt->rdft_hbits[plane], DFT_R2C);
100 
101  for (i = 0; i < h; i++) {
102  for (j = 0; j < w; j++)
103  fftfilt->rdft_hdata[plane][i * fftfilt->rdft_hlen[plane] + j] = *(in->data[plane] + in->linesize[plane] * i + j);
104 
105  copy_rev(fftfilt->rdft_hdata[plane] + i * fftfilt->rdft_hlen[plane], w, fftfilt->rdft_hlen[plane]);
106  }
107 
108  for (i = 0; i < h; i++)
109  av_rdft_calc(fftfilt->rdft, fftfilt->rdft_hdata[plane] + i * fftfilt->rdft_hlen[plane]);
110 
111  av_rdft_end(fftfilt->rdft);
112 }
113 
114 /*Vertical pass - RDFT*/
115 static void rdft_vertical(FFTFILTContext *fftfilt, int h, int plane)
116 {
117  int i, j;
118  fftfilt->rdft = av_rdft_init(fftfilt->rdft_vbits[plane], DFT_R2C);
119 
120  for (i = 0; i < fftfilt->rdft_hlen[plane]; i++) {
121  for (j = 0; j < h; j++)
122  fftfilt->rdft_vdata[plane][i * fftfilt->rdft_vlen[plane] + j] =
123  fftfilt->rdft_hdata[plane][j * fftfilt->rdft_hlen[plane] + i];
124  copy_rev(fftfilt->rdft_vdata[plane] + i * fftfilt->rdft_vlen[plane], h, fftfilt->rdft_vlen[plane]);
125  }
126 
127  for (i = 0; i < fftfilt->rdft_hlen[plane]; i++)
128  av_rdft_calc(fftfilt->rdft, fftfilt->rdft_vdata[plane] + i * fftfilt->rdft_vlen[plane]);
129 
130  av_rdft_end(fftfilt->rdft);
131 }
132 /*Vertical pass - IRDFT*/
133 static void irdft_vertical(FFTFILTContext *fftfilt, int h, int plane)
134 {
135  int i, j;
136  fftfilt->rdft = av_rdft_init(fftfilt->rdft_vbits[plane], IDFT_C2R);
137  for (i = 0; i < fftfilt->rdft_hlen[plane]; i++)
138  av_rdft_calc(fftfilt->rdft, fftfilt->rdft_vdata[plane] + i * fftfilt->rdft_vlen[plane]);
139 
140  for (i = 0; i < fftfilt->rdft_hlen[plane]; i++)
141  for (j = 0; j < h; j++)
142  fftfilt->rdft_hdata[plane][j * fftfilt->rdft_hlen[plane] + i] =
143  fftfilt->rdft_vdata[plane][i * fftfilt->rdft_vlen[plane] + j];
144 
145  av_rdft_end(fftfilt->rdft);
146 }
147 
148 /*Horizontal pass - IRDFT*/
149 static void irdft_horizontal(FFTFILTContext *fftfilt, AVFrame *out, int w, int h, int plane)
150 {
151  int i, j;
152  fftfilt->rdft = av_rdft_init(fftfilt->rdft_hbits[plane], IDFT_C2R);
153  for (i = 0; i < h; i++)
154  av_rdft_calc(fftfilt->rdft, fftfilt->rdft_hdata[plane] + i * fftfilt->rdft_hlen[plane]);
155 
156  for (i = 0; i < h; i++)
157  for (j = 0; j < w; j++)
158  *(out->data[plane] + out->linesize[plane] * i + j) = av_clip(fftfilt->rdft_hdata[plane][i
159  *fftfilt->rdft_hlen[plane] + j] * 4 /
160  (fftfilt->rdft_hlen[plane] *
161  fftfilt->rdft_vlen[plane]), 0, 255);
162 
163  av_rdft_end(fftfilt->rdft);
164 }
165 
167 {
168  FFTFILTContext *fftfilt = ctx->priv;
169  int ret = 0, plane;
170 
171  if (!fftfilt->dc[U] && !fftfilt->dc[V]) {
172  fftfilt->dc[U] = fftfilt->dc[Y];
173  fftfilt->dc[V] = fftfilt->dc[Y];
174  } else {
175  if (!fftfilt->dc[U]) fftfilt->dc[U] = fftfilt->dc[V];
176  if (!fftfilt->dc[V]) fftfilt->dc[V] = fftfilt->dc[U];
177  }
178 
179  if (!fftfilt->weight_str[U] && !fftfilt->weight_str[V]) {
180  fftfilt->weight_str[U] = av_strdup(fftfilt->weight_str[Y]);
181  fftfilt->weight_str[V] = av_strdup(fftfilt->weight_str[Y]);
182  } else {
183  if (!fftfilt->weight_str[U]) fftfilt->weight_str[U] = av_strdup(fftfilt->weight_str[V]);
184  if (!fftfilt->weight_str[V]) fftfilt->weight_str[V] = av_strdup(fftfilt->weight_str[U]);
185  }
186 
187  for (plane = 0; plane < 3; plane++) {
188  static double (*p[])(void *, double, double) = { weight_Y, weight_U, weight_V };
189  const char *const func2_names[] = {"weight_Y", "weight_U", "weight_V", NULL };
190  double (*func2[])(void *, double, double) = { weight_Y, weight_U, weight_V, p[plane], NULL };
191 
192  ret = av_expr_parse(&fftfilt->weight_expr[plane], fftfilt->weight_str[plane], var_names,
193  NULL, NULL, func2_names, func2, 0, ctx);
194  if (ret < 0)
195  break;
196  }
197  return ret;
198 }
199 
200 static int config_props(AVFilterLink *inlink)
201 {
202  FFTFILTContext *fftfilt = inlink->dst->priv;
203  const AVPixFmtDescriptor *desc;
204  int rdft_hbits, rdft_vbits, i, j, plane;
205  double values[VAR_VARS_NB];
206 
207  desc = av_pix_fmt_desc_get(inlink->format);
208  for (i = 0; i < desc->nb_components; i++) {
209  int w = inlink->w;
210  int h = inlink->h;
211 
212  /* RDFT - Array initialization for Horizontal pass*/
213  for (rdft_hbits = 1; 1 << rdft_hbits < w*10/9; rdft_hbits++);
214  fftfilt->rdft_hbits[i] = rdft_hbits;
215  fftfilt->rdft_hlen[i] = 1 << rdft_hbits;
216  if (!(fftfilt->rdft_hdata[i] = av_malloc_array(h, fftfilt->rdft_hlen[i] * sizeof(FFTSample))))
217  return AVERROR(ENOMEM);
218 
219  /* RDFT - Array initialization for Vertical pass*/
220  for (rdft_vbits = 1; 1 << rdft_vbits < h*10/9; rdft_vbits++);
221  fftfilt->rdft_vbits[i] = rdft_vbits;
222  fftfilt->rdft_vlen[i] = 1 << rdft_vbits;
223  if (!(fftfilt->rdft_vdata[i] = av_malloc_array(fftfilt->rdft_hlen[i], fftfilt->rdft_vlen[i] * sizeof(FFTSample))))
224  return AVERROR(ENOMEM);
225  }
226 
227  /*Luminance value - Array initialization*/
228  values[VAR_W] = inlink->w;
229  values[VAR_H] = inlink->h;
230  for (plane = 0; plane < 3; plane++)
231  {
232  if(!(fftfilt->weight[plane] = av_malloc_array(fftfilt->rdft_hlen[plane], fftfilt->rdft_vlen[plane] * sizeof(double))))
233  return AVERROR(ENOMEM);
234  for (i = 0; i < fftfilt->rdft_hlen[plane]; i++)
235  {
236  values[VAR_X] = i;
237  for (j = 0; j < fftfilt->rdft_vlen[plane]; j++)
238  {
239  values[VAR_Y] = j;
240  fftfilt->weight[plane][i * fftfilt->rdft_vlen[plane] + j] =
241  av_expr_eval(fftfilt->weight_expr[plane], values, fftfilt);
242  }
243  }
244  }
245  return 0;
246 }
247 
248 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
249 {
250  AVFilterContext *ctx = inlink->dst;
251  AVFilterLink *outlink = inlink->dst->outputs[0];
252  const AVPixFmtDescriptor *desc;
253  FFTFILTContext *fftfilt = ctx->priv;
254  AVFrame *out;
255  int i, j, plane;
256 
257  out = ff_get_video_buffer(outlink, inlink->w, inlink->h);
258  if (!out)
259  return AVERROR(ENOMEM);
260 
261  av_frame_copy_props(out, in);
262 
263  desc = av_pix_fmt_desc_get(inlink->format);
264  for (plane = 0; plane < desc->nb_components; plane++) {
265  int w = inlink->w;
266  int h = inlink->h;
267 
268  if (plane == 1 || plane == 2) {
269  w = FF_CEIL_RSHIFT(w, desc->log2_chroma_w);
270  h = FF_CEIL_RSHIFT(h, desc->log2_chroma_h);
271  }
272 
273  rdft_horizontal(fftfilt, in, w, h, plane);
274  rdft_vertical(fftfilt, h, plane);
275 
276  /*Change user defined parameters*/
277  for (i = 0; i < fftfilt->rdft_hlen[plane]; i++)
278  for (j = 0; j < fftfilt->rdft_vlen[plane]; j++)
279  fftfilt->rdft_vdata[plane][i * fftfilt->rdft_vlen[plane] + j] *=
280  fftfilt->weight[plane][i * fftfilt->rdft_vlen[plane] + j];
281 
282  fftfilt->rdft_vdata[plane][0] += fftfilt->rdft_hlen[plane] * fftfilt->rdft_vlen[plane] * fftfilt->dc[plane];
283 
284  irdft_vertical(fftfilt, h, plane);
285  irdft_horizontal(fftfilt, out, w, h, plane);
286  }
287 
288  av_frame_free(&in);
289  return ff_filter_frame(outlink, out);
290 }
291 
292 static av_cold void uninit(AVFilterContext *ctx)
293 {
294  FFTFILTContext *fftfilt = ctx->priv;
295  int i;
296  for (i = 0; i < MAX_PLANES; i++) {
297  av_free(fftfilt->rdft_hdata[i]);
298  av_free(fftfilt->rdft_vdata[i]);
299  av_expr_free(fftfilt->weight_expr[i]);
300  av_free(fftfilt->weight[i]);
301  }
302 }
303 
305 {
306  static const enum AVPixelFormat pixel_fmts_fftfilt[] = {
310  };
311 
312  AVFilterFormats *fmts_list = ff_make_format_list(pixel_fmts_fftfilt);
313  if (!fmts_list)
314  return AVERROR(ENOMEM);
315  return ff_set_common_formats(ctx, fmts_list);
316 }
317 
318 static const AVFilterPad fftfilt_inputs[] = {
319  {
320  .name = "default",
321  .type = AVMEDIA_TYPE_VIDEO,
322  .config_props = config_props,
323  .filter_frame = filter_frame,
324  },
325  { NULL }
326 };
327 
328 static const AVFilterPad fftfilt_outputs[] = {
329  {
330  .name = "default",
331  .type = AVMEDIA_TYPE_VIDEO,
332  },
333  { NULL }
334 };
335 
337  .name = "fftfilt",
338  .description = NULL_IF_CONFIG_SMALL("Apply arbitrary expressions to samples in frequency domain"),
339  .priv_size = sizeof(FFTFILTContext),
340  .priv_class = &fftfilt_class,
341  .inputs = fftfilt_inputs,
342  .outputs = fftfilt_outputs,
344  .init = initialize,
345  .uninit = uninit,
346 };
int plane
Definition: avisynth_c.h:291
#define NULL
Definition: coverity.c:32
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2090
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
AVOption.
Definition: opt.h:255
static void irdft_horizontal(FFTFILTContext *fftfilt, AVFrame *out, int w, int h, int plane)
Definition: vf_fftfilt.c:149
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:68
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
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:652
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:109
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
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:67
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1145
Definition: vf_fftfilt.c:57
#define av_cold
Definition: attributes.h:74
AVOptions.
size_t rdft_vlen[MAX_PLANES]
Definition: vf_fftfilt.c:43
static void copy_rev(FFTSample *dest, int w, int w2)
Definition: vf_fftfilt.c:84
Definition: eval.c:143
FFTSample * rdft_vdata[MAX_PLANES]
Definition: vf_fftfilt.c:45
static void rdft_vertical(FFTFILTContext *fftfilt, int h, int plane)
Definition: vf_fftfilt.c:115
AVFILTER_DEFINE_CLASS(fftfilt)
static const char *const var_names[]
Definition: vf_fftfilt.c:54
static const AVFilterPad fftfilt_inputs[]
Definition: vf_fftfilt.c:318
A filter pad used for either input or output.
Definition: internal.h:61
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:542
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
size_t rdft_hlen[MAX_PLANES]
Definition: vf_fftfilt.c:42
#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:148
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
static void irdft_vertical(FFTFILTContext *fftfilt, int h, int plane)
Definition: vf_fftfilt.c:133
void * priv
private data for use by the filter
Definition: avfilter.h:654
Definition: avfft.h:73
float FFTSample
Definition: avfft.h:35
static double weight_V(void *priv, double x, double y)
Definition: vf_fftfilt.c:82
void av_rdft_calc(RDFTContext *s, FFTSample *data)
static const AVOption fftfilt_options[]
Definition: vf_fftfilt.c:62
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
int rdft_vbits[MAX_PLANES]
Definition: vf_fftfilt.c:41
char * weight_str[MAX_PLANES]
Definition: vf_fftfilt.c:48
static double lum(void *priv, double x, double y, int plane)
Definition: vf_fftfilt.c:74
float y
ret
Definition: avfilter.c:974
#define FF_CEIL_RSHIFT(a, b)
Definition: common.h:57
#define OFFSET(x)
Definition: vf_fftfilt.c:59
#define FLAGS
Definition: vf_fftfilt.c:60
Definition: avfft.h:72
void av_rdft_end(RDFTContext *s)
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:312
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:265
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
double * weight[MAX_PLANES]
Definition: vf_fftfilt.c:50
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
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:200
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
static double weight_U(void *priv, double x, double y)
Definition: vf_fftfilt.c:81
static void rdft_horizontal(FFTFILTContext *fftfilt, AVFrame *in, int w, int h, int plane)
Definition: vf_fftfilt.c:96
RDFTContext * rdft
Definition: vf_fftfilt.c:39
const char * name
Filter name.
Definition: avfilter.h:474
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
static int query_formats(AVFilterContext *ctx)
Definition: vf_fftfilt.c:304
static int weight(int i, int blen, int offset)
Definition: diracdec.c:1298
AVFilter ff_vf_fftfilt
Definition: vf_fftfilt.c:336
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
int rdft_hbits[MAX_PLANES]
Definition: vf_fftfilt.c:40
static double weight_Y(void *priv, double x, double y)
Definition: vf_fftfilt.c:80
Definition: vf_fftfilt.c:57
Y , 8bpp.
Definition: pixfmt.h:71
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_fftfilt.c:292
common internal and external API header
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_fftfilt.c:248
int dc[MAX_PLANES]
Definition: vf_fftfilt.c:47
AVExpr * weight_expr[MAX_PLANES]
Definition: vf_fftfilt.c:49
#define av_free(p)
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:707
FFTSample * rdft_hdata[MAX_PLANES]
Definition: vf_fftfilt.c:44
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:328
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-> out
An instance of a filter.
Definition: avfilter.h:633
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
static av_cold int initialize(AVFilterContext *ctx)
Definition: vf_fftfilt.c:166
#define av_malloc_array(a, b)
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
Definition: vf_fftfilt.c:57
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:548
simple arithmetic expression evaluator
#define MAX_PLANES
Definition: vf_fftfilt.c:34