FFmpeg
af_afade.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-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 /**
22  * @file
23  * fade audio filter
24  */
25 
26 #include "config_components.h"
27 
28 #include "libavutil/opt.h"
29 #include "audio.h"
30 #include "avfilter.h"
31 #include "filters.h"
32 
33 typedef struct AudioFadeContext {
34  const AVClass *class;
35  int type;
36  int curve, curve2;
41  double silence;
42  double unity;
43  int overlap;
44  int status[2];
47 
48  void (*fade_samples)(uint8_t **dst, uint8_t * const *src,
49  int nb_samples, int channels, int direction,
50  int64_t start, int64_t range, int curve,
51  double silence, double unity);
52  void (*scale_samples)(uint8_t **dst, uint8_t * const *src,
53  int nb_samples, int channels, double unity);
54  void (*crossfade_samples)(uint8_t **dst, uint8_t * const *cf0,
55  uint8_t * const *cf1,
56  int nb_samples, int channels,
57  int curve0, int curve1);
59 
61 
62 #define OFFSET(x) offsetof(AudioFadeContext, x)
63 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
64 #define TFLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
65 
66  static const enum AVSampleFormat sample_fmts[] = {
72  };
73 
74 static double fade_gain(int curve, int64_t index, int64_t range, double silence, double unity)
75 {
76 #define CUBE(a) ((a)*(a)*(a))
77  double gain;
78 
79  gain = av_clipd(1.0 * index / range, 0, 1.0);
80 
81  switch (curve) {
82  case QSIN:
83  gain = sin(gain * M_PI / 2.0);
84  break;
85  case IQSIN:
86  /* 0.6... = 2 / M_PI */
87  gain = 0.6366197723675814 * asin(gain);
88  break;
89  case ESIN:
90  gain = 1.0 - cos(M_PI / 4.0 * (CUBE(2.0*gain - 1) + 1));
91  break;
92  case HSIN:
93  gain = (1.0 - cos(gain * M_PI)) / 2.0;
94  break;
95  case IHSIN:
96  /* 0.3... = 1 / M_PI */
97  gain = 0.3183098861837907 * acos(1 - 2 * gain);
98  break;
99  case EXP:
100  /* -11.5... = 5*ln(0.1) */
101  gain = exp(-11.512925464970227 * (1 - gain));
102  break;
103  case LOG:
104  gain = av_clipd(1 + 0.2 * log10(gain), 0, 1.0);
105  break;
106  case PAR:
107  gain = 1 - sqrt(1 - gain);
108  break;
109  case IPAR:
110  gain = (1 - (1 - gain) * (1 - gain));
111  break;
112  case QUA:
113  gain *= gain;
114  break;
115  case CUB:
116  gain = CUBE(gain);
117  break;
118  case SQU:
119  gain = sqrt(gain);
120  break;
121  case CBR:
122  gain = cbrt(gain);
123  break;
124  case DESE:
125  gain = gain <= 0.5 ? cbrt(2 * gain) / 2: 1 - cbrt(2 * (1 - gain)) / 2;
126  break;
127  case DESI:
128  gain = gain <= 0.5 ? CUBE(2 * gain) / 2: 1 - CUBE(2 * (1 - gain)) / 2;
129  break;
130  case LOSI: {
131  const double a = 1. / (1. - 0.787) - 1;
132  double A = 1. / (1.0 + exp(0 -((gain-0.5) * a * 2.0)));
133  double B = 1. / (1.0 + exp(a));
134  double C = 1. / (1.0 + exp(0-a));
135  gain = (A - B) / (C - B);
136  }
137  break;
138  case SINC:
139  gain = gain >= 1.0 ? 1.0 : sin(M_PI * (1.0 - gain)) / (M_PI * (1.0 - gain));
140  break;
141  case ISINC:
142  gain = gain <= 0.0 ? 0.0 : 1.0 - sin(M_PI * gain) / (M_PI * gain);
143  break;
144  case QUAT:
145  gain = gain * gain * gain * gain;
146  break;
147  case QUATR:
148  gain = pow(gain, 0.25);
149  break;
150  case QSIN2:
151  gain = sin(gain * M_PI / 2.0) * sin(gain * M_PI / 2.0);
152  break;
153  case HSIN2:
154  gain = pow((1.0 - cos(gain * M_PI)) / 2.0, 2.0);
155  break;
156  case NONE:
157  gain = 1.0;
158  break;
159  }
160 
161  return silence + (unity - silence) * gain;
162 }
163 
164 #define FADE_PLANAR(name, type) \
165 static void fade_samples_## name ##p(uint8_t **dst, uint8_t * const *src, \
166  int nb_samples, int channels, int dir, \
167  int64_t start, int64_t range,int curve,\
168  double silence, double unity) \
169 { \
170  int i, c; \
171  \
172  for (i = 0; i < nb_samples; i++) { \
173  double gain = fade_gain(curve, start + i * dir,range,silence,unity);\
174  for (c = 0; c < channels; c++) { \
175  type *d = (type *)dst[c]; \
176  const type *s = (type *)src[c]; \
177  \
178  d[i] = s[i] * gain; \
179  } \
180  } \
181 }
182 
183 #define FADE(name, type) \
184 static void fade_samples_## name (uint8_t **dst, uint8_t * const *src, \
185  int nb_samples, int channels, int dir, \
186  int64_t start, int64_t range, int curve, \
187  double silence, double unity) \
188 { \
189  type *d = (type *)dst[0]; \
190  const type *s = (type *)src[0]; \
191  int i, c, k = 0; \
192  \
193  for (i = 0; i < nb_samples; i++) { \
194  double gain = fade_gain(curve, start + i * dir,range,silence,unity);\
195  for (c = 0; c < channels; c++, k++) \
196  d[k] = s[k] * gain; \
197  } \
198 }
199 
200 FADE_PLANAR(dbl, double)
201 FADE_PLANAR(flt, float)
202 FADE_PLANAR(s16, int16_t)
203 FADE_PLANAR(s32, int32_t)
204 
205 FADE(dbl, double)
206 FADE(flt, float)
207 FADE(s16, int16_t)
208 FADE(s32, int32_t)
209 
210 #define SCALE_PLANAR(name, type) \
211 static void scale_samples_## name ##p(uint8_t **dst, uint8_t * const *src, \
212  int nb_samples, int channels, \
213  double gain) \
214 { \
215  int i, c; \
216  \
217  for (i = 0; i < nb_samples; i++) { \
218  for (c = 0; c < channels; c++) { \
219  type *d = (type *)dst[c]; \
220  const type *s = (type *)src[c]; \
221  \
222  d[i] = s[i] * gain; \
223  } \
224  } \
225 }
226 
227 #define SCALE(name, type) \
228 static void scale_samples_## name (uint8_t **dst, uint8_t * const *src, \
229  int nb_samples, int channels, double gain)\
230 { \
231  type *d = (type *)dst[0]; \
232  const type *s = (type *)src[0]; \
233  int i, c, k = 0; \
234  \
235  for (i = 0; i < nb_samples; i++) { \
236  for (c = 0; c < channels; c++, k++) \
237  d[k] = s[k] * gain; \
238  } \
239 }
240 
241 SCALE_PLANAR(dbl, double)
242 SCALE_PLANAR(flt, float)
243 SCALE_PLANAR(s16, int16_t)
244 SCALE_PLANAR(s32, int32_t)
245 
246 SCALE(dbl, double)
247 SCALE(flt, float)
248 SCALE(s16, int16_t)
249 SCALE(s32, int32_t)
250 
251 static int config_output(AVFilterLink *outlink)
252 {
253  AVFilterContext *ctx = outlink->src;
254  AudioFadeContext *s = ctx->priv;
255 
256  switch (outlink->format) {
257  case AV_SAMPLE_FMT_DBL: s->fade_samples = fade_samples_dbl;
258  s->scale_samples = scale_samples_dbl;
259  break;
260  case AV_SAMPLE_FMT_DBLP: s->fade_samples = fade_samples_dblp;
261  s->scale_samples = scale_samples_dblp;
262  break;
263  case AV_SAMPLE_FMT_FLT: s->fade_samples = fade_samples_flt;
264  s->scale_samples = scale_samples_flt;
265  break;
266  case AV_SAMPLE_FMT_FLTP: s->fade_samples = fade_samples_fltp;
267  s->scale_samples = scale_samples_fltp;
268  break;
269  case AV_SAMPLE_FMT_S16: s->fade_samples = fade_samples_s16;
270  s->scale_samples = scale_samples_s16;
271  break;
272  case AV_SAMPLE_FMT_S16P: s->fade_samples = fade_samples_s16p;
273  s->scale_samples = scale_samples_s16p;
274  break;
275  case AV_SAMPLE_FMT_S32: s->fade_samples = fade_samples_s32;
276  s->scale_samples = scale_samples_s32;
277  break;
278  case AV_SAMPLE_FMT_S32P: s->fade_samples = fade_samples_s32p;
279  s->scale_samples = scale_samples_s32p;
280  break;
281  }
282 
283  if (s->duration)
284  s->nb_samples = av_rescale(s->duration, outlink->sample_rate, AV_TIME_BASE);
285  s->duration = 0;
286  if (s->start_time)
287  s->start_sample = av_rescale(s->start_time, outlink->sample_rate, AV_TIME_BASE);
288  s->start_time = 0;
289 
290  return 0;
291 }
292 
293 #if CONFIG_AFADE_FILTER
294 
295 static const AVOption afade_options[] = {
296  { "type", "set the fade direction", OFFSET(type), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, TFLAGS, .unit = "type" },
297  { "t", "set the fade direction", OFFSET(type), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, TFLAGS, .unit = "type" },
298  { "in", "fade-in", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, 0, 0, TFLAGS, .unit = "type" },
299  { "out", "fade-out", 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0, TFLAGS, .unit = "type" },
300  { "start_sample", "set number of first sample to start fading", OFFSET(start_sample), AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX, TFLAGS },
301  { "ss", "set number of first sample to start fading", OFFSET(start_sample), AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX, TFLAGS },
302  { "nb_samples", "set number of samples for fade duration", OFFSET(nb_samples), AV_OPT_TYPE_INT64, {.i64 = 44100}, 1, INT64_MAX, TFLAGS },
303  { "ns", "set number of samples for fade duration", OFFSET(nb_samples), AV_OPT_TYPE_INT64, {.i64 = 44100}, 1, INT64_MAX, TFLAGS },
304  { "start_time", "set time to start fading", OFFSET(start_time), AV_OPT_TYPE_DURATION, {.i64 = 0 }, 0, INT64_MAX, TFLAGS },
305  { "st", "set time to start fading", OFFSET(start_time), AV_OPT_TYPE_DURATION, {.i64 = 0 }, 0, INT64_MAX, TFLAGS },
306  { "duration", "set fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0 }, 0, INT64_MAX, TFLAGS },
307  { "d", "set fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0 }, 0, INT64_MAX, TFLAGS },
308  { "curve", "set fade curve type", OFFSET(curve), AV_OPT_TYPE_INT, {.i64 = TRI }, NONE, NB_CURVES - 1, TFLAGS, .unit = "curve" },
309  { "c", "set fade curve type", OFFSET(curve), AV_OPT_TYPE_INT, {.i64 = TRI }, NONE, NB_CURVES - 1, TFLAGS, .unit = "curve" },
310  { "nofade", "no fade; keep audio as-is", 0, AV_OPT_TYPE_CONST, {.i64 = NONE }, 0, 0, TFLAGS, .unit = "curve" },
311  { "tri", "linear slope", 0, AV_OPT_TYPE_CONST, {.i64 = TRI }, 0, 0, TFLAGS, .unit = "curve" },
312  { "qsin", "quarter of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = QSIN }, 0, 0, TFLAGS, .unit = "curve" },
313  { "esin", "exponential sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = ESIN }, 0, 0, TFLAGS, .unit = "curve" },
314  { "hsin", "half of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = HSIN }, 0, 0, TFLAGS, .unit = "curve" },
315  { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64 = LOG }, 0, 0, TFLAGS, .unit = "curve" },
316  { "ipar", "inverted parabola", 0, AV_OPT_TYPE_CONST, {.i64 = IPAR }, 0, 0, TFLAGS, .unit = "curve" },
317  { "qua", "quadratic", 0, AV_OPT_TYPE_CONST, {.i64 = QUA }, 0, 0, TFLAGS, .unit = "curve" },
318  { "cub", "cubic", 0, AV_OPT_TYPE_CONST, {.i64 = CUB }, 0, 0, TFLAGS, .unit = "curve" },
319  { "squ", "square root", 0, AV_OPT_TYPE_CONST, {.i64 = SQU }, 0, 0, TFLAGS, .unit = "curve" },
320  { "cbr", "cubic root", 0, AV_OPT_TYPE_CONST, {.i64 = CBR }, 0, 0, TFLAGS, .unit = "curve" },
321  { "par", "parabola", 0, AV_OPT_TYPE_CONST, {.i64 = PAR }, 0, 0, TFLAGS, .unit = "curve" },
322  { "exp", "exponential", 0, AV_OPT_TYPE_CONST, {.i64 = EXP }, 0, 0, TFLAGS, .unit = "curve" },
323  { "iqsin", "inverted quarter of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = IQSIN}, 0, 0, TFLAGS, .unit = "curve" },
324  { "ihsin", "inverted half of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = IHSIN}, 0, 0, TFLAGS, .unit = "curve" },
325  { "dese", "double-exponential seat", 0, AV_OPT_TYPE_CONST, {.i64 = DESE }, 0, 0, TFLAGS, .unit = "curve" },
326  { "desi", "double-exponential sigmoid", 0, AV_OPT_TYPE_CONST, {.i64 = DESI }, 0, 0, TFLAGS, .unit = "curve" },
327  { "losi", "logistic sigmoid", 0, AV_OPT_TYPE_CONST, {.i64 = LOSI }, 0, 0, TFLAGS, .unit = "curve" },
328  { "sinc", "sine cardinal function", 0, AV_OPT_TYPE_CONST, {.i64 = SINC }, 0, 0, TFLAGS, .unit = "curve" },
329  { "isinc", "inverted sine cardinal function", 0, AV_OPT_TYPE_CONST, {.i64 = ISINC}, 0, 0, TFLAGS, .unit = "curve" },
330  { "quat", "quartic", 0, AV_OPT_TYPE_CONST, {.i64 = QUAT }, 0, 0, TFLAGS, .unit = "curve" },
331  { "quatr", "quartic root", 0, AV_OPT_TYPE_CONST, {.i64 = QUATR}, 0, 0, TFLAGS, .unit = "curve" },
332  { "qsin2", "squared quarter of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = QSIN2}, 0, 0, TFLAGS, .unit = "curve" },
333  { "hsin2", "squared half of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = HSIN2}, 0, 0, TFLAGS, .unit = "curve" },
334  { "silence", "set the silence gain", OFFSET(silence), AV_OPT_TYPE_DOUBLE, {.dbl = 0 }, 0, 1, TFLAGS },
335  { "unity", "set the unity gain", OFFSET(unity), AV_OPT_TYPE_DOUBLE, {.dbl = 1 }, 0, 1, TFLAGS },
336  { NULL }
337 };
338 
339 AVFILTER_DEFINE_CLASS(afade);
340 
341 static av_cold int init(AVFilterContext *ctx)
342 {
343  AudioFadeContext *s = ctx->priv;
344 
345  if (INT64_MAX - s->nb_samples < s->start_sample)
346  return AVERROR(EINVAL);
347 
348  return 0;
349 }
350 
351 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
352 {
353  AudioFadeContext *s = inlink->dst->priv;
354  AVFilterLink *outlink = inlink->dst->outputs[0];
355  int nb_samples = buf->nb_samples;
356  AVFrame *out_buf;
357  int64_t cur_sample = av_rescale_q(buf->pts, inlink->time_base, (AVRational){1, inlink->sample_rate});
358 
359  if (s->unity == 1.0 &&
360  ((!s->type && (s->start_sample + s->nb_samples < cur_sample)) ||
361  ( s->type && (cur_sample + nb_samples < s->start_sample))))
362  return ff_filter_frame(outlink, buf);
363 
364  if (av_frame_is_writable(buf)) {
365  out_buf = buf;
366  } else {
367  out_buf = ff_get_audio_buffer(outlink, nb_samples);
368  if (!out_buf)
369  return AVERROR(ENOMEM);
370  av_frame_copy_props(out_buf, buf);
371  }
372 
373  if ((!s->type && (cur_sample + nb_samples < s->start_sample)) ||
374  ( s->type && (s->start_sample + s->nb_samples < cur_sample))) {
375  if (s->silence == 0.) {
376  av_samples_set_silence(out_buf->extended_data, 0, nb_samples,
377  out_buf->ch_layout.nb_channels, out_buf->format);
378  } else {
379  s->scale_samples(out_buf->extended_data, buf->extended_data,
380  nb_samples, buf->ch_layout.nb_channels,
381  s->silence);
382  }
383  } else if (( s->type && (cur_sample + nb_samples < s->start_sample)) ||
384  (!s->type && (s->start_sample + s->nb_samples < cur_sample))) {
385  s->scale_samples(out_buf->extended_data, buf->extended_data,
386  nb_samples, buf->ch_layout.nb_channels,
387  s->unity);
388  } else {
389  int64_t start;
390 
391  if (!s->type)
392  start = cur_sample - s->start_sample;
393  else
394  start = s->start_sample + s->nb_samples - cur_sample;
395 
396  s->fade_samples(out_buf->extended_data, buf->extended_data,
397  nb_samples, buf->ch_layout.nb_channels,
398  s->type ? -1 : 1, start,
399  s->nb_samples, s->curve, s->silence, s->unity);
400  }
401 
402  if (buf != out_buf)
403  av_frame_free(&buf);
404 
405  return ff_filter_frame(outlink, out_buf);
406 }
407 
408 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
409  char *res, int res_len, int flags)
410 {
411  int ret;
412 
413  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
414  if (ret < 0)
415  return ret;
416 
417  return config_output(ctx->outputs[0]);
418 }
419 
420 static const AVFilterPad avfilter_af_afade_inputs[] = {
421  {
422  .name = "default",
423  .type = AVMEDIA_TYPE_AUDIO,
424  .filter_frame = filter_frame,
425  },
426 };
427 
428 static const AVFilterPad avfilter_af_afade_outputs[] = {
429  {
430  .name = "default",
431  .type = AVMEDIA_TYPE_AUDIO,
432  .config_props = config_output,
433  },
434 };
435 
436 const AVFilter ff_af_afade = {
437  .name = "afade",
438  .description = NULL_IF_CONFIG_SMALL("Fade in/out input audio."),
439  .priv_size = sizeof(AudioFadeContext),
440  .init = init,
441  FILTER_INPUTS(avfilter_af_afade_inputs),
442  FILTER_OUTPUTS(avfilter_af_afade_outputs),
444  .priv_class = &afade_class,
445  .process_command = process_command,
447 };
448 
449 #endif /* CONFIG_AFADE_FILTER */
450 
451 #if CONFIG_ACROSSFADE_FILTER
452 
453 static const AVOption acrossfade_options[] = {
454  { "nb_samples", "set number of samples for cross fade duration", OFFSET(nb_samples), AV_OPT_TYPE_INT64, {.i64 = 44100}, 1, INT32_MAX/10, FLAGS },
455  { "ns", "set number of samples for cross fade duration", OFFSET(nb_samples), AV_OPT_TYPE_INT64, {.i64 = 44100}, 1, INT32_MAX/10, FLAGS },
456  { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0 }, 0, 60000000, FLAGS },
457  { "d", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0 }, 0, 60000000, FLAGS },
458  { "overlap", "overlap 1st stream end with 2nd stream start", OFFSET(overlap), AV_OPT_TYPE_BOOL, {.i64 = 1 }, 0, 1, FLAGS },
459  { "o", "overlap 1st stream end with 2nd stream start", OFFSET(overlap), AV_OPT_TYPE_BOOL, {.i64 = 1 }, 0, 1, FLAGS },
460  { "curve1", "set fade curve type for 1st stream", OFFSET(curve), AV_OPT_TYPE_INT, {.i64 = TRI }, NONE, NB_CURVES - 1, FLAGS, .unit = "curve" },
461  { "c1", "set fade curve type for 1st stream", OFFSET(curve), AV_OPT_TYPE_INT, {.i64 = TRI }, NONE, NB_CURVES - 1, FLAGS, .unit = "curve" },
462  { "nofade", "no fade; keep audio as-is", 0, AV_OPT_TYPE_CONST, {.i64 = NONE }, 0, 0, FLAGS, .unit = "curve" },
463  { "tri", "linear slope", 0, AV_OPT_TYPE_CONST, {.i64 = TRI }, 0, 0, FLAGS, .unit = "curve" },
464  { "qsin", "quarter of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = QSIN }, 0, 0, FLAGS, .unit = "curve" },
465  { "esin", "exponential sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = ESIN }, 0, 0, FLAGS, .unit = "curve" },
466  { "hsin", "half of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = HSIN }, 0, 0, FLAGS, .unit = "curve" },
467  { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64 = LOG }, 0, 0, FLAGS, .unit = "curve" },
468  { "ipar", "inverted parabola", 0, AV_OPT_TYPE_CONST, {.i64 = IPAR }, 0, 0, FLAGS, .unit = "curve" },
469  { "qua", "quadratic", 0, AV_OPT_TYPE_CONST, {.i64 = QUA }, 0, 0, FLAGS, .unit = "curve" },
470  { "cub", "cubic", 0, AV_OPT_TYPE_CONST, {.i64 = CUB }, 0, 0, FLAGS, .unit = "curve" },
471  { "squ", "square root", 0, AV_OPT_TYPE_CONST, {.i64 = SQU }, 0, 0, FLAGS, .unit = "curve" },
472  { "cbr", "cubic root", 0, AV_OPT_TYPE_CONST, {.i64 = CBR }, 0, 0, FLAGS, .unit = "curve" },
473  { "par", "parabola", 0, AV_OPT_TYPE_CONST, {.i64 = PAR }, 0, 0, FLAGS, .unit = "curve" },
474  { "exp", "exponential", 0, AV_OPT_TYPE_CONST, {.i64 = EXP }, 0, 0, FLAGS, .unit = "curve" },
475  { "iqsin", "inverted quarter of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = IQSIN}, 0, 0, FLAGS, .unit = "curve" },
476  { "ihsin", "inverted half of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = IHSIN}, 0, 0, FLAGS, .unit = "curve" },
477  { "dese", "double-exponential seat", 0, AV_OPT_TYPE_CONST, {.i64 = DESE }, 0, 0, FLAGS, .unit = "curve" },
478  { "desi", "double-exponential sigmoid", 0, AV_OPT_TYPE_CONST, {.i64 = DESI }, 0, 0, FLAGS, .unit = "curve" },
479  { "losi", "logistic sigmoid", 0, AV_OPT_TYPE_CONST, {.i64 = LOSI }, 0, 0, FLAGS, .unit = "curve" },
480  { "sinc", "sine cardinal function", 0, AV_OPT_TYPE_CONST, {.i64 = SINC }, 0, 0, FLAGS, .unit = "curve" },
481  { "isinc", "inverted sine cardinal function", 0, AV_OPT_TYPE_CONST, {.i64 = ISINC}, 0, 0, FLAGS, .unit = "curve" },
482  { "quat", "quartic", 0, AV_OPT_TYPE_CONST, {.i64 = QUAT }, 0, 0, FLAGS, .unit = "curve" },
483  { "quatr", "quartic root", 0, AV_OPT_TYPE_CONST, {.i64 = QUATR}, 0, 0, FLAGS, .unit = "curve" },
484  { "qsin2", "squared quarter of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = QSIN2}, 0, 0, FLAGS, .unit = "curve" },
485  { "hsin2", "squared half of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = HSIN2}, 0, 0, FLAGS, .unit = "curve" },
486  { "curve2", "set fade curve type for 2nd stream", OFFSET(curve2), AV_OPT_TYPE_INT, {.i64 = TRI }, NONE, NB_CURVES - 1, FLAGS, .unit = "curve" },
487  { "c2", "set fade curve type for 2nd stream", OFFSET(curve2), AV_OPT_TYPE_INT, {.i64 = TRI }, NONE, NB_CURVES - 1, FLAGS, .unit = "curve" },
488  { NULL }
489 };
490 
491 AVFILTER_DEFINE_CLASS(acrossfade);
492 
493 #define CROSSFADE_PLANAR(name, type) \
494 static void crossfade_samples_## name ##p(uint8_t **dst, uint8_t * const *cf0, \
495  uint8_t * const *cf1, \
496  int nb_samples, int channels, \
497  int curve0, int curve1) \
498 { \
499  int i, c; \
500  \
501  for (i = 0; i < nb_samples; i++) { \
502  double gain0 = fade_gain(curve0, nb_samples - 1 - i, nb_samples,0.,1.);\
503  double gain1 = fade_gain(curve1, i, nb_samples, 0., 1.); \
504  for (c = 0; c < channels; c++) { \
505  type *d = (type *)dst[c]; \
506  const type *s0 = (type *)cf0[c]; \
507  const type *s1 = (type *)cf1[c]; \
508  \
509  d[i] = s0[i] * gain0 + s1[i] * gain1; \
510  } \
511  } \
512 }
513 
514 #define CROSSFADE(name, type) \
515 static void crossfade_samples_## name (uint8_t **dst, uint8_t * const *cf0, \
516  uint8_t * const *cf1, \
517  int nb_samples, int channels, \
518  int curve0, int curve1) \
519 { \
520  type *d = (type *)dst[0]; \
521  const type *s0 = (type *)cf0[0]; \
522  const type *s1 = (type *)cf1[0]; \
523  int i, c, k = 0; \
524  \
525  for (i = 0; i < nb_samples; i++) { \
526  double gain0 = fade_gain(curve0, nb_samples - 1-i,nb_samples,0.,1.);\
527  double gain1 = fade_gain(curve1, i, nb_samples, 0., 1.); \
528  for (c = 0; c < channels; c++, k++) \
529  d[k] = s0[k] * gain0 + s1[k] * gain1; \
530  } \
531 }
532 
533 CROSSFADE_PLANAR(dbl, double)
534 CROSSFADE_PLANAR(flt, float)
535 CROSSFADE_PLANAR(s16, int16_t)
536 CROSSFADE_PLANAR(s32, int32_t)
537 
538 CROSSFADE(dbl, double)
539 CROSSFADE(flt, float)
540 CROSSFADE(s16, int16_t)
541 CROSSFADE(s32, int32_t)
542 
543 static int check_input(AVFilterLink *inlink)
544 {
545  const int queued_samples = ff_inlink_queued_samples(inlink);
546 
547  return ff_inlink_check_available_samples(inlink, queued_samples + 1) == 1;
548 }
549 
550 static int activate(AVFilterContext *ctx)
551 {
552  AudioFadeContext *s = ctx->priv;
553  AVFilterLink *outlink = ctx->outputs[0];
554  AVFrame *in = NULL, *out, *cf[2] = { NULL };
555  int ret = 0, nb_samples, status;
556  int64_t pts;
557 
559 
560  if (s->passthrough && s->status[0]) {
561  ret = ff_inlink_consume_frame(ctx->inputs[1], &in);
562  if (ret > 0) {
563  in->pts = s->pts;
564  s->pts += av_rescale_q(in->nb_samples,
565  (AVRational){ 1, outlink->sample_rate }, outlink->time_base);
566  return ff_filter_frame(outlink, in);
567  } else if (ret < 0) {
568  return ret;
569  } else if (ff_inlink_acknowledge_status(ctx->inputs[1], &status, &pts)) {
570  ff_outlink_set_status(outlink, status, pts);
571  return 0;
572  } else if (!ret) {
573  if (ff_outlink_frame_wanted(outlink)) {
574  ff_inlink_request_frame(ctx->inputs[1]);
575  return 0;
576  }
577  }
578  }
579 
580  nb_samples = ff_inlink_queued_samples(ctx->inputs[0]);
581  if (nb_samples > s->nb_samples) {
582  nb_samples -= s->nb_samples;
583  s->passthrough = 1;
584  ret = ff_inlink_consume_samples(ctx->inputs[0], nb_samples, nb_samples, &in);
585  if (ret < 0)
586  return ret;
587  in->pts = s->pts;
588  s->pts += av_rescale_q(in->nb_samples,
589  (AVRational){ 1, outlink->sample_rate }, outlink->time_base);
590  return ff_filter_frame(outlink, in);
591  } else if (s->status[0] && nb_samples >= s->nb_samples &&
592  ff_inlink_queued_samples(ctx->inputs[1]) >= s->nb_samples) {
593  if (s->overlap) {
594  out = ff_get_audio_buffer(outlink, s->nb_samples);
595  if (!out)
596  return AVERROR(ENOMEM);
597 
598  ret = ff_inlink_consume_samples(ctx->inputs[0], s->nb_samples, s->nb_samples, &cf[0]);
599  if (ret < 0) {
600  av_frame_free(&out);
601  return ret;
602  }
603 
604  ret = ff_inlink_consume_samples(ctx->inputs[1], s->nb_samples, s->nb_samples, &cf[1]);
605  if (ret < 0) {
606  av_frame_free(&out);
607  return ret;
608  }
609 
610  s->crossfade_samples(out->extended_data, cf[0]->extended_data,
611  cf[1]->extended_data,
612  s->nb_samples, out->ch_layout.nb_channels,
613  s->curve, s->curve2);
614  out->pts = s->pts;
615  s->pts += av_rescale_q(s->nb_samples,
616  (AVRational){ 1, outlink->sample_rate }, outlink->time_base);
617  s->passthrough = 1;
618  av_frame_free(&cf[0]);
619  av_frame_free(&cf[1]);
620  return ff_filter_frame(outlink, out);
621  } else {
622  out = ff_get_audio_buffer(outlink, s->nb_samples);
623  if (!out)
624  return AVERROR(ENOMEM);
625 
626  ret = ff_inlink_consume_samples(ctx->inputs[0], s->nb_samples, s->nb_samples, &cf[0]);
627  if (ret < 0) {
628  av_frame_free(&out);
629  return ret;
630  }
631 
632  s->fade_samples(out->extended_data, cf[0]->extended_data, s->nb_samples,
633  outlink->ch_layout.nb_channels, -1, s->nb_samples - 1, s->nb_samples, s->curve, 0., 1.);
634  out->pts = s->pts;
635  s->pts += av_rescale_q(s->nb_samples,
636  (AVRational){ 1, outlink->sample_rate }, outlink->time_base);
637  av_frame_free(&cf[0]);
638  ret = ff_filter_frame(outlink, out);
639  if (ret < 0)
640  return ret;
641 
642  out = ff_get_audio_buffer(outlink, s->nb_samples);
643  if (!out)
644  return AVERROR(ENOMEM);
645 
646  ret = ff_inlink_consume_samples(ctx->inputs[1], s->nb_samples, s->nb_samples, &cf[1]);
647  if (ret < 0) {
648  av_frame_free(&out);
649  return ret;
650  }
651 
652  s->fade_samples(out->extended_data, cf[1]->extended_data, s->nb_samples,
653  outlink->ch_layout.nb_channels, 1, 0, s->nb_samples, s->curve2, 0., 1.);
654  out->pts = s->pts;
655  s->pts += av_rescale_q(s->nb_samples,
656  (AVRational){ 1, outlink->sample_rate }, outlink->time_base);
657  s->passthrough = 1;
658  av_frame_free(&cf[1]);
659  return ff_filter_frame(outlink, out);
660  }
661  } else if (ff_outlink_frame_wanted(outlink)) {
662  if (!s->status[0] && check_input(ctx->inputs[0]))
663  s->status[0] = AVERROR_EOF;
664  s->passthrough = !s->status[0];
665  if (check_input(ctx->inputs[1])) {
666  s->status[1] = AVERROR_EOF;
668  return 0;
669  }
670  if (!s->status[0])
671  ff_inlink_request_frame(ctx->inputs[0]);
672  else
673  ff_inlink_request_frame(ctx->inputs[1]);
674  return 0;
675  }
676 
677  return ret;
678 }
679 
680 static int acrossfade_config_output(AVFilterLink *outlink)
681 {
682  AVFilterContext *ctx = outlink->src;
683  AudioFadeContext *s = ctx->priv;
684 
685  outlink->time_base = ctx->inputs[0]->time_base;
686 
687  switch (outlink->format) {
688  case AV_SAMPLE_FMT_DBL: s->crossfade_samples = crossfade_samples_dbl; break;
689  case AV_SAMPLE_FMT_DBLP: s->crossfade_samples = crossfade_samples_dblp; break;
690  case AV_SAMPLE_FMT_FLT: s->crossfade_samples = crossfade_samples_flt; break;
691  case AV_SAMPLE_FMT_FLTP: s->crossfade_samples = crossfade_samples_fltp; break;
692  case AV_SAMPLE_FMT_S16: s->crossfade_samples = crossfade_samples_s16; break;
693  case AV_SAMPLE_FMT_S16P: s->crossfade_samples = crossfade_samples_s16p; break;
694  case AV_SAMPLE_FMT_S32: s->crossfade_samples = crossfade_samples_s32; break;
695  case AV_SAMPLE_FMT_S32P: s->crossfade_samples = crossfade_samples_s32p; break;
696  }
697 
698  config_output(outlink);
699 
700  return 0;
701 }
702 
703 static AVFrame *get_audio_buffer(AVFilterLink *inlink, int nb_samples)
704 {
705  AVFilterContext *ctx = inlink->dst;
706  AudioFadeContext *s = ctx->priv;
707 
708  return s->passthrough ?
709  ff_null_get_audio_buffer (inlink, nb_samples) :
710  ff_default_get_audio_buffer(inlink, nb_samples);
711 }
712 
713 static const AVFilterPad avfilter_af_acrossfade_inputs[] = {
714  {
715  .name = "crossfade0",
716  .type = AVMEDIA_TYPE_AUDIO,
717  .get_buffer.audio = get_audio_buffer,
718  },
719  {
720  .name = "crossfade1",
721  .type = AVMEDIA_TYPE_AUDIO,
722  .get_buffer.audio = get_audio_buffer,
723  },
724 };
725 
726 static const AVFilterPad avfilter_af_acrossfade_outputs[] = {
727  {
728  .name = "default",
729  .type = AVMEDIA_TYPE_AUDIO,
730  .config_props = acrossfade_config_output,
731  },
732 };
733 
734 const AVFilter ff_af_acrossfade = {
735  .name = "acrossfade",
736  .description = NULL_IF_CONFIG_SMALL("Cross fade two input audio streams."),
737  .priv_size = sizeof(AudioFadeContext),
738  .activate = activate,
739  .priv_class = &acrossfade_class,
740  FILTER_INPUTS(avfilter_af_acrossfade_inputs),
741  FILTER_OUTPUTS(avfilter_af_acrossfade_outputs),
743 };
744 
745 #endif /* CONFIG_ACROSSFADE_FILTER */
AudioFadeContext::unity
double unity
Definition: af_afade.c:42
A
#define A(x)
Definition: vpx_arith.h:28
ff_get_audio_buffer
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:98
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
AudioFadeContext::type
int type
Definition: af_afade.c:35
AVERROR
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
opt.h
AudioFadeContext::curve2
int curve2
Definition: af_afade.c:36
ff_af_afade
const AVFilter ff_af_afade
out
FILE * out
Definition: movenc.c:55
NONE
@ NONE
Definition: af_afade.c:60
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1062
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AudioFadeContext::fade_samples
void(* fade_samples)(uint8_t **dst, uint8_t *const *src, int nb_samples, int channels, int direction, int64_t start, int64_t range, int curve, double silence, double unity)
Definition: af_afade.c:48
QUA
@ QUA
Definition: af_afade.c:60
int64_t
long long int64_t
Definition: coverity.c:34
inlink
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
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:162
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:501
av_samples_set_silence
int av_samples_set_silence(uint8_t *const *audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
Definition: samplefmt.c:246
AVOption
AVOption.
Definition: opt.h:429
IPAR
@ IPAR
Definition: af_afade.c:60
AV_SAMPLE_FMT_S32P
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:65
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
Definition: opt.h:319
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_afade.c:251
NB_CURVES
@ NB_CURVES
Definition: af_afade.c:60
SCALE_PLANAR
#define SCALE_PLANAR(name, type)
Definition: af_afade.c:210
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:327
DESE
@ DESE
Definition: af_afade.c:60
DESI
@ DESI
Definition: af_afade.c:60
ff_inlink_consume_frame
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition: avfilter.c:1491
FADE
#define FADE(name, type)
Definition: af_afade.c:183
FF_FILTER_FORWARD_STATUS_BACK_ALL
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
Definition: filters.h:447
ISINC
@ ISINC
Definition: af_afade.c:60
scale_samples_s32
static void scale_samples_s32(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
Definition: af_volume.c:204
scale_samples_s16
static void scale_samples_s16(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
Definition: af_volume.c:184
fade_gain
static double fade_gain(int curve, int64_t index, int64_t range, double silence, double unity)
Definition: af_afade.c:74
CUBE
#define CUBE(a)
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:790
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
pts
static int64_t pts
Definition: transcode_aac.c:644
OFFSET
#define OFFSET(x)
Definition: af_afade.c:62
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
cbrt
#define cbrt
Definition: tablegen.h:35
C
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s your new playground is ready Some little details about what s going which in turn will define variables for the build system and the C
Definition: writing_filters.txt:58
AudioFadeContext::silence
double silence
Definition: af_afade.c:41
QUAT
@ QUAT
Definition: af_afade.c:60
ff_af_acrossfade
const AVFilter ff_af_acrossfade
ff_inlink_check_available_samples
int ff_inlink_check_available_samples(AVFilterLink *link, unsigned min)
Test if enough samples are available on the link.
Definition: avfilter.c:1472
av_cold
#define av_cold
Definition: attributes.h:90
CUB
@ CUB
Definition: af_afade.c:60
QSIN
@ QSIN
Definition: af_afade.c:60
duration
int64_t duration
Definition: movenc.c:65
IHSIN
@ IHSIN
Definition: af_afade.c:60
ff_outlink_set_status
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:424
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1594
s
#define s(width, name)
Definition: cbs_vp9.c:198
TRI
@ TRI
Definition: af_afade.c:60
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition: opt.h:267
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
HSIN2
@ HSIN2
Definition: af_afade.c:60
HSIN
@ HSIN
Definition: af_afade.c:60
AV_OPT_TYPE_INT64
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
Definition: opt.h:263
filters.h
B
#define B
Definition: huffyuv.h:42
ff_null_get_audio_buffer
AVFrame * ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
get_audio_buffer() handler for filters which simply pass audio along
Definition: audio.c:41
ctx
AVFormatContext * ctx
Definition: movenc.c:49
FLAGS
#define FLAGS
Definition: af_afade.c:63
channels
channels
Definition: aptx.h:31
IQSIN
@ IQSIN
Definition: af_afade.c:60
av_rescale_q
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
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
AudioFadeContext::crossfade_samples
void(* crossfade_samples)(uint8_t **dst, uint8_t *const *cf0, uint8_t *const *cf1, int nb_samples, int channels, int curve0, int curve1)
Definition: af_afade.c:54
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
ff_inlink_consume_samples
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
Definition: avfilter.c:1511
NULL
#define NULL
Definition: coverity.c:32
AudioFadeContext::status
int status[2]
Definition: af_afade.c:44
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:713
SCALE
#define SCALE(name, type)
Definition: af_afade.c:227
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AudioFadeContext::start_sample
int64_t start_sample
Definition: af_afade.c:38
activate
filter_frame For filters that do not use the activate() callback
filter_frame
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition: dolby_e.c:1059
QSIN2
@ QSIN2
Definition: af_afade.c:60
AVFILTER_DEFINE_CLASS
#define AVFILTER_DEFINE_CLASS(fname)
Definition: filters.h:273
exp
int8_t exp
Definition: eval.c:73
ff_inlink_acknowledge_status
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1438
index
int index
Definition: gxfenc.c:90
SQU
@ SQU
Definition: af_afade.c:60
CurveType
CurveType
Definition: af_afade.c:60
TFLAGS
#define TFLAGS
Definition: af_afade.c:64
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
get_audio_buffer
static AVFrame * get_audio_buffer(AVFilterLink *inlink, int nb_samples)
Definition: avf_concat.c:214
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_acrusher.c:307
start_time
static int64_t start_time
Definition: ffplay.c:326
AudioFadeContext::curve
int curve
Definition: af_afade.c:36
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:649
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:476
AudioFadeContext::scale_samples
void(* scale_samples)(uint8_t **dst, uint8_t *const *src, int nb_samples, int channels, double unity)
Definition: af_afade.c:52
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2464
AudioFadeContext::duration
int64_t duration
Definition: af_afade.c:39
EXP
@ EXP
Definition: af_afade.c:60
ff_filter_process_command
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition: avfilter.c:901
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
M_PI
#define M_PI
Definition: mathematics.h:67
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:64
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#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:182
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:469
SINC
@ SINC
Definition: af_afade.c:60
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:450
AudioFadeContext::pts
int64_t pts
Definition: af_afade.c:46
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
AudioFadeContext::overlap
int overlap
Definition: af_afade.c:43
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
FILTER_SAMPLEFMTS_ARRAY
#define FILTER_SAMPLEFMTS_ARRAY(array)
Definition: filters.h:245
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
CBR
@ CBR
Definition: af_afade.c:60
ff_inlink_queued_samples
int ff_inlink_queued_samples(AVFilterLink *link)
Definition: avfilter.c:1466
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
AudioFadeContext::start_time
int64_t start_time
Definition: af_afade.c:40
AVFilter
Filter definition.
Definition: avfilter.h:201
LOSI
@ LOSI
Definition: af_afade.c:60
ret
ret
Definition: filter_design.txt:187
status
ov_status_e status
Definition: dnn_backend_openvino.c:100
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
avfilter.h
AudioFadeContext::passthrough
int passthrough
Definition: af_afade.c:45
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:67
FADE_PLANAR
#define FADE_PLANAR(name, type)
Definition: af_afade.c:164
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
audio.h
ff_default_get_audio_buffer
AVFrame * ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
default handler for get_audio_buffer() for audio inputs
Definition: audio.c:46
QUATR
@ QUATR
Definition: af_afade.c:60
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
int32_t
int32_t
Definition: audioconvert.c:56
ESIN
@ ESIN
Definition: af_afade.c:60
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: af_afade.c:66
ff_outlink_frame_wanted
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
AV_SAMPLE_FMT_DBL
@ AV_SAMPLE_FMT_DBL
double
Definition: samplefmt.h:61
PAR
@ PAR
Definition: af_afade.c:60
AV_SAMPLE_FMT_S32
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:59
AudioFadeContext::nb_samples
int64_t nb_samples
Definition: af_afade.c:37
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
AudioFadeContext
Definition: af_afade.c:33
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:60
src
#define src
Definition: vp8dsp.c:248
av_clipd
av_clipd
Definition: af_crystalizer.c:132
LOG
@ LOG
Definition: af_afade.c:60