Unified · Split
| @@ -69,6 +69,8 @@ typedef struct SilenceRemoveContext { · 68 unmodified lines | ||
| 69 | 69 | int64_t stop_silence_opt; |
| 70 | 70 | int stop_mode; |
| 71 | 71 | |
| 72 | + int64_t window_duration_opt; | |
| 73 | + | |
| 72 | 74 | AVFrame *start_holdoff; |
| 73 | 75 | AVFrame *start_silence_hold; |
| 74 | 76 | size_t start_holdoff_offset; |
| @@ -85,10 +87,9 @@ typedef struct SilenceRemoveContext { · 10 unmodified lines | ||
| 85 | 87 | size_t stop_silence_end; |
| 86 | 88 | int stop_found_periods; |
| 87 | 89 | |
| 88 | − double window_ratio; | |
| 89 | 90 | AVFrame *window; |
| 90 | 91 | int window_offset; |
| 91 | − int window_size; | |
| 92 | + int64_t window_duration; | |
| 92 | 93 | double sum; |
| 93 | 94 | |
| 94 | 95 | int restart; |
| @@ -120,7 +121,7 @@ static const AVOption silenceremove_options[] = { · 25 unmodified lines | ||
| 120 | 121 | { "detection", "set how silence is detected", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=D_RMS}, D_PEAK,D_RMS, AF, "detection" }, |
| 121 | 122 | { "peak", "use absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_PEAK},0, 0, AF, "detection" }, |
| 122 | 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 | 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 | 179 | new_sum -= wsample; |
| 179 | 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 | 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 | 206 | new_sum -= wsample; |
| 206 | 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 | 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 | 233 | new_sum -= wsample; |
| 233 | 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 | 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 | 260 | new_sum -= wsample; |
| 260 | 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 | 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 | 287 | new_sum -= wsample; |
| 287 | 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 | 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 | 314 | new_sum -= wsample; |
| 314 | 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 | 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 | 341 | new_sum -= wsample; |
| 341 | 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 | 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 | 368 | new_sum -= wsample; |
| 368 | 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 | 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 | 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 | 401 | s->window->channels, s->window->format); |
| 401 | 402 | |
| 402 | 403 | s->window_offset = 0; |
| @@ -409,8 +410,10 @@ static int config_input(AVFilterLink *inlink) · 6 unmodified lines | ||
| 409 | 410 | SilenceRemoveContext *s = ctx->priv; |
| 410 | 411 | |
| 411 | 412 | s->next_pts = AV_NOPTS_VALUE; |
| 412 | − s->window_size = FFMAX((inlink->sample_rate * s->window_ratio), 1); | |
| 413 | − s->window = ff_get_audio_buffer(ctx->outputs[0], s->window_size); | |
| 413 | + s->window_duration = av_rescale(s->window_duration_opt, inlink->sample_rate, | |
| 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 | 417 | if (!s->window) |
| 415 | 418 | return AVERROR(ENOMEM); |
| 416 | 419 | |
| @@ -615,7 +618,7 @@ silence_trim: · 198 unmodified lines | ||
| 615 | 618 | } |
| 616 | 619 | |
| 617 | 620 | s->window_offset++; |
| 618 | − if (s->window_offset >= s->window_size) | |
| 621 | + if (s->window_offset >= s->window_duration) | |
| 619 | 622 | s->window_offset = 0; |
| 620 | 623 | s->start_holdoff_end++; |
| 621 | 624 | nb_samples_read++; |
| @@ -641,7 +644,7 @@ silence_trim: · 19 unmodified lines | ||
| 641 | 644 | } |
| 642 | 645 | |
| 643 | 646 | s->window_offset++; |
| 644 | − if (s->window_offset >= s->window_size) | |
| 647 | + if (s->window_offset >= s->window_duration) | |
| 645 | 648 | s->window_offset = 0; |
| 646 | 649 | nb_samples_read++; |
| 647 | 650 | s->start_silence_offset++; |
| @@ -744,7 +747,7 @@ silence_copy: · 96 unmodified lines | ||
| 744 | 747 | } |
| 745 | 748 | |
| 746 | 749 | s->window_offset++; |
| 747 | − if (s->window_offset >= s->window_size) | |
| 750 | + if (s->window_offset >= s->window_duration) | |
| 748 | 751 | s->window_offset = 0; |
| 749 | 752 | nb_samples_read++; |
| 750 | 753 | nb_samples_written++; |
| @@ -763,7 +766,7 @@ silence_copy: · 12 unmodified lines | ||
| 763 | 766 | } |
| 764 | 767 | |
| 765 | 768 | s->window_offset++; |
| 766 | − if (s->window_offset >= s->window_size) | |
| 769 | + if (s->window_offset >= s->window_duration) | |
| 767 | 770 | s->window_offset = 0; |
| 768 | 771 | nb_samples_read++; |
| 769 | 772 | s->stop_holdoff_end++; |