You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

678 lines
23KB

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