FFmpeg  2.8.17
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
af_silenceremove.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001 Heikki Leinonen
3  * Copyright (c) 2001 Chris Bagwell
4  * Copyright (c) 2003 Donnie Smith
5  * Copyright (c) 2014 Paul B Mahol
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include <float.h> /* DBL_MAX */
25 
26 #include "libavutil/opt.h"
27 #include "libavutil/timestamp.h"
28 #include "audio.h"
29 #include "formats.h"
30 #include "avfilter.h"
31 #include "internal.h"
32 
39 };
40 
41 typedef struct SilenceRemoveContext {
42  const AVClass *class;
43 
45 
47  int64_t start_duration;
49 
51  int64_t stop_duration;
53 
54  double *start_holdoff;
58 
59  double *stop_holdoff;
63 
64  double *window;
65  double *window_current;
66  double *window_end;
68  double rms_sum;
69 
71  int restart;
72  int64_t next_pts;
74 
75 #define OFFSET(x) offsetof(SilenceRemoveContext, x)
76 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
77 static const AVOption silenceremove_options[] = {
78  { "start_periods", NULL, OFFSET(start_periods), AV_OPT_TYPE_INT, {.i64=0}, 0, 9000, FLAGS },
79  { "start_duration", NULL, OFFSET(start_duration), AV_OPT_TYPE_DURATION, {.i64=0}, 0, 9000, FLAGS },
80  { "start_threshold", NULL, OFFSET(start_threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX, FLAGS },
81  { "stop_periods", NULL, OFFSET(stop_periods), AV_OPT_TYPE_INT, {.i64=0}, -9000, 9000, FLAGS },
82  { "stop_duration", NULL, OFFSET(stop_duration), AV_OPT_TYPE_DURATION, {.i64=0}, 0, 9000, FLAGS },
83  { "stop_threshold", NULL, OFFSET(stop_threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX, FLAGS },
84  { "leave_silence", NULL, OFFSET(leave_silence), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS },
85  { NULL }
86 };
87 
88 AVFILTER_DEFINE_CLASS(silenceremove);
89 
90 static av_cold int init(AVFilterContext *ctx)
91 {
92  SilenceRemoveContext *s = ctx->priv;
93 
94  if (s->stop_periods < 0) {
95  s->stop_periods = -s->stop_periods;
96  s->restart = 1;
97  }
98 
99  return 0;
100 }
101 
103 {
104  memset(s->window, 0, s->window_size * sizeof(*s->window));
105 
106  s->window_current = s->window;
107  s->window_end = s->window + s->window_size;
108  s->rms_sum = 0;
109 }
110 
111 static int config_input(AVFilterLink *inlink)
112 {
113  AVFilterContext *ctx = inlink->dst;
114  SilenceRemoveContext *s = ctx->priv;
115 
116  s->window_size = (inlink->sample_rate / 50) * inlink->channels;
117  s->window = av_malloc_array(s->window_size, sizeof(*s->window));
118  if (!s->window)
119  return AVERROR(ENOMEM);
120 
121  clear_rms(s);
122 
124  AV_TIME_BASE);
125  if (s->start_duration < 0) {
126  av_log(ctx, AV_LOG_WARNING, "start duration must be non-negative\n");
128  }
129 
131  AV_TIME_BASE);
132  if (s->stop_duration < 0) {
133  av_log(ctx, AV_LOG_WARNING, "stop duration must be non-negative\n");
134  s->stop_duration = -s->stop_duration;
135  }
136 
138  sizeof(*s->start_holdoff) *
139  inlink->channels);
140  if (!s->start_holdoff)
141  return AVERROR(ENOMEM);
142 
143  s->start_holdoff_offset = 0;
144  s->start_holdoff_end = 0;
145  s->start_found_periods = 0;
146 
148  sizeof(*s->stop_holdoff) *
149  inlink->channels);
150  if (!s->stop_holdoff)
151  return AVERROR(ENOMEM);
152 
153  s->stop_holdoff_offset = 0;
154  s->stop_holdoff_end = 0;
155  s->stop_found_periods = 0;
156 
157  if (s->start_periods)
158  s->mode = SILENCE_TRIM;
159  else
160  s->mode = SILENCE_COPY;
161 
162  return 0;
163 }
164 
165 static int config_output(AVFilterLink *outlink)
166 {
167  outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
168 
169  return 0;
170 }
171 
172 static double compute_rms(SilenceRemoveContext *s, double sample)
173 {
174  double new_sum;
175 
176  new_sum = s->rms_sum;
177  new_sum -= *s->window_current;
178  new_sum += sample * sample;
179 
180  return sqrt(new_sum / s->window_size);
181 }
182 
184 {
185  s->rms_sum -= *s->window_current;
186  *s->window_current = sample * sample;
187  s->rms_sum += *s->window_current;
188 
189  s->window_current++;
190  if (s->window_current >= s->window_end)
191  s->window_current = s->window;
192 }
193 
194 static void flush(AVFrame *out, AVFilterLink *outlink,
195  int *nb_samples_written, int *ret)
196 {
197  if (*nb_samples_written) {
198  out->nb_samples = *nb_samples_written / outlink->channels;
199  *ret = ff_filter_frame(outlink, out);
200  *nb_samples_written = 0;
201  } else {
202  av_frame_free(&out);
203  }
204 }
205 
206 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
207 {
208  AVFilterContext *ctx = inlink->dst;
209  AVFilterLink *outlink = ctx->outputs[0];
210  SilenceRemoveContext *s = ctx->priv;
211  int i, j, threshold, ret = 0;
212  int nbs, nb_samples_read, nb_samples_written;
213  double *obuf, *ibuf = (double *)in->data[0];
214  AVFrame *out;
215 
216  nb_samples_read = nb_samples_written = 0;
217 
218  switch (s->mode) {
219  case SILENCE_TRIM:
220 silence_trim:
221  nbs = in->nb_samples - nb_samples_read / inlink->channels;
222  if (!nbs)
223  break;
224 
225  for (i = 0; i < nbs; i++) {
226  threshold = 0;
227  for (j = 0; j < inlink->channels; j++) {
228  threshold |= compute_rms(s, ibuf[j]) > s->start_threshold;
229  }
230 
231  if (threshold) {
232  for (j = 0; j < inlink->channels; j++) {
233  update_rms(s, *ibuf);
234  s->start_holdoff[s->start_holdoff_end++] = *ibuf++;
235  nb_samples_read++;
236  }
237 
238  if (s->start_holdoff_end >= s->start_duration * inlink->channels) {
239  if (++s->start_found_periods >= s->start_periods) {
241  goto silence_trim_flush;
242  }
243 
244  s->start_holdoff_offset = 0;
245  s->start_holdoff_end = 0;
246  }
247  } else {
248  s->start_holdoff_end = 0;
249 
250  for (j = 0; j < inlink->channels; j++)
251  update_rms(s, ibuf[j]);
252 
253  ibuf += inlink->channels;
254  nb_samples_read += inlink->channels;
255  }
256  }
257  break;
258 
259  case SILENCE_TRIM_FLUSH:
260 silence_trim_flush:
262  nbs -= nbs % inlink->channels;
263  if (!nbs)
264  break;
265 
266  out = ff_get_audio_buffer(inlink, nbs / inlink->channels);
267  if (!out) {
268  av_frame_free(&in);
269  return AVERROR(ENOMEM);
270  }
271 
272  memcpy(out->data[0], &s->start_holdoff[s->start_holdoff_offset],
273  nbs * sizeof(double));
274  s->start_holdoff_offset += nbs;
275 
276  ret = ff_filter_frame(outlink, out);
277 
279  s->start_holdoff_offset = 0;
280  s->start_holdoff_end = 0;
281  s->mode = SILENCE_COPY;
282  goto silence_copy;
283  }
284  break;
285 
286  case SILENCE_COPY:
287 silence_copy:
288  nbs = in->nb_samples - nb_samples_read / inlink->channels;
289  if (!nbs)
290  break;
291 
292  out = ff_get_audio_buffer(inlink, nbs);
293  if (!out) {
294  av_frame_free(&in);
295  return AVERROR(ENOMEM);
296  }
297  obuf = (double *)out->data[0];
298 
299  if (s->stop_periods) {
300  for (i = 0; i < nbs; i++) {
301  threshold = 1;
302  for (j = 0; j < inlink->channels; j++)
303  threshold &= compute_rms(s, ibuf[j]) > s->stop_threshold;
304 
305  if (threshold && s->stop_holdoff_end && !s->leave_silence) {
307  flush(out, outlink, &nb_samples_written, &ret);
308  goto silence_copy_flush;
309  } else if (threshold) {
310  for (j = 0; j < inlink->channels; j++) {
311  update_rms(s, *ibuf);
312  *obuf++ = *ibuf++;
313  nb_samples_read++;
314  nb_samples_written++;
315  }
316  } else if (!threshold) {
317  for (j = 0; j < inlink->channels; j++) {
318  update_rms(s, *ibuf);
319  if (s->leave_silence) {
320  *obuf++ = *ibuf;
321  nb_samples_written++;
322  }
323 
324  s->stop_holdoff[s->stop_holdoff_end++] = *ibuf++;
325  nb_samples_read++;
326  }
327 
328  if (s->stop_holdoff_end >= s->stop_duration * inlink->channels) {
329  if (++s->stop_found_periods >= s->stop_periods) {
330  s->stop_holdoff_offset = 0;
331  s->stop_holdoff_end = 0;
332 
333  if (!s->restart) {
334  s->mode = SILENCE_STOP;
335  flush(out, outlink, &nb_samples_written, &ret);
336  goto silence_stop;
337  } else {
338  s->stop_found_periods = 0;
339  s->start_found_periods = 0;
340  s->start_holdoff_offset = 0;
341  s->start_holdoff_end = 0;
342  clear_rms(s);
343  s->mode = SILENCE_TRIM;
344  flush(out, outlink, &nb_samples_written, &ret);
345  goto silence_trim;
346  }
347  }
349  flush(out, outlink, &nb_samples_written, &ret);
350  goto silence_copy_flush;
351  }
352  }
353  }
354  flush(out, outlink, &nb_samples_written, &ret);
355  } else {
356  memcpy(obuf, ibuf, sizeof(double) * nbs * inlink->channels);
357  ret = ff_filter_frame(outlink, out);
358  }
359  break;
360 
361  case SILENCE_COPY_FLUSH:
362 silence_copy_flush:
364  nbs -= nbs % inlink->channels;
365  if (!nbs)
366  break;
367 
368  out = ff_get_audio_buffer(inlink, nbs / inlink->channels);
369  if (!out) {
370  av_frame_free(&in);
371  return AVERROR(ENOMEM);
372  }
373 
374  memcpy(out->data[0], &s->stop_holdoff[s->stop_holdoff_offset],
375  nbs * sizeof(double));
376  s->stop_holdoff_offset += nbs;
377 
378  ret = ff_filter_frame(outlink, out);
379 
380  if (s->stop_holdoff_offset == s->stop_holdoff_end) {
381  s->stop_holdoff_offset = 0;
382  s->stop_holdoff_end = 0;
383  s->mode = SILENCE_COPY;
384  goto silence_copy;
385  }
386  break;
387  case SILENCE_STOP:
388 silence_stop:
389  break;
390  }
391 
392  av_frame_free(&in);
393 
394  return ret;
395 }
396 
397 static int request_frame(AVFilterLink *outlink)
398 {
399  AVFilterContext *ctx = outlink->src;
400  SilenceRemoveContext *s = ctx->priv;
401  int ret;
402 
403  ret = ff_request_frame(ctx->inputs[0]);
404  if (ret == AVERROR_EOF && (s->mode == SILENCE_COPY_FLUSH ||
405  s->mode == SILENCE_COPY)) {
406  int nbs = s->stop_holdoff_end - s->stop_holdoff_offset;
407  if (nbs) {
408  AVFrame *frame;
409 
410  frame = ff_get_audio_buffer(outlink, nbs / outlink->channels);
411  if (!frame)
412  return AVERROR(ENOMEM);
413 
414  memcpy(frame->data[0], &s->stop_holdoff[s->stop_holdoff_offset],
415  nbs * sizeof(double));
416  ret = ff_filter_frame(ctx->inputs[0], frame);
417  }
418  s->mode = SILENCE_STOP;
419  }
420  return ret;
421 }
422 
424 {
427  static const enum AVSampleFormat sample_fmts[] = {
429  };
430  int ret;
431 
432  layouts = ff_all_channel_layouts();
433  if (!layouts)
434  return AVERROR(ENOMEM);
435  ret = ff_set_common_channel_layouts(ctx, layouts);
436  if (ret < 0)
437  return ret;
438 
439  formats = ff_make_format_list(sample_fmts);
440  if (!formats)
441  return AVERROR(ENOMEM);
442  ret = ff_set_common_formats(ctx, formats);
443  if (ret < 0)
444  return ret;
445 
446  formats = ff_all_samplerates();
447  if (!formats)
448  return AVERROR(ENOMEM);
449  return ff_set_common_samplerates(ctx, formats);
450 }
451 
452 static av_cold void uninit(AVFilterContext *ctx)
453 {
454  SilenceRemoveContext *s = ctx->priv;
455 
456  av_freep(&s->start_holdoff);
457  av_freep(&s->stop_holdoff);
458  av_freep(&s->window);
459 }
460 
462  {
463  .name = "default",
464  .type = AVMEDIA_TYPE_AUDIO,
465  .config_props = config_input,
466  .filter_frame = filter_frame,
467  },
468  { NULL }
469 };
470 
472  {
473  .name = "default",
474  .type = AVMEDIA_TYPE_AUDIO,
475  .config_props = config_output,
476  .request_frame = request_frame,
477  },
478  { NULL }
479 };
480 
482  .name = "silenceremove",
483  .description = NULL_IF_CONFIG_SMALL("Remove silence."),
484  .priv_size = sizeof(SilenceRemoveContext),
485  .priv_class = &silenceremove_class,
486  .init = init,
487  .uninit = uninit,
489  .inputs = silenceremove_inputs,
490  .outputs = silenceremove_outputs,
491 };
static void flush(AVFrame *out, AVFilterLink *outlink, int *nb_samples_written, int *ret)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
#define NULL
Definition: coverity.c:32
int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *layouts)
A helper for query_formats() which sets all links to the same list of channel layouts/sample rates...
Definition: formats.c:523
const char * s
Definition: avisynth_c.h:631
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
AVOption.
Definition: opt.h:255
static const AVFilterPad silenceremove_outputs[]
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
Main libavfilter public API header.
static int config_output(AVFilterLink *outlink)
AVFilter ff_af_silenceremove
static enum AVSampleFormat formats[]
#define sample
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
#define FLAGS
const char * name
Pad name.
Definition: internal.h:69
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:641
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1158
#define av_cold
Definition: attributes.h:74
AVOptions.
timestamp utils, mostly useful for debugging/logging purposes
SilenceMode
static AVFrame * frame
static av_cold int init(AVFilterContext *ctx)
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:63
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
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:74
#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:178
void * priv
private data for use by the filter
Definition: avfilter.h:654
#define FFMAX(a, b)
Definition: common.h:90
static int query_formats(AVFilterContext *ctx)
static int config_input(AVFilterLink *inlink)
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:134
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:246
static const AVFilterPad silenceremove_inputs[]
static void clear_rms(SilenceRemoveContext *s)
static int request_frame(AVFilterLink *outlink)
AVFILTER_DEFINE_CLASS(silenceremove)
enum SilenceMode mode
Frame requests may need to loop in order to be fulfilled.
Definition: internal.h:374
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (...
Definition: formats.c:385
A list of supported channel layouts.
Definition: formats.h:85
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:59
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 av_cold void uninit(AVFilterContext *ctx)
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
static void update_rms(SilenceRemoveContext *s, double sample)
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
static double compute_rms(SilenceRemoveContext *s, double sample)
const char * name
Filter name.
Definition: avfilter.h:474
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:379
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
if(ret< 0)
Definition: vf_mcdeint.c:280
static const AVOption silenceremove_options[]
A list of supported formats for one end of a filter link.
Definition: formats.h:64
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
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
#define av_freep(p)
#define av_malloc_array(a, b)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:343
internal API functions
#define OFFSET(x)
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:225
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:530