History

avfilter/af_silenceremove: improve trimming middle silence

Paul B Mahol committed 5 years ago

Commit 6a1bda31 parent d6f4b911 file · +8 −12Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_silenceremove.c+8−12
@@ -94,7 +94,6 @@ typedef struct SilenceRemoveContext { · 93 unmodified lines
9494 int64_t window_duration;
9595 double sum;
9696
97− int threshold;
9897 int one_period;
9998 int restart;
10099 int64_t next_pts;
@@ -435,7 +434,6 @@ static int config_input(AVFilterLink *inlink) · 334 unmodified lines
435434 AVFilterContext *ctx = inlink->dst;
436435 SilenceRemoveContext *s = ctx->priv;
437436
438− s->threshold = -1;
439437 s->next_pts = AV_NOPTS_VALUE;
440438 s->window_duration = av_rescale(s->window_duration_opt, inlink->sample_rate,
441439 AV_TIME_BASE);
@@ -629,10 +627,6 @@ silence_trim: · 187 unmodified lines
629627 }
630628 }
631629
632− if (s->threshold >= 0)
633− s->one_period = s->threshold != threshold;
634− s->threshold = threshold;
635−
636630 if (threshold) {
637631 for (j = 0; j < outlink->channels; j++) {
638632 s->update(s, in, j, nb_samples_read);
@@ -646,7 +640,8 @@ silence_trim: · 7 unmodified lines
646640 nb_samples_read++;
647641
648642 if (s->start_holdoff_end >= s->start_duration) {
649− s->start_found_periods += s->one_period;
643+ s->start_found_periods += s->one_period >= 1;
644+ s->one_period = 0;
650645 if (s->start_found_periods >= s->start_periods) {
651646 s->mode = SILENCE_TRIM_FLUSH;
652647 goto silence_trim_flush;
@@ -659,6 +654,7 @@ silence_trim: · 6 unmodified lines
659654 }
660655 } else {
661656 s->start_holdoff_end = 0;
657+ s->one_period++;
662658
663659 for (j = 0; j < outlink->channels; j++) {
664660 s->update(s, in, j, nb_samples_read);
@@ -755,13 +751,10 @@ silence_copy: · 90 unmodified lines
755751 }
756752 }
757753
758− if (s->threshold >= 0)
759− s->one_period = s->threshold != threshold;
760− s->threshold = threshold;
761−
762754 if (threshold && s->stop_holdoff_end && !s->stop_silence) {
763755 s->mode = SILENCE_COPY_FLUSH;
764756 flush(s, out, outlink, &nb_samples_written, 0);
757+ s->one_period++;
765758 goto silence_copy_flush;
766759 } else if (threshold) {
767760 for (j = 0; j < outlink->channels; j++) {
@@ -774,6 +767,7 @@ silence_copy: · 6 unmodified lines
774767 s->window_offset = 0;
775768 nb_samples_read++;
776769 nb_samples_written++;
770+ s->one_period++;
777771 } else if (!threshold) {
778772 for (j = 0; j < outlink->channels; j++) {
779773 s->update(s, in, j, nb_samples_read);
@@ -798,7 +792,8 @@ silence_copy: · 18 unmodified lines
798792 s->stop_holdoff_end++;
799793
800794 if (s->stop_holdoff_end >= s->stop_duration) {
801− s->stop_found_periods += s->one_period;
795+ s->stop_found_periods += s->one_period >= 1;
796+ s->one_period = 0;
802797 if (s->stop_found_periods >= s->stop_periods) {
803798 s->stop_holdoff_offset = 0;
804799 s->stop_holdoff_end = 0;
@@ -826,6 +821,7 @@ silence_copy: · 21 unmodified lines
826821 }
827822 }
828823 }
824+ s->one_period++;
829825 flush(s, out, outlink, &nb_samples_written, 0);
830826 } else {
831827 av_samples_copy(out->extended_data, in->extended_data,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t