Browse code

avfilter/avf_showvolume: use current peak value for picking colors

Paul B Mahol authored on 2016/08/19 03:14:58
Showing 2 changed files
... ...
@@ -16899,6 +16899,9 @@ The expression can use the following variables:
16899 16899
 @item VOLUME
16900 16900
 Current max volume of channel in dB.
16901 16901
 
16902
+@item PEAK
16903
+Current peak.
16904
+
16902 16905
 @item CHANNEL
16903 16906
 Current channel number, starting from 0.
16904 16907
 @end table
... ...
@@ -31,8 +31,8 @@
31 31
 #include "video.h"
32 32
 #include "internal.h"
33 33
 
34
-static const char *const var_names[] = {   "VOLUME",   "CHANNEL",        NULL };
35
-enum                                   { VAR_VOLUME, VAR_CHANNEL, VAR_VARS_NB };
34
+static const char *const var_names[] = {   "VOLUME",   "CHANNEL",   "PEAK",        NULL };
35
+enum                                   { VAR_VOLUME, VAR_CHANNEL, VAR_PEAK, VAR_VARS_NB };
36 36
 
37 37
 typedef struct ShowVolumeContext {
38 38
     const AVClass *class;
... ...
@@ -61,7 +61,7 @@ static const AVOption showvolume_options[] = {
61 61
     { "w", "set channel width",  OFFSET(w), AV_OPT_TYPE_INT, {.i64=400}, 80, 8192, FLAGS },
62 62
     { "h", "set channel height", OFFSET(h), AV_OPT_TYPE_INT, {.i64=20}, 1, 900, FLAGS },
63 63
     { "f", "set fade",           OFFSET(f), AV_OPT_TYPE_DOUBLE, {.dbl=0.95}, 0.001, 1, FLAGS },
64
-    { "c", "set volume color expression", OFFSET(color), AV_OPT_TYPE_STRING, {.str="if(gte(VOLUME,-6), if(gte(VOLUME,-2), if(gte(VOLUME,-1), if(gt(VOLUME,0), 0xff0000ff, 0xff0066ff), 0xff00ffff),0xff00ff00),0xffff0000)"}, 0, 0, FLAGS },
64
+    { "c", "set volume color expression", OFFSET(color), AV_OPT_TYPE_STRING, {.str="PEAK*255+floor((1-PEAK)*255)*256"}, 0, 0, FLAGS },
65 65
     { "t", "display channel names", OFFSET(draw_text), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
66 66
     { "v", "display volume value", OFFSET(draw_volume), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
67 67
     { "o", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "orientation" },
... ...
@@ -228,6 +228,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
228 228
             for (i = 0; i < insamples->nb_samples; i++)
229 229
                 max = FFMAX(max, src[i]);
230 230
 
231
+            s->values[c * VAR_VARS_NB + VAR_PEAK] = max;
231 232
             s->values[c * VAR_VARS_NB + VAR_VOLUME] = 20.0 * log10(max);
232 233
             max = av_clipf(max, 0, 1);
233 234
             s->values[c * VAR_VARS_NB + VAR_CHANNEL] = c;
... ...
@@ -258,6 +259,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
258 258
             for (i = 0; i < insamples->nb_samples; i++)
259 259
                 max = FFMAX(max, src[i]);
260 260
 
261
+            s->values[c * VAR_VARS_NB + VAR_PEAK] = max;
261 262
             s->values[c * VAR_VARS_NB + VAR_VOLUME] = 20.0 * log10(max);
262 263
             max = av_clipf(max, 0, 1);
263 264
             s->values[c * VAR_VARS_NB + VAR_CHANNEL] = c;