FFmpeg  4.0
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_ratio;
65  double *window;
66  double *window_current;
67  double *window_end;
69  double sum;
70 
72  int restart;
73  int64_t next_pts;
74 
75  int detection;
76  void (*update)(struct SilenceRemoveContext *s, double sample);
77  double(*compute)(struct SilenceRemoveContext *s, double sample);
79 
80 #define OFFSET(x) offsetof(SilenceRemoveContext, x)
81 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
82 static const AVOption silenceremove_options[] = {
83  { "start_periods", NULL, OFFSET(start_periods), AV_OPT_TYPE_INT, {.i64=0}, 0, 9000, FLAGS },
84  { "start_duration", NULL, OFFSET(start_duration), AV_OPT_TYPE_DURATION, {.i64=0}, 0, 9000, FLAGS },
85  { "start_threshold", NULL, OFFSET(start_threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX, FLAGS },
86  { "stop_periods", NULL, OFFSET(stop_periods), AV_OPT_TYPE_INT, {.i64=0}, -9000, 9000, FLAGS },
87  { "stop_duration", NULL, OFFSET(stop_duration), AV_OPT_TYPE_DURATION, {.i64=0}, 0, 9000, FLAGS },
88  { "stop_threshold", NULL, OFFSET(stop_threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX, FLAGS },
89  { "leave_silence", NULL, OFFSET(leave_silence), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
90  { "detection", NULL, OFFSET(detection), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "detection" },
91  { "peak", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "detection" },
92  { "rms", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "detection" },
93  { "window", NULL, OFFSET(window_ratio), AV_OPT_TYPE_DOUBLE, {.dbl=0.02}, 0, 10, FLAGS },
94  { NULL }
95 };
96 
97 AVFILTER_DEFINE_CLASS(silenceremove);
98 
99 static double compute_peak(SilenceRemoveContext *s, double sample)
100 {
101  double new_sum;
102 
103  new_sum = s->sum;
104  new_sum -= *s->window_current;
105  new_sum += fabs(sample);
106 
107  return new_sum / s->window_size;
108 }
109 
111 {
112  s->sum -= *s->window_current;
113  *s->window_current = fabs(sample);
114  s->sum += *s->window_current;
115 
116  s->window_current++;
117  if (s->window_current >= s->window_end)
118  s->window_current = s->window;
119 }
120 
121 static double compute_rms(SilenceRemoveContext *s, double sample)
122 {
123  double new_sum;
124 
125  new_sum = s->sum;
126  new_sum -= *s->window_current;
127  new_sum += sample * sample;
128 
129  return sqrt(new_sum / s->window_size);
130 }
131 
133 {
134  s->sum -= *s->window_current;
135  *s->window_current = sample * sample;
136  s->sum += *s->window_current;
137 
138  s->window_current++;
139  if (s->window_current >= s->window_end)
140  s->window_current = s->window;
141 }
142 
144 {
145  SilenceRemoveContext *s = ctx->priv;
146 
147  if (s->stop_periods < 0) {
148  s->stop_periods = -s->stop_periods;
149  s->restart = 1;
150  }
151 
152  switch (s->detection) {
153  case 0:
154  s->update = update_peak;
155  s->compute = compute_peak;
156  break;
157  case 1:
158  s->update = update_rms;
159  s->compute = compute_rms;
160  break;
161  };
162 
163  return 0;
164 }
165 
167 {
168  memset(s->window, 0, s->window_size * sizeof(*s->window));
169 
170  s->window_current = s->window;
171  s->window_end = s->window + s->window_size;
172  s->sum = 0;
173 }
174 
175 static int config_input(AVFilterLink *inlink)
176 {
177  AVFilterContext *ctx = inlink->dst;
178  SilenceRemoveContext *s = ctx->priv;
179 
180  s->window_size = FFMAX((inlink->sample_rate * s->window_ratio), 1) * inlink->channels;
181  s->window = av_malloc_array(s->window_size, sizeof(*s->window));
182  if (!s->window)
183  return AVERROR(ENOMEM);
184 
185  clear_window(s);
186 
188  AV_TIME_BASE);
189  if (s->start_duration < 0) {
190  av_log(ctx, AV_LOG_WARNING, "start duration must be non-negative\n");
192  }
193 
195  AV_TIME_BASE);
196  if (s->stop_duration < 0) {
197  av_log(ctx, AV_LOG_WARNING, "stop duration must be non-negative\n");
198  s->stop_duration = -s->stop_duration;
199  }
200 
202  sizeof(*s->start_holdoff) *
203  inlink->channels);
204  if (!s->start_holdoff)
205  return AVERROR(ENOMEM);
206 
207  s->start_holdoff_offset = 0;
208  s->start_holdoff_end = 0;
209  s->start_found_periods = 0;
210 
212  sizeof(*s->stop_holdoff) *
213  inlink->channels);
214  if (!s->stop_holdoff)
215  return AVERROR(ENOMEM);
216 
217  s->stop_holdoff_offset = 0;
218  s->stop_holdoff_end = 0;
219  s->stop_found_periods = 0;
220 
221  if (s->start_periods)
222  s->mode = SILENCE_TRIM;
223  else
224  s->mode = SILENCE_COPY;
225 
226  return 0;
227 }
228 
230  AVFrame *out, AVFilterLink *outlink,
231  int *nb_samples_written, int *ret)
232 {
233  if (*nb_samples_written) {
234  out->nb_samples = *nb_samples_written / outlink->channels;
235 
236  out->pts = s->next_pts;
237  s->next_pts += av_rescale_q(out->nb_samples,
238  (AVRational){1, outlink->sample_rate},
239  outlink->time_base);
240 
241  *ret = ff_filter_frame(outlink, out);
242  *nb_samples_written = 0;
243  } else {
244  av_frame_free(&out);
245  }
246 }
247 
248 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
249 {
250  AVFilterContext *ctx = inlink->dst;
251  AVFilterLink *outlink = ctx->outputs[0];
252  SilenceRemoveContext *s = ctx->priv;
253  int i, j, threshold, ret = 0;
254  int nbs, nb_samples_read, nb_samples_written;
255  double *obuf, *ibuf = (double *)in->data[0];
256  AVFrame *out;
257 
258  nb_samples_read = nb_samples_written = 0;
259 
260  switch (s->mode) {
261  case SILENCE_TRIM:
262 silence_trim:
263  nbs = in->nb_samples - nb_samples_read / inlink->channels;
264  if (!nbs)
265  break;
266 
267  for (i = 0; i < nbs; i++) {
268  threshold = 0;
269  for (j = 0; j < inlink->channels; j++) {
270  threshold |= s->compute(s, ibuf[j]) > s->start_threshold;
271  }
272 
273  if (threshold) {
274  for (j = 0; j < inlink->channels; j++) {
275  s->update(s, *ibuf);
276  s->start_holdoff[s->start_holdoff_end++] = *ibuf++;
277  }
278  nb_samples_read += inlink->channels;
279 
280  if (s->start_holdoff_end >= s->start_duration * inlink->channels) {
281  if (++s->start_found_periods >= s->start_periods) {
283  goto silence_trim_flush;
284  }
285 
286  s->start_holdoff_offset = 0;
287  s->start_holdoff_end = 0;
288  }
289  } else {
290  s->start_holdoff_end = 0;
291 
292  for (j = 0; j < inlink->channels; j++)
293  s->update(s, ibuf[j]);
294 
295  ibuf += inlink->channels;
296  nb_samples_read += inlink->channels;
297  }
298  }
299  break;
300 
301  case SILENCE_TRIM_FLUSH:
302 silence_trim_flush:
304  nbs -= nbs % inlink->channels;
305  if (!nbs)
306  break;
307 
308  out = ff_get_audio_buffer(inlink, nbs / inlink->channels);
309  if (!out) {
310  av_frame_free(&in);
311  return AVERROR(ENOMEM);
312  }
313 
314  memcpy(out->data[0], &s->start_holdoff[s->start_holdoff_offset],
315  nbs * sizeof(double));
316 
317  out->pts = s->next_pts;
318  s->next_pts += av_rescale_q(out->nb_samples,
319  (AVRational){1, outlink->sample_rate},
320  outlink->time_base);
321 
322  s->start_holdoff_offset += nbs;
323 
324  ret = ff_filter_frame(outlink, out);
325 
327  s->start_holdoff_offset = 0;
328  s->start_holdoff_end = 0;
329  s->mode = SILENCE_COPY;
330  goto silence_copy;
331  }
332  break;
333 
334  case SILENCE_COPY:
335 silence_copy:
336  nbs = in->nb_samples - nb_samples_read / inlink->channels;
337  if (!nbs)
338  break;
339 
340  out = ff_get_audio_buffer(inlink, nbs);
341  if (!out) {
342  av_frame_free(&in);
343  return AVERROR(ENOMEM);
344  }
345  obuf = (double *)out->data[0];
346 
347  if (s->stop_periods) {
348  for (i = 0; i < nbs; i++) {
349  threshold = 1;
350  for (j = 0; j < inlink->channels; j++)
351  threshold &= s->compute(s, ibuf[j]) > s->stop_threshold;
352 
353  if (threshold && s->stop_holdoff_end && !s->leave_silence) {
355  flush(s, out, outlink, &nb_samples_written, &ret);
356  goto silence_copy_flush;
357  } else if (threshold) {
358  for (j = 0; j < inlink->channels; j++) {
359  s->update(s, *ibuf);
360  *obuf++ = *ibuf++;
361  }
362  nb_samples_read += inlink->channels;
363  nb_samples_written += inlink->channels;
364  } else if (!threshold) {
365  for (j = 0; j < inlink->channels; j++) {
366  s->update(s, *ibuf);
367  if (s->leave_silence) {
368  *obuf++ = *ibuf;
369  nb_samples_written++;
370  }
371 
372  s->stop_holdoff[s->stop_holdoff_end++] = *ibuf++;
373  }
374  nb_samples_read += inlink->channels;
375 
376  if (s->stop_holdoff_end >= s->stop_duration * inlink->channels) {
377  if (++s->stop_found_periods >= s->stop_periods) {
378  s->stop_holdoff_offset = 0;
379  s->stop_holdoff_end = 0;
380 
381  if (!s->restart) {
382  s->mode = SILENCE_STOP;
383  flush(s, out, outlink, &nb_samples_written, &ret);
384  goto silence_stop;
385  } else {
386  s->stop_found_periods = 0;
387  s->start_found_periods = 0;
388  s->start_holdoff_offset = 0;
389  s->start_holdoff_end = 0;
390  clear_window(s);
391  s->mode = SILENCE_TRIM;
392  flush(s, out, outlink, &nb_samples_written, &ret);
393  goto silence_trim;
394  }
395  }
397  flush(s, out, outlink, &nb_samples_written, &ret);
398  goto silence_copy_flush;
399  }
400  }
401  }
402  flush(s, out, outlink, &nb_samples_written, &ret);
403  } else {
404  memcpy(obuf, ibuf, sizeof(double) * nbs * inlink->channels);
405 
406  out->pts = s->next_pts;
407  s->next_pts += av_rescale_q(out->nb_samples,
408  (AVRational){1, outlink->sample_rate},
409  outlink->time_base);
410 
411  ret = ff_filter_frame(outlink, out);
412  }
413  break;
414 
415  case SILENCE_COPY_FLUSH:
416 silence_copy_flush:
418  nbs -= nbs % inlink->channels;
419  if (!nbs)
420  break;
421 
422  out = ff_get_audio_buffer(inlink, nbs / inlink->channels);
423  if (!out) {
424  av_frame_free(&in);
425  return AVERROR(ENOMEM);
426  }
427 
428  memcpy(out->data[0], &s->stop_holdoff[s->stop_holdoff_offset],
429  nbs * sizeof(double));
430  s->stop_holdoff_offset += nbs;
431 
432  out->pts = s->next_pts;
433  s->next_pts += av_rescale_q(out->nb_samples,
434  (AVRational){1, outlink->sample_rate},
435  outlink->time_base);
436 
437  ret = ff_filter_frame(outlink, out);
438 
439  if (s->stop_holdoff_offset == s->stop_holdoff_end) {
440  s->stop_holdoff_offset = 0;
441  s->stop_holdoff_end = 0;
442  s->mode = SILENCE_COPY;
443  goto silence_copy;
444  }
445  break;
446  case SILENCE_STOP:
447 silence_stop:
448  break;
449  }
450 
451  av_frame_free(&in);
452 
453  return ret;
454 }
455 
456 static int request_frame(AVFilterLink *outlink)
457 {
458  AVFilterContext *ctx = outlink->src;
459  SilenceRemoveContext *s = ctx->priv;
460  int ret;
461 
462  ret = ff_request_frame(ctx->inputs[0]);
463  if (ret == AVERROR_EOF && (s->mode == SILENCE_COPY_FLUSH ||
464  s->mode == SILENCE_COPY)) {
465  int nbs = s->stop_holdoff_end - s->stop_holdoff_offset;
466  if (nbs) {
467  AVFrame *frame;
468 
469  frame = ff_get_audio_buffer(outlink, nbs / outlink->channels);
470  if (!frame)
471  return AVERROR(ENOMEM);
472 
473  memcpy(frame->data[0], &s->stop_holdoff[s->stop_holdoff_offset],
474  nbs * sizeof(double));
475 
476  frame->pts = s->next_pts;
477  s->next_pts += av_rescale_q(frame->nb_samples,
478  (AVRational){1, outlink->sample_rate},
479  outlink->time_base);
480 
481  ret = ff_filter_frame(outlink, frame);
482  }
483  s->mode = SILENCE_STOP;
484  }
485  return ret;
486 }
487 
489 {
492  static const enum AVSampleFormat sample_fmts[] = {
494  };
495  int ret;
496 
497  layouts = ff_all_channel_counts();
498  if (!layouts)
499  return AVERROR(ENOMEM);
500  ret = ff_set_common_channel_layouts(ctx, layouts);
501  if (ret < 0)
502  return ret;
503 
504  formats = ff_make_format_list(sample_fmts);
505  if (!formats)
506  return AVERROR(ENOMEM);
507  ret = ff_set_common_formats(ctx, formats);
508  if (ret < 0)
509  return ret;
510 
511  formats = ff_all_samplerates();
512  if (!formats)
513  return AVERROR(ENOMEM);
514  return ff_set_common_samplerates(ctx, formats);
515 }
516 
518 {
519  SilenceRemoveContext *s = ctx->priv;
520 
521  av_freep(&s->start_holdoff);
522  av_freep(&s->stop_holdoff);
523  av_freep(&s->window);
524 }
525 
527  {
528  .name = "default",
529  .type = AVMEDIA_TYPE_AUDIO,
530  .config_props = config_input,
531  .filter_frame = filter_frame,
532  },
533  { NULL }
534 };
535 
537  {
538  .name = "default",
539  .type = AVMEDIA_TYPE_AUDIO,
540  .request_frame = request_frame,
541  },
542  { NULL }
543 };
544 
546  .name = "silenceremove",
547  .description = NULL_IF_CONFIG_SMALL("Remove silence."),
548  .priv_size = sizeof(SilenceRemoveContext),
549  .priv_class = &silenceremove_class,
550  .init = init,
551  .uninit = uninit,
553  .inputs = silenceremove_inputs,
554  .outputs = silenceremove_outputs,
555 };
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:549
const char * s
Definition: avisynth_c.h:768
void(* update)(struct SilenceRemoveContext *s, double sample)
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
AVOption.
Definition: opt.h:246
static const AVFilterPad silenceremove_outputs[]
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
Main libavfilter public API header.
AVFilter ff_af_silenceremove
#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:60
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
#define av_cold
Definition: attributes.h:82
AVOptions.
timestamp utils, mostly useful for debugging/logging purposes
SilenceMode
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:311
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:54
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
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:568
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:86
#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:202
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
void * priv
private data for use by the filter
Definition: avfilter.h:353
#define FFMAX(a, b)
Definition: common.h:94
double(* compute)(struct SilenceRemoveContext *s, double sample)
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:129
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
static const AVFilterPad silenceremove_inputs[]
AVFormatContext * ctx
Definition: movenc.c:48
static int request_frame(AVFilterLink *outlink)
AVFILTER_DEFINE_CLASS(silenceremove)
enum SilenceMode mode
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
if(ret< 0)
Definition: vf_mcdeint.c:279
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
A list of supported channel layouts.
Definition: formats.h:85
static void flush(SilenceRemoveContext *s, AVFrame *out, AVFilterLink *outlink, int *nb_samples_written, int *ret)
static double compute_peak(SilenceRemoveContext *s, double sample)
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
typedef void(RENAME(mix_any_func_type))
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_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:144
static void update_rms(SilenceRemoveContext *s, double sample)
Rational number (pair of numerator and denominator).
Definition: rational.h:58
static double compute_rms(SilenceRemoveContext *s, double sample)
static void clear_window(SilenceRemoveContext *s)
const char * name
Filter name.
Definition: avfilter.h:148
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:232
static void update_peak(SilenceRemoveContext *s, double sample)
static const AVOption silenceremove_options[]
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:338
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
FILE * out
Definition: movenc.c:54
#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:407
formats
Definition: signature.h:48
internal API functions
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition...
Definition: formats.c:410
#define OFFSET(x)
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:284
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:556