]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/af_silenceremove.c
avfilter/vf_v360: add truncated square pyramid input format
[ffmpeg] / libavfilter / af_silenceremove.c
index ba5c4e17e37243e1f313cb8c02d4f2344006d7a4..7dd8c5a1d81ea48c696bc3d04b429b5b4d80c143 100644 (file)
@@ -35,6 +35,11 @@ enum SilenceDetect {
     D_RMS,
 };
 
+enum ThresholdMode {
+    T_ANY,
+    T_ALL,
+};
+
 enum SilenceMode {
     SILENCE_TRIM,
     SILENCE_TRIM_FLUSH,
@@ -103,14 +108,14 @@ static const AVOption silenceremove_options[] = {
     { "start_duration",  "set start duration of non-silence part",             OFFSET(start_duration_opt),  AV_OPT_TYPE_DURATION, {.i64=0},     0, INT32_MAX, AF },
     { "start_threshold", "set threshold for start silence detection",          OFFSET(start_threshold),     AV_OPT_TYPE_DOUBLE,   {.dbl=0},     0,   DBL_MAX, AF },
     { "start_silence",   "set start duration of silence part to keep",         OFFSET(start_silence_opt),   AV_OPT_TYPE_DURATION, {.i64=0},     0, INT32_MAX, AF },
-    { "start_mode",      "set which channel will trigger trimming from start", OFFSET(start_mode),          AV_OPT_TYPE_INT,      {.i64=0},     0,         1, AF, "mode" },
-    {   "any",           0,                                                    0,                           AV_OPT_TYPE_CONST,    {.i64=0},     0,         0, AF, "mode" },
-    {   "all",           0,                                                    0,                           AV_OPT_TYPE_CONST,    {.i64=1},     0,         0, AF, "mode" },
+    { "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" },
+    {   "any",           0,                                                    0,                           AV_OPT_TYPE_CONST,    {.i64=T_ANY}, 0,         0, AF, "mode" },
+    {   "all",           0,                                                    0,                           AV_OPT_TYPE_CONST,    {.i64=T_ALL}, 0,         0, AF, "mode" },
     { "stop_periods",    NULL,                                                 OFFSET(stop_periods),        AV_OPT_TYPE_INT,      {.i64=0}, -9000,      9000, AF },
     { "stop_duration",   "set stop duration of non-silence part",              OFFSET(stop_duration_opt),   AV_OPT_TYPE_DURATION, {.i64=0},     0, INT32_MAX, AF },
     { "stop_threshold",  "set threshold for stop silence detection",           OFFSET(stop_threshold),      AV_OPT_TYPE_DOUBLE,   {.dbl=0},     0,   DBL_MAX, AF },
     { "stop_silence",    "set stop duration of silence part to keep",          OFFSET(stop_silence_opt),    AV_OPT_TYPE_DURATION, {.i64=0},     0, INT32_MAX, AF },
-    { "stop_mode",       "set which channel will trigger trimming from end",   OFFSET(stop_mode),           AV_OPT_TYPE_INT,      {.i64=0},     0,         1, AF, "mode" },
+    { "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" },
     { "detection",       "set how silence is detected",                        OFFSET(detection),           AV_OPT_TYPE_INT,      {.i64=D_RMS}, D_PEAK,D_RMS, AF, "detection" },
     {   "peak",          "use absolute values of samples",                     0,                           AV_OPT_TYPE_CONST,    {.i64=D_PEAK},0,         0, AF, "detection" },
     {   "rms",           "use squared values of samples",                      0,                           AV_OPT_TYPE_CONST,    {.i64=D_RMS}, 0,         0, AF, "detection" },
@@ -201,6 +206,7 @@ static int config_input(AVFilterLink *inlink)
     AVFilterContext *ctx = inlink->dst;
     SilenceRemoveContext *s = ctx->priv;
 
+    s->next_pts = AV_NOPTS_VALUE;
     s->window_size = FFMAX((inlink->sample_rate * s->window_ratio), 1) * inlink->channels;
     s->window = av_malloc_array(s->window_size, sizeof(*s->window));
     if (!s->window)
@@ -323,6 +329,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     nb_samples_read = nb_samples_written = 0;
 
+    if (s->next_pts == AV_NOPTS_VALUE)
+        s->next_pts = in->pts;
+
     switch (s->mode) {
     case SILENCE_TRIM:
 silence_trim:
@@ -331,7 +340,7 @@ silence_trim:
             break;
 
         for (i = 0; i < nbs; i++) {
-            if (s->start_mode) {
+            if (s->start_mode == T_ANY) {
                 threshold = 0;
                 for (j = 0; j < outlink->channels; j++) {
                     threshold |= s->compute(s, ibuf[j]) > s->start_threshold;
@@ -446,7 +455,7 @@ silence_copy:
 
         if (s->stop_periods) {
             for (i = 0; i < nbs; i++) {
-                if (s->stop_mode) {
+                if (s->stop_mode == T_ANY) {
                     threshold = 0;
                     for (j = 0; j < outlink->channels; j++) {
                         threshold |= s->compute(s, ibuf[j]) > s->stop_threshold;