Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -69,6 +69,8 @@ typedef struct SilenceRemoveContext { · 68 unmodified lines | |||
| 69 | int64_t stop_silence_opt; | 69 | int64_t stop_silence_opt; |
| 70 | int stop_mode; | 70 | int stop_mode; |
| 71 | 71 | ||
| 72 | int64_t window_duration_opt; | ||
| 73 | |||
| 72 | AVFrame *start_holdoff; | 74 | AVFrame *start_holdoff; |
| 73 | AVFrame *start_silence_hold; | 75 | AVFrame *start_silence_hold; |
| 74 | size_t start_holdoff_offset; | 76 | size_t start_holdoff_offset; |
| @@ -85,10 +87,9 @@ typedef struct SilenceRemoveContext { · 10 unmodified lines | |||
| 85 | size_t stop_silence_end; | 87 | size_t stop_silence_end; |
| 86 | int stop_found_periods; | 88 | int stop_found_periods; |
| 87 | 89 | ||
| 88 | double window_ratio; | ||
| 89 | AVFrame *window; | 90 | AVFrame *window; |
| 90 | int window_offset; | 91 | int window_offset; |
| 91 | int window_size; | 92 | int64_t window_duration; |
| 92 | double sum; | 93 | double sum; |
| 93 | 94 | ||
| 94 | int restart; | 95 | int restart; |
| @@ -120,7 +121,7 @@ static const AVOption silenceremove_options[] = { · 25 unmodified lines | |||
| 120 | { "detection", "set how silence is detected", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=D_RMS}, D_PEAK,D_RMS, AF, "detection" }, | 121 | { "detection", "set how silence is detected", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=D_RMS}, D_PEAK,D_RMS, AF, "detection" }, |
| 121 | { "peak", "use absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_PEAK},0, 0, AF, "detection" }, | 122 | { "peak", "use absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_PEAK},0, 0, AF, "detection" }, |
| 122 | { "rms", "use squared values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_RMS}, 0, 0, AF, "detection" }, | 123 | { "rms", "use squared values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_RMS}, 0, 0, AF, "detection" }, |
| 123 | { "window", "set duration of window in seconds", OFFSET(window_ratio), AV_OPT_TYPE_DOUBLE, {.dbl=0.02}, 0, 10, AF }, | 124 | { "window", "set duration of window for silence detection", OFFSET(window_duration_opt), AV_OPT_TYPE_DURATION, {.i64=20000}, 0, 100000000, AF }, |
| 124 | { NULL } | 125 | { NULL } |
| 125 | }; | 126 | }; |
| 126 | 127 | ||
| @@ -178,7 +179,7 @@ static double compute_peak_double(SilenceRemoveContext *s, AVFrame *frame, int c · 51 unmodified lines | |||
| 178 | new_sum -= wsample; | 179 | new_sum -= wsample; |
| 179 | new_sum += fabs(sample); | 180 | new_sum += fabs(sample); |
| 180 | 181 | ||
| 181 | return new_sum / s->window_size; | 182 | return new_sum / s->window_duration; |
| 182 | } | 183 | } |
| 183 | 184 | ||
| 184 | static void update_peak_double(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) | 185 | static void update_peak_double(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) |
| @@ -205,7 +206,7 @@ static double compute_peak_float(SilenceRemoveContext *s, AVFrame *frame, int ch · 20 unmodified lines | |||
| 205 | new_sum -= wsample; | 206 | new_sum -= wsample; |
| 206 | new_sum += fabsf(sample); | 207 | new_sum += fabsf(sample); |
| 207 | 208 | ||
| 208 | return new_sum / s->window_size; | 209 | return new_sum / s->window_duration; |
| 209 | } | 210 | } |
| 210 | 211 | ||
| 211 | static void update_peak_float(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) | 212 | static void update_peak_float(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) |
| @@ -232,7 +233,7 @@ static double compute_rms_double(SilenceRemoveContext *s, AVFrame *frame, int ch · 20 unmodified lines | |||
| 232 | new_sum -= wsample; | 233 | new_sum -= wsample; |
| 233 | new_sum += sample * sample; | 234 | new_sum += sample * sample; |
| 234 | 235 | ||
| 235 | return sqrt(new_sum / s->window_size); | 236 | return sqrt(new_sum / s->window_duration); |
| 236 | } | 237 | } |
| 237 | 238 | ||
| 238 | static void update_rms_double(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) | 239 | static void update_rms_double(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) |
| @@ -259,7 +260,7 @@ static double compute_rms_float(SilenceRemoveContext *s, AVFrame *frame, int ch, · 20 unmodified lines | |||
| 259 | new_sum -= wsample; | 260 | new_sum -= wsample; |
| 260 | new_sum += sample * sample; | 261 | new_sum += sample * sample; |
| 261 | 262 | ||
| 262 | return sqrtf(new_sum / s->window_size); | 263 | return sqrtf(new_sum / s->window_duration); |
| 263 | } | 264 | } |
| 264 | 265 | ||
| 265 | static void update_rms_float(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) | 266 | static void update_rms_float(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) |
| @@ -286,7 +287,7 @@ static double compute_peak_doublep(SilenceRemoveContext *s, AVFrame *frame, int · 20 unmodified lines | |||
| 286 | new_sum -= wsample; | 287 | new_sum -= wsample; |
| 287 | new_sum += fabs(sample); | 288 | new_sum += fabs(sample); |
| 288 | 289 | ||
| 289 | return new_sum / s->window_size; | 290 | return new_sum / s->window_duration; |
| 290 | } | 291 | } |
| 291 | 292 | ||
| 292 | static void update_peak_doublep(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) | 293 | static void update_peak_doublep(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) |
| @@ -313,7 +314,7 @@ static double compute_peak_floatp(SilenceRemoveContext *s, AVFrame *frame, int c · 20 unmodified lines | |||
| 313 | new_sum -= wsample; | 314 | new_sum -= wsample; |
| 314 | new_sum += fabsf(sample); | 315 | new_sum += fabsf(sample); |
| 315 | 316 | ||
| 316 | return new_sum / s->window_size; | 317 | return new_sum / s->window_duration; |
| 317 | } | 318 | } |
| 318 | 319 | ||
| 319 | static void update_peak_floatp(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) | 320 | static void update_peak_floatp(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) |
| @@ -340,7 +341,7 @@ static double compute_rms_doublep(SilenceRemoveContext *s, AVFrame *frame, int c · 20 unmodified lines | |||
| 340 | new_sum -= wsample; | 341 | new_sum -= wsample; |
| 341 | new_sum += sample * sample; | 342 | new_sum += sample * sample; |
| 342 | 343 | ||
| 343 | return sqrt(new_sum / s->window_size); | 344 | return sqrt(new_sum / s->window_duration); |
| 344 | } | 345 | } |
| 345 | 346 | ||
| 346 | static void update_rms_doublep(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) | 347 | static void update_rms_doublep(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) |
| @@ -367,7 +368,7 @@ static double compute_rms_floatp(SilenceRemoveContext *s, AVFrame *frame, int ch · 20 unmodified lines | |||
| 367 | new_sum -= wsample; | 368 | new_sum -= wsample; |
| 368 | new_sum += sample * sample; | 369 | new_sum += sample * sample; |
| 369 | 370 | ||
| 370 | return sqrtf(new_sum / s->window_size); | 371 | return sqrtf(new_sum / s->window_duration); |
| 371 | } | 372 | } |
| 372 | 373 | ||
| 373 | static void update_rms_floatp(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) | 374 | static void update_rms_floatp(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset) |
| @@ -396,7 +397,7 @@ static av_cold int init(AVFilterContext *ctx) · 22 unmodified lines | |||
| 396 | 397 | ||
| 397 | static void clear_window(SilenceRemoveContext *s) | 398 | static void clear_window(SilenceRemoveContext *s) |
| 398 | { | 399 | { |
| 399 | av_samples_set_silence(s->window->extended_data, 0, s->window_size, | 400 | av_samples_set_silence(s->window->extended_data, 0, s->window_duration, |
| 400 | s->window->channels, s->window->format); | 401 | s->window->channels, s->window->format); |
| 401 | 402 | ||
| 402 | s->window_offset = 0; | 403 | s->window_offset = 0; |
| @@ -409,8 +410,10 @@ static int config_input(AVFilterLink *inlink) · 6 unmodified lines | |||
| 409 | SilenceRemoveContext *s = ctx->priv; | 410 | SilenceRemoveContext *s = ctx->priv; |
| 410 | 411 | ||
| 411 | s->next_pts = AV_NOPTS_VALUE; | 412 | s->next_pts = AV_NOPTS_VALUE; |
| 412 | s->window_size = FFMAX((inlink->sample_rate * s->window_ratio), 1); | 413 | s->window_duration = av_rescale(s->window_duration_opt, inlink->sample_rate, |
| 413 | s->window = ff_get_audio_buffer(ctx->outputs[0], s->window_size); | 414 | AV_TIME_BASE); |
| 415 | s->window_duration = FFMAX(1, s->window_duration); | ||
| 416 | s->window = ff_get_audio_buffer(ctx->outputs[0], s->window_duration); | ||
| 414 | if (!s->window) | 417 | if (!s->window) |
| 415 | return AVERROR(ENOMEM); | 418 | return AVERROR(ENOMEM); |
| 416 | 419 | ||
| @@ -615,7 +618,7 @@ silence_trim: · 198 unmodified lines | |||
| 615 | } | 618 | } |
| 616 | 619 | ||
| 617 | s->window_offset++; | 620 | s->window_offset++; |
| 618 | if (s->window_offset >= s->window_size) | 621 | if (s->window_offset >= s->window_duration) |
| 619 | s->window_offset = 0; | 622 | s->window_offset = 0; |
| 620 | s->start_holdoff_end++; | 623 | s->start_holdoff_end++; |
| 621 | nb_samples_read++; | 624 | nb_samples_read++; |
| @@ -641,7 +644,7 @@ silence_trim: · 19 unmodified lines | |||
| 641 | } | 644 | } |
| 642 | 645 | ||
| 643 | s->window_offset++; | 646 | s->window_offset++; |
| 644 | if (s->window_offset >= s->window_size) | 647 | if (s->window_offset >= s->window_duration) |
| 645 | s->window_offset = 0; | 648 | s->window_offset = 0; |
| 646 | nb_samples_read++; | 649 | nb_samples_read++; |
| 647 | s->start_silence_offset++; | 650 | s->start_silence_offset++; |
| @@ -744,7 +747,7 @@ silence_copy: · 96 unmodified lines | |||
| 744 | } | 747 | } |
| 745 | 748 | ||
| 746 | s->window_offset++; | 749 | s->window_offset++; |
| 747 | if (s->window_offset >= s->window_size) | 750 | if (s->window_offset >= s->window_duration) |
| 748 | s->window_offset = 0; | 751 | s->window_offset = 0; |
| 749 | nb_samples_read++; | 752 | nb_samples_read++; |
| 750 | nb_samples_written++; | 753 | nb_samples_written++; |
| @@ -763,7 +766,7 @@ silence_copy: · 12 unmodified lines | |||
| 763 | } | 766 | } |
| 764 | 767 | ||
| 765 | s->window_offset++; | 768 | s->window_offset++; |
| 766 | if (s->window_offset >= s->window_size) | 769 | if (s->window_offset >= s->window_duration) |
| 767 | s->window_offset = 0; | 770 | s->window_offset = 0; |
| 768 | nb_samples_read++; | 771 | nb_samples_read++; |
| 769 | s->stop_holdoff_end++; | 772 | s->stop_holdoff_end++; |