]> git.sesse.net Git - ffmpeg/blob - libavfilter/af_silenceremove.c
Merge commit 'a70eac7a9b193e8434b5bed90bd72aa4cb688363'
[ffmpeg] / libavfilter / af_silenceremove.c
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
33 enum SilenceDetect {
34     D_PEAK,
35     D_RMS,
36 };
37
38 enum ThresholdMode {
39     T_ANY,
40     T_ALL,
41 };
42
43 enum SilenceMode {
44     SILENCE_TRIM,
45     SILENCE_TRIM_FLUSH,
46     SILENCE_COPY,
47     SILENCE_COPY_FLUSH,
48     SILENCE_STOP
49 };
50
51 typedef struct SilenceRemoveContext {
52     const AVClass *class;
53
54     enum SilenceMode mode;
55
56     int start_periods;
57     int64_t start_duration;
58     int64_t start_duration_opt;
59     double start_threshold;
60     int64_t start_silence;
61     int64_t start_silence_opt;
62     int start_mode;
63
64     int stop_periods;
65     int64_t stop_duration;
66     int64_t stop_duration_opt;
67     double stop_threshold;
68     int64_t stop_silence;
69     int64_t stop_silence_opt;
70     int stop_mode;
71
72     double *start_holdoff;
73     double *start_silence_hold;
74     size_t start_holdoff_offset;
75     size_t start_holdoff_end;
76     size_t start_silence_offset;
77     size_t start_silence_end;
78     int    start_found_periods;
79
80     double *stop_holdoff;
81     double *stop_silence_hold;
82     size_t stop_holdoff_offset;
83     size_t stop_holdoff_end;
84     size_t stop_silence_offset;
85     size_t stop_silence_end;
86     int    stop_found_periods;
87
88     double window_ratio;
89     double *window;
90     double *window_current;
91     double *window_end;
92     int window_size;
93     double sum;
94
95     int restart;
96     int64_t next_pts;
97
98     int detection;
99     void (*update)(struct SilenceRemoveContext *s, double sample);
100     double(*compute)(struct SilenceRemoveContext *s, double sample);
101 } SilenceRemoveContext;
102
103 #define OFFSET(x) offsetof(SilenceRemoveContext, x)
104 #define AF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
105
106 static const AVOption silenceremove_options[] = {
107     { "start_periods",   NULL,                                                 OFFSET(start_periods),       AV_OPT_TYPE_INT,      {.i64=0},     0,      9000, AF },
108     { "start_duration",  "set start duration of non-silence part",             OFFSET(start_duration_opt),  AV_OPT_TYPE_DURATION, {.i64=0},     0, INT32_MAX, AF },
109     { "start_threshold", "set threshold for start silence detection",          OFFSET(start_threshold),     AV_OPT_TYPE_DOUBLE,   {.dbl=0},     0,   DBL_MAX, AF },
110     { "start_silence",   "set start duration of silence part to keep",         OFFSET(start_silence_opt),   AV_OPT_TYPE_DURATION, {.i64=0},     0, INT32_MAX, AF },
111     { "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" },
112     {   "any",           0,                                                    0,                           AV_OPT_TYPE_CONST,    {.i64=T_ANY}, 0,         0, AF, "mode" },
113     {   "all",           0,                                                    0,                           AV_OPT_TYPE_CONST,    {.i64=T_ALL}, 0,         0, AF, "mode" },
114     { "stop_periods",    NULL,                                                 OFFSET(stop_periods),        AV_OPT_TYPE_INT,      {.i64=0}, -9000,      9000, AF },
115     { "stop_duration",   "set stop duration of non-silence part",              OFFSET(stop_duration_opt),   AV_OPT_TYPE_DURATION, {.i64=0},     0, INT32_MAX, AF },
116     { "stop_threshold",  "set threshold for stop silence detection",           OFFSET(stop_threshold),      AV_OPT_TYPE_DOUBLE,   {.dbl=0},     0,   DBL_MAX, AF },
117     { "stop_silence",    "set stop duration of silence part to keep",          OFFSET(stop_silence_opt),    AV_OPT_TYPE_DURATION, {.i64=0},     0, INT32_MAX, AF },
118     { "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" },
119     { "detection",       "set how silence is detected",                        OFFSET(detection),           AV_OPT_TYPE_INT,      {.i64=D_RMS}, D_PEAK,D_RMS, AF, "detection" },
120     {   "peak",          "use absolute values of samples",                     0,                           AV_OPT_TYPE_CONST,    {.i64=D_PEAK},0,         0, AF, "detection" },
121     {   "rms",           "use squared values of samples",                      0,                           AV_OPT_TYPE_CONST,    {.i64=D_RMS}, 0,         0, AF, "detection" },
122     { "window",          "set duration of window in seconds",                  OFFSET(window_ratio),        AV_OPT_TYPE_DOUBLE,   {.dbl=0.02},  0,        10, AF },
123     { NULL }
124 };
125
126 AVFILTER_DEFINE_CLASS(silenceremove);
127
128 static double compute_peak(SilenceRemoveContext *s, double sample)
129 {
130     double new_sum;
131
132     new_sum  = s->sum;
133     new_sum -= *s->window_current;
134     new_sum += fabs(sample);
135
136     return new_sum / s->window_size;
137 }
138
139 static void update_peak(SilenceRemoveContext *s, double sample)
140 {
141     s->sum -= *s->window_current;
142     *s->window_current = fabs(sample);
143     s->sum += *s->window_current;
144
145     s->window_current++;
146     if (s->window_current >= s->window_end)
147         s->window_current = s->window;
148 }
149
150 static double compute_rms(SilenceRemoveContext *s, double sample)
151 {
152     double new_sum;
153
154     new_sum  = s->sum;
155     new_sum -= *s->window_current;
156     new_sum += sample * sample;
157
158     return sqrt(new_sum / s->window_size);
159 }
160
161 static void update_rms(SilenceRemoveContext *s, double sample)
162 {
163     s->sum -= *s->window_current;
164     *s->window_current = sample * sample;
165     s->sum += *s->window_current;
166
167     s->window_current++;
168     if (s->window_current >= s->window_end)
169         s->window_current = s->window;
170 }
171
172 static av_cold int init(AVFilterContext *ctx)
173 {
174     SilenceRemoveContext *s = ctx->priv;
175
176     if (s->stop_periods < 0) {
177         s->stop_periods = -s->stop_periods;
178         s->restart = 1;
179     }
180
181     switch (s->detection) {
182     case D_PEAK:
183         s->update = update_peak;
184         s->compute = compute_peak;
185         break;
186     case D_RMS:
187         s->update = update_rms;
188         s->compute = compute_rms;
189         break;
190     }
191
192     return 0;
193 }
194
195 static void clear_window(SilenceRemoveContext *s)
196 {
197     memset(s->window, 0, s->window_size * sizeof(*s->window));
198
199     s->window_current = s->window;
200     s->window_end = s->window + s->window_size;
201     s->sum = 0;
202 }
203
204 static int config_input(AVFilterLink *inlink)
205 {
206     AVFilterContext *ctx = inlink->dst;
207     SilenceRemoveContext *s = ctx->priv;
208
209     s->window_size = FFMAX((inlink->sample_rate * s->window_ratio), 1) * inlink->channels;
210     s->window = av_malloc_array(s->window_size, sizeof(*s->window));
211     if (!s->window)
212         return AVERROR(ENOMEM);
213
214     clear_window(s);
215
216     s->start_duration = av_rescale(s->start_duration_opt, inlink->sample_rate,
217                                    AV_TIME_BASE);
218     s->start_silence  = av_rescale(s->start_silence_opt, inlink->sample_rate,
219                                    AV_TIME_BASE);
220     s->stop_duration  = av_rescale(s->stop_duration_opt, inlink->sample_rate,
221                                    AV_TIME_BASE);
222     s->stop_silence   = av_rescale(s->stop_silence_opt, inlink->sample_rate,
223                                    AV_TIME_BASE);
224
225     s->start_holdoff = av_malloc_array(FFMAX(s->start_duration, 1),
226                                        sizeof(*s->start_holdoff) *
227                                        inlink->channels);
228     if (!s->start_holdoff)
229         return AVERROR(ENOMEM);
230
231     s->start_silence_hold = av_malloc_array(FFMAX(s->start_silence, 1),
232                                             sizeof(*s->start_silence_hold) *
233                                             inlink->channels);
234     if (!s->start_silence_hold)
235         return AVERROR(ENOMEM);
236
237     s->start_holdoff_offset = 0;
238     s->start_holdoff_end    = 0;
239     s->start_found_periods  = 0;
240
241     s->stop_holdoff = av_malloc_array(FFMAX(s->stop_duration, 1),
242                                       sizeof(*s->stop_holdoff) *
243                                       inlink->channels);
244     if (!s->stop_holdoff)
245         return AVERROR(ENOMEM);
246
247     s->stop_silence_hold = av_malloc_array(FFMAX(s->stop_silence, 1),
248                                            sizeof(*s->stop_silence_hold) *
249                                            inlink->channels);
250     if (!s->stop_silence_hold)
251         return AVERROR(ENOMEM);
252
253     s->stop_holdoff_offset = 0;
254     s->stop_holdoff_end    = 0;
255     s->stop_found_periods  = 0;
256
257     if (s->start_periods)
258         s->mode = SILENCE_TRIM;
259     else
260         s->mode = SILENCE_COPY;
261
262     return 0;
263 }
264
265 static void flush(SilenceRemoveContext *s,
266                   AVFrame *out, AVFilterLink *outlink,
267                   int *nb_samples_written, int *ret, int flush_silence)
268 {
269     AVFrame *silence;
270
271     if (*nb_samples_written) {
272         out->nb_samples = *nb_samples_written / outlink->channels;
273
274         out->pts = s->next_pts;
275         s->next_pts += av_rescale_q(out->nb_samples,
276                                     (AVRational){1, outlink->sample_rate},
277                                     outlink->time_base);
278
279         *ret = ff_filter_frame(outlink, out);
280         if (*ret < 0)
281             return;
282         *nb_samples_written = 0;
283     } else {
284         av_frame_free(&out);
285     }
286
287     if (s->stop_silence_end <= 0 || !flush_silence)
288         return;
289
290     silence = ff_get_audio_buffer(outlink, s->stop_silence_end / outlink->channels);
291     if (!silence) {
292         *ret = AVERROR(ENOMEM);
293         return;
294     }
295
296     if (s->stop_silence_offset < s->stop_silence_end) {
297         memcpy(silence->data[0],
298                &s->stop_silence_hold[s->stop_silence_offset],
299                (s->stop_silence_end - s->stop_silence_offset) * sizeof(double));
300     }
301
302     if (s->stop_silence_offset > 0) {
303         memcpy(silence->data[0] + (s->stop_silence_end - s->stop_silence_offset) * sizeof(double),
304                &s->stop_silence_hold[0],
305                s->stop_silence_offset * sizeof(double));
306     }
307
308     s->stop_silence_offset = 0;
309     s->stop_silence_end = 0;
310
311     silence->pts = s->next_pts;
312     s->next_pts += av_rescale_q(silence->nb_samples,
313                                 (AVRational){1, outlink->sample_rate},
314                                 outlink->time_base);
315
316     *ret = ff_filter_frame(outlink, silence);
317 }
318
319 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
320 {
321     AVFilterContext *ctx = inlink->dst;
322     AVFilterLink *outlink = ctx->outputs[0];
323     SilenceRemoveContext *s = ctx->priv;
324     int i, j, threshold, ret = 0;
325     int nbs, nb_samples_read, nb_samples_written;
326     double *obuf, *ibuf = (double *)in->data[0];
327     AVFrame *out;
328
329     nb_samples_read = nb_samples_written = 0;
330
331     switch (s->mode) {
332     case SILENCE_TRIM:
333 silence_trim:
334         nbs = in->nb_samples - nb_samples_read / outlink->channels;
335         if (!nbs)
336             break;
337
338         for (i = 0; i < nbs; i++) {
339             if (s->start_mode == T_ANY) {
340                 threshold = 0;
341                 for (j = 0; j < outlink->channels; j++) {
342                     threshold |= s->compute(s, ibuf[j]) > s->start_threshold;
343                 }
344             } else {
345                 threshold = 1;
346                 for (j = 0; j < outlink->channels; j++) {
347                     threshold &= s->compute(s, ibuf[j]) > s->start_threshold;
348                 }
349             }
350
351             if (threshold) {
352                 for (j = 0; j < outlink->channels; j++) {
353                     s->update(s, *ibuf);
354                     s->start_holdoff[s->start_holdoff_end++] = *ibuf++;
355                 }
356                 nb_samples_read += outlink->channels;
357
358                 if (s->start_holdoff_end >= s->start_duration * outlink->channels) {
359                     if (++s->start_found_periods >= s->start_periods) {
360                         s->mode = SILENCE_TRIM_FLUSH;
361                         goto silence_trim_flush;
362                     }
363
364                     s->start_holdoff_offset = 0;
365                     s->start_holdoff_end = 0;
366                     s->start_silence_offset = 0;
367                     s->start_silence_end = 0;
368                 }
369             } else {
370                 s->start_holdoff_end = 0;
371
372                 for (j = 0; j < outlink->channels; j++) {
373                     s->update(s, ibuf[j]);
374                     if (s->start_silence) {
375                         s->start_silence_hold[s->start_silence_offset++] = ibuf[j];
376                         s->start_silence_end = FFMIN(s->start_silence_end + 1, outlink->channels * s->start_silence);
377                         if (s->start_silence_offset >= outlink->channels * s->start_silence) {
378                             s->start_silence_offset = 0;
379                         }
380                     }
381                 }
382
383                 ibuf += outlink->channels;
384                 nb_samples_read += outlink->channels;
385             }
386         }
387         break;
388
389     case SILENCE_TRIM_FLUSH:
390 silence_trim_flush:
391         nbs  = s->start_holdoff_end - s->start_holdoff_offset;
392         nbs -= nbs % outlink->channels;
393         if (!nbs)
394             break;
395
396         out = ff_get_audio_buffer(outlink, nbs / outlink->channels + s->start_silence_end / outlink->channels);
397         if (!out) {
398             av_frame_free(&in);
399             return AVERROR(ENOMEM);
400         }
401
402         if (s->start_silence_end > 0) {
403             if (s->start_silence_offset < s->start_silence_end) {
404                 memcpy(out->data[0],
405                        &s->start_silence_hold[s->start_silence_offset],
406                        (s->start_silence_end - s->start_silence_offset) * sizeof(double));
407             }
408
409             if (s->start_silence_offset > 0) {
410                 memcpy(out->data[0] + (s->start_silence_end - s->start_silence_offset) * sizeof(double),
411                        &s->start_silence_hold[0],
412                        s->start_silence_offset * sizeof(double));
413             }
414         }
415
416         memcpy(out->data[0] + s->start_silence_end * sizeof(double),
417                &s->start_holdoff[s->start_holdoff_offset],
418                nbs * sizeof(double));
419
420         out->pts = s->next_pts;
421         s->next_pts += av_rescale_q(out->nb_samples,
422                                     (AVRational){1, outlink->sample_rate},
423                                     outlink->time_base);
424
425         s->start_holdoff_offset += nbs;
426
427         ret = ff_filter_frame(outlink, out);
428
429         if (s->start_holdoff_offset == s->start_holdoff_end) {
430             s->start_holdoff_offset = 0;
431             s->start_holdoff_end = 0;
432             s->start_silence_offset = 0;
433             s->start_silence_end = 0;
434             s->mode = SILENCE_COPY;
435             goto silence_copy;
436         }
437         break;
438
439     case SILENCE_COPY:
440 silence_copy:
441         nbs = in->nb_samples - nb_samples_read / outlink->channels;
442         if (!nbs)
443             break;
444
445         out = ff_get_audio_buffer(outlink, nbs);
446         if (!out) {
447             av_frame_free(&in);
448             return AVERROR(ENOMEM);
449         }
450         obuf = (double *)out->data[0];
451
452         if (s->stop_periods) {
453             for (i = 0; i < nbs; i++) {
454                 if (s->stop_mode == T_ANY) {
455                     threshold = 0;
456                     for (j = 0; j < outlink->channels; j++) {
457                         threshold |= s->compute(s, ibuf[j]) > s->stop_threshold;
458                     }
459                 } else {
460                     threshold = 1;
461                     for (j = 0; j < outlink->channels; j++) {
462                         threshold &= s->compute(s, ibuf[j]) > s->stop_threshold;
463                     }
464                 }
465
466                 if (threshold && s->stop_holdoff_end && !s->stop_silence) {
467                     s->mode = SILENCE_COPY_FLUSH;
468                     flush(s, out, outlink, &nb_samples_written, &ret, 0);
469                     goto silence_copy_flush;
470                 } else if (threshold) {
471                     for (j = 0; j < outlink->channels; j++) {
472                         s->update(s, *ibuf);
473                         *obuf++ = *ibuf++;
474                     }
475                     nb_samples_read    += outlink->channels;
476                     nb_samples_written += outlink->channels;
477                 } else if (!threshold) {
478                     for (j = 0; j < outlink->channels; j++) {
479                         s->update(s, *ibuf);
480                         if (s->stop_silence) {
481                             s->stop_silence_hold[s->stop_silence_offset++] = *ibuf;
482                             s->stop_silence_end = FFMIN(s->stop_silence_end + 1, outlink->channels * s->stop_silence);
483                             if (s->stop_silence_offset >= outlink->channels * s->stop_silence) {
484                                 s->stop_silence_offset = 0;
485                             }
486                         }
487
488                         s->stop_holdoff[s->stop_holdoff_end++] = *ibuf++;
489                     }
490                     nb_samples_read += outlink->channels;
491
492                     if (s->stop_holdoff_end >= s->stop_duration * outlink->channels) {
493                         if (++s->stop_found_periods >= s->stop_periods) {
494                             s->stop_holdoff_offset = 0;
495                             s->stop_holdoff_end = 0;
496
497                             if (!s->restart) {
498                                 s->mode = SILENCE_STOP;
499                                 flush(s, out, outlink, &nb_samples_written, &ret, 1);
500                                 goto silence_stop;
501                             } else {
502                                 s->stop_found_periods = 0;
503                                 s->start_found_periods = 0;
504                                 s->start_holdoff_offset = 0;
505                                 s->start_holdoff_end = 0;
506                                 s->start_silence_offset = 0;
507                                 s->start_silence_end = 0;
508                                 clear_window(s);
509                                 s->mode = SILENCE_TRIM;
510                                 flush(s, out, outlink, &nb_samples_written, &ret, 1);
511                                 goto silence_trim;
512                             }
513                         }
514                         s->mode = SILENCE_COPY_FLUSH;
515                         flush(s, out, outlink, &nb_samples_written, &ret, 0);
516                         goto silence_copy_flush;
517                     }
518                 }
519             }
520             flush(s, out, outlink, &nb_samples_written, &ret, 0);
521         } else {
522             memcpy(obuf, ibuf, sizeof(double) * nbs * outlink->channels);
523
524             out->pts = s->next_pts;
525             s->next_pts += av_rescale_q(out->nb_samples,
526                                         (AVRational){1, outlink->sample_rate},
527                                         outlink->time_base);
528
529             ret = ff_filter_frame(outlink, out);
530         }
531         break;
532
533     case SILENCE_COPY_FLUSH:
534 silence_copy_flush:
535         nbs  = s->stop_holdoff_end - s->stop_holdoff_offset;
536         nbs -= nbs % outlink->channels;
537         if (!nbs)
538             break;
539
540         out = ff_get_audio_buffer(outlink, nbs / outlink->channels);
541         if (!out) {
542             av_frame_free(&in);
543             return AVERROR(ENOMEM);
544         }
545
546         memcpy(out->data[0], &s->stop_holdoff[s->stop_holdoff_offset],
547                nbs * sizeof(double));
548         s->stop_holdoff_offset += nbs;
549
550         out->pts = s->next_pts;
551         s->next_pts += av_rescale_q(out->nb_samples,
552                                     (AVRational){1, outlink->sample_rate},
553                                     outlink->time_base);
554
555         ret = ff_filter_frame(outlink, out);
556
557         if (s->stop_holdoff_offset == s->stop_holdoff_end) {
558             s->stop_holdoff_offset = 0;
559             s->stop_holdoff_end = 0;
560             s->stop_silence_offset = 0;
561             s->stop_silence_end = 0;
562             s->mode = SILENCE_COPY;
563             goto silence_copy;
564         }
565         break;
566     case SILENCE_STOP:
567 silence_stop:
568         break;
569     }
570
571     av_frame_free(&in);
572
573     return ret;
574 }
575
576 static int request_frame(AVFilterLink *outlink)
577 {
578     AVFilterContext *ctx = outlink->src;
579     SilenceRemoveContext *s = ctx->priv;
580     int ret;
581
582     ret = ff_request_frame(ctx->inputs[0]);
583     if (ret == AVERROR_EOF && (s->mode == SILENCE_COPY_FLUSH ||
584                                s->mode == SILENCE_COPY)) {
585         int nbs = s->stop_holdoff_end - s->stop_holdoff_offset;
586         if (nbs) {
587             AVFrame *frame;
588
589             frame = ff_get_audio_buffer(outlink, nbs / outlink->channels);
590             if (!frame)
591                 return AVERROR(ENOMEM);
592
593             memcpy(frame->data[0], &s->stop_holdoff[s->stop_holdoff_offset],
594                    nbs * sizeof(double));
595
596             frame->pts = s->next_pts;
597             s->next_pts += av_rescale_q(frame->nb_samples,
598                                         (AVRational){1, outlink->sample_rate},
599                                         outlink->time_base);
600
601             ret = ff_filter_frame(outlink, frame);
602         }
603         s->mode = SILENCE_STOP;
604     }
605     return ret;
606 }
607
608 static int query_formats(AVFilterContext *ctx)
609 {
610     AVFilterFormats *formats = NULL;
611     AVFilterChannelLayouts *layouts = NULL;
612     static const enum AVSampleFormat sample_fmts[] = {
613         AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_NONE
614     };
615     int ret;
616
617     layouts = ff_all_channel_counts();
618     if (!layouts)
619         return AVERROR(ENOMEM);
620     ret = ff_set_common_channel_layouts(ctx, layouts);
621     if (ret < 0)
622         return ret;
623
624     formats = ff_make_format_list(sample_fmts);
625     if (!formats)
626         return AVERROR(ENOMEM);
627     ret = ff_set_common_formats(ctx, formats);
628     if (ret < 0)
629         return ret;
630
631     formats = ff_all_samplerates();
632     if (!formats)
633         return AVERROR(ENOMEM);
634     return ff_set_common_samplerates(ctx, formats);
635 }
636
637 static av_cold void uninit(AVFilterContext *ctx)
638 {
639     SilenceRemoveContext *s = ctx->priv;
640
641     av_freep(&s->start_holdoff);
642     av_freep(&s->start_silence_hold);
643     av_freep(&s->stop_holdoff);
644     av_freep(&s->stop_silence_hold);
645     av_freep(&s->window);
646 }
647
648 static const AVFilterPad silenceremove_inputs[] = {
649     {
650         .name         = "default",
651         .type         = AVMEDIA_TYPE_AUDIO,
652         .config_props = config_input,
653         .filter_frame = filter_frame,
654     },
655     { NULL }
656 };
657
658 static const AVFilterPad silenceremove_outputs[] = {
659     {
660         .name          = "default",
661         .type          = AVMEDIA_TYPE_AUDIO,
662         .request_frame = request_frame,
663     },
664     { NULL }
665 };
666
667 AVFilter ff_af_silenceremove = {
668     .name          = "silenceremove",
669     .description   = NULL_IF_CONFIG_SMALL("Remove silence."),
670     .priv_size     = sizeof(SilenceRemoveContext),
671     .priv_class    = &silenceremove_class,
672     .init          = init,
673     .uninit        = uninit,
674     .query_formats = query_formats,
675     .inputs        = silenceremove_inputs,
676     .outputs       = silenceremove_outputs,
677 };