FFmpeg
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/audio_fifo.h"
27 #include "libavutil/avassert.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/timestamp.h"
30 #include "audio.h"
31 #include "formats.h"
32 #include "avfilter.h"
33 #include "internal.h"
34 
38 };
39 
43 };
44 
51 };
52 
53 typedef struct SilenceRemoveContext {
54  const AVClass *class;
55 
57 
59  int64_t start_duration;
62  int64_t start_silence;
65 
67  int64_t stop_duration;
70  int64_t stop_silence;
72  int stop_mode;
73 
75 
83 
91 
94  int64_t window_duration;
95  double sum;
96 
97  int threshold;
99  int restart;
100  int64_t next_pts;
101 
103  void (*update)(struct SilenceRemoveContext *s, AVFrame *frame, int ch, int offset);
104  double (*compute)(struct SilenceRemoveContext *s, AVFrame *frame, int ch, int offset);
105  void (*copy)(struct SilenceRemoveContext *s, AVFrame *out, AVFrame *in,
106  int ch, int out_offset, int in_offset);
107 
110 
111 #define OFFSET(x) offsetof(SilenceRemoveContext, x)
112 #define AF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
113 
114 static const AVOption silenceremove_options[] = {
115  { "start_periods", "set periods of silence parts to skip from start", OFFSET(start_periods), AV_OPT_TYPE_INT, {.i64=0}, 0, 9000, AF },
116  { "start_duration", "set start duration of non-silence part", OFFSET(start_duration_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF },
117  { "start_threshold", "set threshold for start silence detection", OFFSET(start_threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX, AF },
118  { "start_silence", "set start duration of silence part to keep", OFFSET(start_silence_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF },
119  { "start_mode", "set which channel will trigger trimming from start", OFFSET(start_mode), AV_OPT_TYPE_INT, {.i64=T_ANY}, T_ANY, T_ALL, AF, "mode" },
120  { "any", 0, 0, AV_OPT_TYPE_CONST, {.i64=T_ANY}, 0, 0, AF, "mode" },
121  { "all", 0, 0, AV_OPT_TYPE_CONST, {.i64=T_ALL}, 0, 0, AF, "mode" },
122  { "stop_periods", "set periods of silence parts to skip from end", OFFSET(stop_periods), AV_OPT_TYPE_INT, {.i64=0}, -9000, 9000, AF },
123  { "stop_duration", "set stop duration of non-silence part", OFFSET(stop_duration_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF },
124  { "stop_threshold", "set threshold for stop silence detection", OFFSET(stop_threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, DBL_MAX, AF },
125  { "stop_silence", "set stop duration of silence part to keep", OFFSET(stop_silence_opt), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT32_MAX, AF },
126  { "stop_mode", "set which channel will trigger trimming from end", OFFSET(stop_mode), AV_OPT_TYPE_INT, {.i64=T_ANY}, T_ANY, T_ALL, AF, "mode" },
127  { "detection", "set how silence is detected", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=D_RMS}, D_PEAK,D_RMS, AF, "detection" },
128  { "peak", "use absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_PEAK},0, 0, AF, "detection" },
129  { "rms", "use squared values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_RMS}, 0, 0, AF, "detection" },
130  { "window", "set duration of window for silence detection", OFFSET(window_duration_opt), AV_OPT_TYPE_DURATION, {.i64=20000}, 0, 100000000, AF },
131  { NULL }
132 };
133 
134 AVFILTER_DEFINE_CLASS(silenceremove);
135 
137  int ch, int out_offset, int in_offset)
138 {
139  const double *srcp = (const double *)in->data[0];
140  const double src = srcp[in->channels * in_offset + ch];
141  double *dstp = (double *)out->data[0];
142 
143  dstp[out->channels * out_offset + ch] = src;
144 }
145 
147  int ch, int out_offset, int in_offset)
148 {
149  const double *srcp = (const double *)in->extended_data[ch];
150  const double src = srcp[in_offset];
151  double *dstp = (double *)out->extended_data[ch];
152 
153  dstp[out_offset] = src;
154 }
155 
157  int ch, int out_offset, int in_offset)
158 {
159  const float *srcp = (const float *)in->data[0];
160  const float src = srcp[in->channels * in_offset + ch];
161  float *dstp = (float *)out->data[0];
162 
163  dstp[out->channels * out_offset + ch] = src;
164 }
165 
167  int ch, int out_offset, int in_offset)
168 {
169  const float *srcp = (const float *)in->extended_data[ch];
170  const float src = srcp[in_offset];
171  float *dstp = (float *)out->extended_data[ch];
172 
173  dstp[out_offset] = src;
174 }
175 
177 {
178  const double *samples = (const double *)frame->data[0];
179  const double *wsamples = (const double *)s->window->data[0];
180  double sample = samples[frame->channels * offset + ch];
181  double wsample = wsamples[frame->channels * s->window_offset + ch];
182  double new_sum;
183 
184  new_sum = s->sum;
185  new_sum -= wsample;
186  new_sum = fmax(new_sum, 0.);
187  new_sum += fabs(sample);
188 
189  return new_sum / s->window_duration;
190 }
191 
193 {
194  const double *samples = (const double *)frame->data[0];
195  double *wsamples = (double *)s->window->data[0];
196  double sample = samples[frame->channels * offset + ch];
197  double *wsample = &wsamples[frame->channels * s->window_offset + ch];
198 
199  s->sum -= *wsample;
200  s->sum = fmax(s->sum, 0.);
201  *wsample = fabs(sample);
202  s->sum += *wsample;
203 }
204 
206 {
207  const float *samples = (const float *)frame->data[0];
208  const float *wsamples = (const float *)s->window->data[0];
209  float sample = samples[frame->channels * offset + ch];
210  float wsample = wsamples[frame->channels * s->window_offset + ch];
211  float new_sum;
212 
213  new_sum = s->sum;
214  new_sum -= wsample;
215  new_sum = fmaxf(new_sum, 0.f);
216  new_sum += fabsf(sample);
217 
218  return new_sum / s->window_duration;
219 }
220 
222 {
223  const float *samples = (const float *)frame->data[0];
224  float *wsamples = (float *)s->window->data[0];
225  float sample = samples[frame->channels * offset + ch];
226  float *wsample = &wsamples[frame->channels * s->window_offset + ch];
227 
228  s->sum -= *wsample;
229  s->sum = fmaxf(s->sum, 0.f);
230  *wsample = fabsf(sample);
231  s->sum += *wsample;
232 }
233 
235 {
236  const double *samples = (const double *)frame->data[0];
237  const double *wsamples = (const double *)s->window->data[0];
238  double sample = samples[frame->channels * offset + ch];
239  double wsample = wsamples[frame->channels * s->window_offset + ch];
240  double new_sum;
241 
242  new_sum = s->sum;
243  new_sum -= wsample;
244  new_sum = fmax(new_sum, 0.);
245  new_sum += sample * sample;
246 
247  av_assert2(new_sum >= 0.);
248  return sqrt(new_sum / s->window_duration);
249 }
250 
252 {
253  const double *samples = (const double *)frame->data[0];
254  double *wsamples = (double *)s->window->data[0];
255  double sample = samples[frame->channels * offset + ch];
256  double *wsample = &wsamples[frame->channels * s->window_offset + ch];
257 
258  s->sum -= *wsample;
259  s->sum = fmax(s->sum, 0.);
260  *wsample = sample * sample;
261  s->sum += *wsample;
262 }
263 
265 {
266  const float *samples = (const float *)frame->data[0];
267  const float *wsamples = (const float *)s->window->data[0];
268  float sample = samples[frame->channels * offset + ch];
269  float wsample = wsamples[frame->channels * s->window_offset + ch];
270  float new_sum;
271 
272  new_sum = s->sum;
273  new_sum -= wsample;
274  new_sum = fmaxf(new_sum, 0.f);
275  new_sum += sample * sample;
276 
277  av_assert2(new_sum >= 0.f);
278  return sqrtf(new_sum / s->window_duration);
279 }
280 
282 {
283  const float *samples = (const float *)frame->data[0];
284  float sample = samples[frame->channels * offset + ch];
285  float *wsamples = (float *)s->window->data[0];
286  float *wsample = &wsamples[frame->channels * s->window_offset + ch];
287 
288  s->sum -= *wsample;
289  s->sum = fmaxf(s->sum, 0.f);
290  *wsample = sample * sample;
291  s->sum += *wsample;
292 }
293 
295 {
296  const double *samples = (const double *)frame->extended_data[ch];
297  const double *wsamples = (const double *)s->window->extended_data[ch];
298  double sample = samples[offset];
299  double wsample = wsamples[s->window_offset];
300  double new_sum;
301 
302  new_sum = s->sum;
303  new_sum -= wsample;
304  new_sum = fmax(new_sum, 0.);
305  new_sum += fabs(sample);
306 
307  return new_sum / s->window_duration;
308 }
309 
311 {
312  const double *samples = (const double *)frame->extended_data[ch];
313  double *wsamples = (double *)s->window->extended_data[ch];
314  double sample = samples[offset];
315  double *wsample = &wsamples[s->window_offset];
316 
317  s->sum -= *wsample;
318  s->sum = fmax(s->sum, 0.);
319  *wsample = fabs(sample);
320  s->sum += *wsample;
321 }
322 
324 {
325  const float *samples = (const float *)frame->extended_data[ch];
326  const float *wsamples = (const float *)s->window->extended_data[ch];
327  float sample = samples[offset];
328  float wsample = wsamples[s->window_offset];
329  float new_sum;
330 
331  new_sum = s->sum;
332  new_sum -= wsample;
333  new_sum = fmaxf(new_sum, 0.f);
334  new_sum += fabsf(sample);
335 
336  return new_sum / s->window_duration;
337 }
338 
340 {
341  const float *samples = (const float *)frame->extended_data[ch];
342  float *wsamples = (float *)s->window->extended_data[ch];
343  float sample = samples[offset];
344  float *wsample = &wsamples[s->window_offset];
345 
346  s->sum -= *wsample;
347  s->sum = fmaxf(s->sum, 0.f);
348  *wsample = fabsf(sample);
349  s->sum += *wsample;
350 }
351 
353 {
354  const double *samples = (const double *)frame->extended_data[ch];
355  const double *wsamples = (const double *)s->window->extended_data[ch];
356  double sample = samples[offset];
357  double wsample = wsamples[s->window_offset];
358  double new_sum;
359 
360  new_sum = s->sum;
361  new_sum -= wsample;
362  new_sum = fmax(new_sum, 0.);
363  new_sum += sample * sample;
364 
365  av_assert2(new_sum >= 0.);
366  return sqrt(new_sum / s->window_duration);
367 }
368 
370 {
371  const double *samples = (const double *)frame->extended_data[ch];
372  double *wsamples = (double *)s->window->extended_data[ch];
373  double sample = samples[offset];
374  double *wsample = &wsamples[s->window_offset];
375 
376  s->sum -= *wsample;
377  s->sum = fmax(s->sum, 0.);
378  *wsample = sample * sample;
379  s->sum += *wsample;
380 }
381 
383 {
384  const float *samples = (const float *)frame->extended_data[ch];
385  const float *wsamples = (const float *)s->window->extended_data[ch];
386  float sample = samples[offset];
387  float wsample = wsamples[s->window_offset];
388  float new_sum;
389 
390  new_sum = s->sum;
391  new_sum -= wsample;
392  new_sum = fmaxf(new_sum, 0.f);
393  new_sum += sample * sample;
394 
395  av_assert2(new_sum >= 0.f);
396  return sqrtf(new_sum / s->window_duration);
397 }
398 
400 {
401  const float *samples = (const float *)frame->extended_data[ch];
402  float *wsamples = (float *)s->window->extended_data[ch];
403  float sample = samples[offset];
404  float *wsample = &wsamples[s->window_offset];
405 
406  s->sum -= *wsample;
407  s->sum = fmaxf(s->sum, 0.f);
408  *wsample = sample * sample;
409  s->sum += *wsample;
410 }
411 
413 {
414  SilenceRemoveContext *s = ctx->priv;
415 
416  if (s->stop_periods < 0) {
417  s->stop_periods = -s->stop_periods;
418  s->restart = 1;
419  }
420 
421  return 0;
422 }
423 
425 {
426  av_samples_set_silence(s->window->extended_data, 0, s->window_duration,
427  s->window->channels, s->window->format);
428 
429  s->window_offset = 0;
430  s->sum = 0;
431 }
432 
434 {
435  AVFilterContext *ctx = inlink->dst;
436  SilenceRemoveContext *s = ctx->priv;
437 
438  s->threshold = -1;
439  s->next_pts = AV_NOPTS_VALUE;
440  s->window_duration = av_rescale(s->window_duration_opt, inlink->sample_rate,
441  AV_TIME_BASE);
442  s->window_duration = FFMAX(1, s->window_duration);
443  s->window = ff_get_audio_buffer(ctx->outputs[0], s->window_duration);
444  if (!s->window)
445  return AVERROR(ENOMEM);
446 
447  clear_window(s);
448 
449  s->start_duration = av_rescale(s->start_duration_opt, inlink->sample_rate,
450  AV_TIME_BASE);
451  s->start_silence = av_rescale(s->start_silence_opt, inlink->sample_rate,
452  AV_TIME_BASE);
453  s->stop_duration = av_rescale(s->stop_duration_opt, inlink->sample_rate,
454  AV_TIME_BASE);
455  s->stop_silence = av_rescale(s->stop_silence_opt, inlink->sample_rate,
456  AV_TIME_BASE);
457 
458  s->start_holdoff = ff_get_audio_buffer(ctx->outputs[0],
459  FFMAX(s->start_duration, 1));
460  if (!s->start_holdoff)
461  return AVERROR(ENOMEM);
462 
463  s->start_silence_hold = ff_get_audio_buffer(ctx->outputs[0],
464  FFMAX(s->start_silence, 1));
465  if (!s->start_silence_hold)
466  return AVERROR(ENOMEM);
467 
468  s->start_holdoff_offset = 0;
469  s->start_holdoff_end = 0;
470  s->start_found_periods = 0;
471 
472  s->stop_holdoff = ff_get_audio_buffer(ctx->outputs[0],
473  FFMAX(s->stop_duration, 1));
474  if (!s->stop_holdoff)
475  return AVERROR(ENOMEM);
476 
477  s->stop_silence_hold = ff_get_audio_buffer(ctx->outputs[0],
478  FFMAX(s->stop_silence, 1));
479  if (!s->stop_silence_hold)
480  return AVERROR(ENOMEM);
481 
482  s->stop_holdoff_offset = 0;
483  s->stop_holdoff_end = 0;
484  s->stop_found_periods = 0;
485 
486  if (s->start_periods)
487  s->mode = SILENCE_TRIM;
488  else
489  s->mode = SILENCE_COPY;
490 
491  switch (inlink->format) {
492  case AV_SAMPLE_FMT_DBL:
493  s->copy = copy_double;
494  switch (s->detection) {
495  case D_PEAK:
496  s->update = update_peak_double;
497  s->compute = compute_peak_double;
498  break;
499  case D_RMS:
500  s->update = update_rms_double;
501  s->compute = compute_rms_double;
502  break;
503  }
504  break;
505  case AV_SAMPLE_FMT_FLT:
506  s->copy = copy_float;
507  switch (s->detection) {
508  case D_PEAK:
509  s->update = update_peak_float;
510  s->compute = compute_peak_float;
511  break;
512  case D_RMS:
513  s->update = update_rms_float;
514  s->compute = compute_rms_float;
515  break;
516  }
517  break;
518  case AV_SAMPLE_FMT_DBLP:
519  s->copy = copy_doublep;
520  switch (s->detection) {
521  case D_PEAK:
522  s->update = update_peak_doublep;
523  s->compute = compute_peak_doublep;
524  break;
525  case D_RMS:
526  s->update = update_rms_doublep;
527  s->compute = compute_rms_doublep;
528  break;
529  }
530  break;
531  case AV_SAMPLE_FMT_FLTP:
532  s->copy = copy_floatp;
533  switch (s->detection) {
534  case D_PEAK:
535  s->update = update_peak_floatp;
536  s->compute = compute_peak_floatp;
537  break;
538  case D_RMS:
539  s->update = update_rms_floatp;
540  s->compute = compute_rms_floatp;
541  break;
542  }
543  break;
544  default:
545  return AVERROR_BUG;
546  }
547 
548  s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, 1024);
549  if (!s->fifo)
550  return AVERROR(ENOMEM);
551 
552  return 0;
553 }
554 
556  AVFrame *out, AVFilterLink *outlink,
557  int *nb_samples_written, int flush_silence)
558 {
559  AVFrame *silence;
560 
561  if (*nb_samples_written) {
562  out->nb_samples = *nb_samples_written;
563 
564  av_audio_fifo_write(s->fifo, (void **)out->extended_data, out->nb_samples);
565  *nb_samples_written = 0;
566  }
567 
568  av_frame_free(&out);
569 
570  if (s->stop_silence_end <= 0 || !flush_silence)
571  return;
572 
573  silence = ff_get_audio_buffer(outlink, s->stop_silence_end);
574  if (!silence)
575  return;
576 
577  if (s->stop_silence_offset < s->stop_silence_end) {
578  av_samples_copy(silence->extended_data, s->stop_silence_hold->extended_data, 0,
579  s->stop_silence_offset,
580  s->stop_silence_end - s->stop_silence_offset,
581  outlink->channels, outlink->format);
582  }
583 
584  if (s->stop_silence_offset > 0) {
585  av_samples_copy(silence->extended_data, s->stop_silence_hold->extended_data,
586  s->stop_silence_end - s->stop_silence_offset,
587  0, s->stop_silence_offset,
588  outlink->channels, outlink->format);
589  }
590 
591  s->stop_silence_offset = 0;
592  s->stop_silence_end = 0;
593 
594  av_audio_fifo_write(s->fifo, (void **)silence->extended_data, silence->nb_samples);
595  av_frame_free(&silence);
596 }
597 
599 {
600  AVFilterContext *ctx = inlink->dst;
601  AVFilterLink *outlink = ctx->outputs[0];
602  SilenceRemoveContext *s = ctx->priv;
603  int nbs, nb_samples_read, nb_samples_written;
604  int i, j, threshold, ret = 0;
605  AVFrame *out;
606 
607  nb_samples_read = nb_samples_written = 0;
608 
609  if (s->next_pts == AV_NOPTS_VALUE)
610  s->next_pts = in->pts;
611 
612  switch (s->mode) {
613  case SILENCE_TRIM:
614 silence_trim:
615  nbs = in->nb_samples - nb_samples_read;
616  if (!nbs)
617  break;
618 
619  for (i = 0; i < nbs; i++) {
620  if (s->start_mode == T_ANY) {
621  threshold = 0;
622  for (j = 0; j < outlink->channels; j++) {
623  threshold |= s->compute(s, in, j, nb_samples_read) > s->start_threshold;
624  }
625  } else {
626  threshold = 1;
627  for (j = 0; j < outlink->channels; j++) {
628  threshold &= s->compute(s, in, j, nb_samples_read) > s->start_threshold;
629  }
630  }
631 
632  if (s->threshold >= 0)
633  s->one_period = s->threshold != threshold;
634  s->threshold = threshold;
635 
636  if (threshold) {
637  for (j = 0; j < outlink->channels; j++) {
638  s->update(s, in, j, nb_samples_read);
639  s->copy(s, s->start_holdoff, in, j, s->start_holdoff_end, nb_samples_read);
640  }
641 
642  s->window_offset++;
643  if (s->window_offset >= s->window_duration)
644  s->window_offset = 0;
645  s->start_holdoff_end++;
646  nb_samples_read++;
647 
648  if (s->start_holdoff_end >= s->start_duration) {
649  s->start_found_periods += s->one_period;
650  if (s->start_found_periods >= s->start_periods) {
651  s->mode = SILENCE_TRIM_FLUSH;
652  goto silence_trim_flush;
653  }
654 
655  s->start_holdoff_offset = 0;
656  s->start_holdoff_end = 0;
657  s->start_silence_offset = 0;
658  s->start_silence_end = 0;
659  }
660  } else {
661  s->start_holdoff_end = 0;
662 
663  for (j = 0; j < outlink->channels; j++) {
664  s->update(s, in, j, nb_samples_read);
665  if (s->start_silence)
666  s->copy(s, s->start_silence_hold, in, j, s->start_silence_offset, nb_samples_read);
667  }
668 
669  s->window_offset++;
670  if (s->window_offset >= s->window_duration)
671  s->window_offset = 0;
672  nb_samples_read++;
673  s->start_silence_offset++;
674 
675  if (s->start_silence) {
676  s->start_silence_end = FFMIN(s->start_silence_end + 1, s->start_silence);
677  if (s->start_silence_offset >= s->start_silence)
678  s->start_silence_offset = 0;
679  }
680  }
681  }
682  break;
683 
684  case SILENCE_TRIM_FLUSH:
685 silence_trim_flush:
686  nbs = s->start_holdoff_end - s->start_holdoff_offset;
687  if (!nbs)
688  break;
689 
690  out = ff_get_audio_buffer(outlink, nbs + s->start_silence_end);
691  if (!out) {
692  av_frame_free(&in);
693  return AVERROR(ENOMEM);
694  }
695 
696  if (s->start_silence_end > 0) {
697  if (s->start_silence_offset < s->start_silence_end) {
698  av_samples_copy(out->extended_data, s->start_silence_hold->extended_data, 0,
699  s->start_silence_offset,
700  s->start_silence_end - s->start_silence_offset,
701  outlink->channels, outlink->format);
702  }
703 
704  if (s->start_silence_offset > 0) {
705  av_samples_copy(out->extended_data, s->start_silence_hold->extended_data,
706  s->start_silence_end - s->start_silence_offset,
707  0, s->start_silence_offset,
708  outlink->channels, outlink->format);
709  }
710  }
711 
712  av_samples_copy(out->extended_data, s->start_holdoff->extended_data,
713  s->start_silence_end,
714  s->start_holdoff_offset, nbs,
715  outlink->channels, outlink->format);
716 
717  s->start_holdoff_offset += nbs;
718 
719  av_audio_fifo_write(s->fifo, (void **)out->extended_data, out->nb_samples);
720  av_frame_free(&out);
721 
722  if (s->start_holdoff_offset == s->start_holdoff_end) {
723  s->start_holdoff_offset = 0;
724  s->start_holdoff_end = 0;
725  s->start_silence_offset = 0;
726  s->start_silence_end = 0;
727  s->mode = SILENCE_COPY;
728  goto silence_copy;
729  }
730  break;
731 
732  case SILENCE_COPY:
733 silence_copy:
734  nbs = in->nb_samples - nb_samples_read;
735  if (!nbs)
736  break;
737 
738  out = ff_get_audio_buffer(outlink, nbs);
739  if (!out) {
740  av_frame_free(&in);
741  return AVERROR(ENOMEM);
742  }
743 
744  if (s->stop_periods) {
745  for (i = 0; i < nbs; i++) {
746  if (s->stop_mode == T_ANY) {
747  threshold = 0;
748  for (j = 0; j < outlink->channels; j++) {
749  threshold |= s->compute(s, in, j, nb_samples_read) > s->stop_threshold;
750  }
751  } else {
752  threshold = 1;
753  for (j = 0; j < outlink->channels; j++) {
754  threshold &= s->compute(s, in, j, nb_samples_read) > s->stop_threshold;
755  }
756  }
757 
758  if (s->threshold >= 0)
759  s->one_period = s->threshold != threshold;
760  s->threshold = threshold;
761 
762  if (threshold && s->stop_holdoff_end && !s->stop_silence) {
763  s->mode = SILENCE_COPY_FLUSH;
764  flush(s, out, outlink, &nb_samples_written, 0);
765  goto silence_copy_flush;
766  } else if (threshold) {
767  for (j = 0; j < outlink->channels; j++) {
768  s->update(s, in, j, nb_samples_read);
769  s->copy(s, out, in, j, nb_samples_written, nb_samples_read);
770  }
771 
772  s->window_offset++;
773  if (s->window_offset >= s->window_duration)
774  s->window_offset = 0;
775  nb_samples_read++;
776  nb_samples_written++;
777  } else if (!threshold) {
778  for (j = 0; j < outlink->channels; j++) {
779  s->update(s, in, j, nb_samples_read);
780  if (s->stop_silence)
781  s->copy(s, s->stop_silence_hold, in, j, s->stop_silence_offset, nb_samples_read);
782 
783  s->copy(s, s->stop_holdoff, in, j, s->stop_holdoff_end, nb_samples_read);
784  }
785 
786  if (s->stop_silence) {
787  s->stop_silence_offset++;
788  s->stop_silence_end = FFMIN(s->stop_silence_end + 1, s->stop_silence);
789  if (s->stop_silence_offset >= s->stop_silence) {
790  s->stop_silence_offset = 0;
791  }
792  }
793 
794  s->window_offset++;
795  if (s->window_offset >= s->window_duration)
796  s->window_offset = 0;
797  nb_samples_read++;
798  s->stop_holdoff_end++;
799 
800  if (s->stop_holdoff_end >= s->stop_duration) {
801  s->stop_found_periods += s->one_period;
802  if (s->stop_found_periods >= s->stop_periods) {
803  s->stop_holdoff_offset = 0;
804  s->stop_holdoff_end = 0;
805 
806  if (!s->restart) {
807  s->mode = SILENCE_STOP;
808  flush(s, out, outlink, &nb_samples_written, 1);
809  goto silence_stop;
810  } else {
811  s->stop_found_periods = 0;
812  s->start_found_periods = 0;
813  s->start_holdoff_offset = 0;
814  s->start_holdoff_end = 0;
815  s->start_silence_offset = 0;
816  s->start_silence_end = 0;
817  clear_window(s);
818  s->mode = SILENCE_TRIM;
819  flush(s, out, outlink, &nb_samples_written, 1);
820  goto silence_trim;
821  }
822  }
823  s->mode = SILENCE_COPY_FLUSH;
824  flush(s, out, outlink, &nb_samples_written, 0);
825  goto silence_copy_flush;
826  }
827  }
828  }
829  flush(s, out, outlink, &nb_samples_written, 0);
830  } else {
831  av_samples_copy(out->extended_data, in->extended_data,
832  nb_samples_written,
833  nb_samples_read, nbs,
834  outlink->channels, outlink->format);
835 
836  av_audio_fifo_write(s->fifo, (void **)out->extended_data, out->nb_samples);
837  av_frame_free(&out);
838  }
839  break;
840 
841  case SILENCE_COPY_FLUSH:
842 silence_copy_flush:
843  nbs = s->stop_holdoff_end - s->stop_holdoff_offset;
844  if (!nbs)
845  break;
846 
847  out = ff_get_audio_buffer(outlink, nbs);
848  if (!out) {
849  av_frame_free(&in);
850  return AVERROR(ENOMEM);
851  }
852 
853  av_samples_copy(out->extended_data, s->stop_holdoff->extended_data, 0,
854  s->stop_holdoff_offset, nbs,
855  outlink->channels, outlink->format);
856 
857  s->stop_holdoff_offset += nbs;
858 
859  av_audio_fifo_write(s->fifo, (void **)out->extended_data, out->nb_samples);
860  av_frame_free(&out);
861 
862  if (s->stop_holdoff_offset == s->stop_holdoff_end) {
863  s->stop_holdoff_offset = 0;
864  s->stop_holdoff_end = 0;
865  s->stop_silence_offset = 0;
866  s->stop_silence_end = 0;
867  s->mode = SILENCE_COPY;
868  goto silence_copy;
869  }
870  break;
871  case SILENCE_STOP:
872 silence_stop:
873  break;
874  default:
875  ret = AVERROR_BUG;
876  }
877 
878  av_frame_free(&in);
879 
880  if (av_audio_fifo_size(s->fifo) > 0) {
881  out = ff_get_audio_buffer(outlink, av_audio_fifo_size(s->fifo));
882  if (!out)
883  return AVERROR(ENOMEM);
884 
885  av_audio_fifo_read(s->fifo, (void **)out->extended_data, out->nb_samples);
886  out->pts = s->next_pts;
887  s->next_pts += av_rescale_q(out->nb_samples,
888  (AVRational){1, outlink->sample_rate},
889  outlink->time_base);
890 
891  ret = ff_filter_frame(outlink, out);
892  }
893 
894  return ret;
895 }
896 
897 static int request_frame(AVFilterLink *outlink)
898 {
899  AVFilterContext *ctx = outlink->src;
900  SilenceRemoveContext *s = ctx->priv;
901  int ret;
902 
903  ret = ff_request_frame(ctx->inputs[0]);
904  if (ret == AVERROR_EOF && (s->mode == SILENCE_COPY_FLUSH ||
905  s->mode == SILENCE_COPY)) {
906  int nbs = s->stop_holdoff_end - s->stop_holdoff_offset;
907  if (nbs) {
908  AVFrame *frame;
909 
910  frame = ff_get_audio_buffer(outlink, nbs);
911  if (!frame)
912  return AVERROR(ENOMEM);
913 
914  av_samples_copy(frame->extended_data, s->stop_holdoff->extended_data, 0,
915  s->stop_holdoff_offset, nbs,
916  outlink->channels, outlink->format);
917 
918  frame->pts = s->next_pts;
919  s->next_pts += av_rescale_q(frame->nb_samples,
920  (AVRational){1, outlink->sample_rate},
921  outlink->time_base);
922 
923  ret = ff_filter_frame(outlink, frame);
924  }
925  s->mode = SILENCE_STOP;
926  }
927  return ret;
928 }
929 
931 {
932  static const enum AVSampleFormat sample_fmts[] = {
936  };
938  if (ret < 0)
939  return ret;
940 
942  if (ret < 0)
943  return ret;
944 
946 }
947 
949 {
950  SilenceRemoveContext *s = ctx->priv;
951 
952  av_frame_free(&s->start_holdoff);
953  av_frame_free(&s->start_silence_hold);
954  av_frame_free(&s->stop_holdoff);
955  av_frame_free(&s->stop_silence_hold);
956  av_frame_free(&s->window);
957 
958  av_audio_fifo_free(s->fifo);
959  s->fifo = NULL;
960 }
961 
963  {
964  .name = "default",
965  .type = AVMEDIA_TYPE_AUDIO,
966  .config_props = config_input,
967  .filter_frame = filter_frame,
968  },
969 };
970 
972  {
973  .name = "default",
974  .type = AVMEDIA_TYPE_AUDIO,
975  .request_frame = request_frame,
976  },
977 };
978 
980  .name = "silenceremove",
981  .description = NULL_IF_CONFIG_SMALL("Remove silence."),
982  .priv_size = sizeof(SilenceRemoveContext),
983  .priv_class = &silenceremove_class,
984  .init = init,
985  .uninit = uninit,
989 };
av_audio_fifo_free
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
Definition: audio_fifo.c:45
compute_rms_double
static double compute_rms_double(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:234
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:88
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:69
update_rms_doublep
static void update_rms_doublep(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:369
SilenceRemoveContext::fifo
AVAudioFifo * fifo
Definition: af_silenceremove.c:108
update_rms_float
static void update_rms_float(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:281
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
out
FILE * out
Definition: movenc.c:54
SilenceRemoveContext::stop_silence_offset
size_t stop_silence_offset
Definition: af_silenceremove.c:88
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1019
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
init
static av_cold int init(AVFilterContext *ctx)
Definition: af_silenceremove.c:412
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:112
SilenceRemoveContext::start_holdoff_offset
size_t start_holdoff_offset
Definition: af_silenceremove.c:78
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: af_silenceremove.c:897
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:396
SilenceDetect
SilenceDetect
Definition: af_silenceremove.c:35
SilenceRemoveContext::stop_silence_hold
AVFrame * stop_silence_hold
Definition: af_silenceremove.c:85
AVOption
AVOption.
Definition: opt.h:247
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Definition: opt.h:238
ff_request_frame
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:421
silenceremove_inputs
static const AVFilterPad silenceremove_inputs[]
Definition: af_silenceremove.c:962
ff_set_common_all_samplerates
int ff_set_common_all_samplerates(AVFilterContext *ctx)
Equivalent to ff_set_common_samplerates(ctx, ff_all_samplerates())
Definition: formats.c:687
SilenceRemoveContext::start_duration_opt
int64_t start_duration_opt
Definition: af_silenceremove.c:60
float.h
update_peak_float
static void update_peak_float(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:221
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:153
SilenceRemoveContext::start_silence_opt
int64_t start_silence_opt
Definition: af_silenceremove.c:63
SilenceRemoveContext::stop_silence
int64_t stop_silence
Definition: af_silenceremove.c:70
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(silenceremove)
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:317
formats.h
compute_rms_float
static double compute_rms_float(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:264
AVAudioFifo
Context for an Audio FIFO Buffer.
Definition: audio_fifo.c:34
SilenceRemoveContext::detection
int detection
Definition: af_silenceremove.c:102
SilenceRemoveContext::window_offset
int window_offset
Definition: af_silenceremove.c:93
copy_floatp
static void copy_floatp(SilenceRemoveContext *s, AVFrame *out, AVFrame *in, int ch, int out_offset, int in_offset)
Definition: af_silenceremove.c:166
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
compute_peak_floatp
static double compute_peak_floatp(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:323
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
compute_peak_doublep
static double compute_peak_doublep(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:294
avassert.h
av_cold
#define av_cold
Definition: attributes.h:90
s
#define s(width, name)
Definition: cbs_vp9.c:257
flush
static void flush(SilenceRemoveContext *s, AVFrame *out, AVFilterLink *outlink, int *nb_samples_written, int flush_silence)
Definition: af_silenceremove.c:555
SilenceRemoveContext::mode
enum SilenceMode mode
Definition: af_silenceremove.c:56
SILENCE_STOP
@ SILENCE_STOP
Definition: af_silenceremove.c:50
AVFrame::channels
int channels
number of audio channels, only used for audio.
Definition: frame.h:592
av_audio_fifo_write
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
Definition: audio_fifo.c:112
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:226
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_silenceremove.c:598
ff_set_common_formats_from_list
int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_format_list(fmts))
Definition: formats.c:703
ctx
AVFormatContext * ctx
Definition: movenc.c:48
update_peak_floatp
static void update_peak_floatp(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:339
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:141
SilenceRemoveContext::start_silence_end
size_t start_silence_end
Definition: af_silenceremove.c:81
SilenceRemoveContext::start_silence_hold
AVFrame * start_silence_hold
Definition: af_silenceremove.c:77
compute_rms_doublep
static double compute_rms_doublep(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:352
f
#define f(width, name)
Definition: cbs_vp9.c:255
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:152
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_silenceremove.c:930
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
NULL
#define NULL
Definition: coverity.c:32
compute_peak_double
static double compute_peak_double(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:176
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
av_audio_fifo_alloc
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
Definition: audio_fifo.c:59
SilenceRemoveContext::stop_holdoff
AVFrame * stop_holdoff
Definition: af_silenceremove.c:84
src
#define src
Definition: vp8dsp.c:255
SilenceRemoveContext::start_silence_offset
size_t start_silence_offset
Definition: af_silenceremove.c:80
SilenceRemoveContext
Definition: af_silenceremove.c:53
SilenceRemoveContext::one_period
int one_period
Definition: af_silenceremove.c:98
SILENCE_TRIM
@ SILENCE_TRIM
Definition: af_silenceremove.c:46
SilenceRemoveContext::start_threshold
double start_threshold
Definition: af_silenceremove.c:61
ff_set_common_all_channel_counts
int ff_set_common_all_channel_counts(AVFilterContext *ctx)
Equivalent to ff_set_common_channel_layouts(ctx, ff_all_channel_counts())
Definition: formats.c:669
silenceremove_options
static const AVOption silenceremove_options[]
Definition: af_silenceremove.c:114
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_silenceremove.c:948
copy_double
static void copy_double(SilenceRemoveContext *s, AVFrame *out, AVFrame *in, int ch, int out_offset, int in_offset)
Definition: af_silenceremove.c:136
SilenceRemoveContext::window_duration_opt
int64_t window_duration_opt
Definition: af_silenceremove.c:74
SILENCE_COPY_FLUSH
@ SILENCE_COPY_FLUSH
Definition: af_silenceremove.c:49
AF
#define AF
Definition: af_silenceremove.c:112
SilenceRemoveContext::start_found_periods
int start_found_periods
Definition: af_silenceremove.c:82
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:117
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_silenceremove.c:433
fmaxf
float fmaxf(float, float)
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
sample
#define sample
Definition: flacdsp_template.c:44
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
SilenceRemoveContext::stop_holdoff_offset
size_t stop_holdoff_offset
Definition: af_silenceremove.c:86
update_peak_doublep
static void update_peak_doublep(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:310
SilenceRemoveContext::stop_periods
int stop_periods
Definition: af_silenceremove.c:66
offset
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 offset
Definition: writing_filters.txt:86
SILENCE_COPY
@ SILENCE_COPY
Definition: af_silenceremove.c:48
av_audio_fifo_size
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
Definition: audio_fifo.c:228
clear_window
static void clear_window(SilenceRemoveContext *s)
Definition: af_silenceremove.c:424
SilenceRemoveContext::sum
double sum
Definition: af_silenceremove.c:95
SilenceRemoveContext::threshold
int threshold
Definition: af_silenceremove.c:97
SILENCE_TRIM_FLUSH
@ SILENCE_TRIM_FLUSH
Definition: af_silenceremove.c:47
SilenceRemoveContext::start_holdoff_end
size_t start_holdoff_end
Definition: af_silenceremove.c:79
internal.h
av_audio_fifo_read
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
Definition: audio_fifo.c:181
av_samples_copy
int av_samples_copy(uint8_t **dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Copy samples from src to dst.
Definition: samplefmt.c:220
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
update_rms_double
static void update_rms_double(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:251
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:369
update_peak_double
static void update_peak_double(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:192
SilenceRemoveContext::stop_silence_opt
int64_t stop_silence_opt
Definition: af_silenceremove.c:71
i
int i
Definition: input.c:406
ff_af_silenceremove
const AVFilter ff_af_silenceremove
Definition: af_silenceremove.c:979
SilenceRemoveContext::stop_mode
int stop_mode
Definition: af_silenceremove.c:72
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:350
SilenceMode
SilenceMode
Definition: af_silenceremove.c:45
SilenceRemoveContext::stop_duration
int64_t stop_duration
Definition: af_silenceremove.c:67
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
audio_fifo.h
SilenceRemoveContext::stop_silence_end
size_t stop_silence_end
Definition: af_silenceremove.c:89
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
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:128
SilenceRemoveContext::stop_found_periods
int stop_found_periods
Definition: af_silenceremove.c:90
update_rms_floatp
static void update_rms_floatp(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:399
SilenceRemoveContext::start_mode
int start_mode
Definition: af_silenceremove.c:64
SilenceRemoveContext::update
void(* update)(struct SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:103
SilenceRemoveContext::compute
double(* compute)(struct SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:104
av_samples_set_silence
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
Definition: samplefmt.c:244
AVFilter
Filter definition.
Definition: avfilter.h:149
SilenceRemoveContext::stop_threshold
double stop_threshold
Definition: af_silenceremove.c:69
ret
ret
Definition: filter_design.txt:187
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
SilenceRemoveContext::restart
int restart
Definition: af_silenceremove.c:99
SilenceRemoveContext::window_duration
int64_t window_duration
Definition: af_silenceremove.c:94
compute_peak_float
static double compute_peak_float(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:205
fmax
double fmax(double, double)
D_PEAK
@ D_PEAK
Definition: af_silenceremove.c:36
OFFSET
#define OFFSET(x)
Definition: af_silenceremove.c:111
SilenceRemoveContext::window
AVFrame * window
Definition: af_silenceremove.c:92
SilenceRemoveContext::start_periods
int start_periods
Definition: af_silenceremove.c:58
copy_doublep
static void copy_doublep(SilenceRemoveContext *s, AVFrame *out, AVFrame *in, int ch, int out_offset, int in_offset)
Definition: af_silenceremove.c:146
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:70
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
AVFilterContext
An instance of a filter.
Definition: avfilter.h:346
ThresholdMode
ThresholdMode
Definition: af_silenceremove.c:40
audio.h
SilenceRemoveContext::stop_duration_opt
int64_t stop_duration_opt
Definition: af_silenceremove.c:68
SilenceRemoveContext::start_silence
int64_t start_silence
Definition: af_silenceremove.c:62
compute_rms_floatp
static double compute_rms_floatp(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
Definition: af_silenceremove.c:382
SilenceRemoveContext::copy
void(* copy)(struct SilenceRemoveContext *s, AVFrame *out, AVFrame *in, int ch, int out_offset, int in_offset)
Definition: af_silenceremove.c:105
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:153
silenceremove_outputs
static const AVFilterPad silenceremove_outputs[]
Definition: af_silenceremove.c:971
SilenceRemoveContext::start_holdoff
AVFrame * start_holdoff
Definition: af_silenceremove.c:76
timestamp.h
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
copy_float
static void copy_float(SilenceRemoveContext *s, AVFrame *out, AVFrame *in, int ch, int out_offset, int in_offset)
Definition: af_silenceremove.c:156
T_ALL
@ T_ALL
Definition: af_silenceremove.c:42
AV_SAMPLE_FMT_DBL
@ AV_SAMPLE_FMT_DBL
double
Definition: samplefmt.h:64
D_RMS
@ D_RMS
Definition: af_silenceremove.c:37
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
SilenceRemoveContext::stop_holdoff_end
size_t stop_holdoff_end
Definition: af_silenceremove.c:87
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:63
SilenceRemoveContext::start_duration
int64_t start_duration
Definition: af_silenceremove.c:59
T_ANY
@ T_ANY
Definition: af_silenceremove.c:41
SilenceRemoveContext::next_pts
int64_t next_pts
Definition: af_silenceremove.c:100