History

avfilter/avf_showspectrum: add option to control dynamic range for colors

Paul B Mahol committed 5 years ago

Commit 2678b4f1 parent 2146b652 files · +18 −3Browse files

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

Unified · Split

libavfilter/avf_showspectrum.c+10−3
@@ -101,6 +101,8 @@ typedef struct ShowSpectrumContext { · 100 unmodified lines
101101 int single_pic;
102102 int legend;
103103 int start_x, start_y;
104+ float drange;
105+ float dmin, dscale;
104106 int (*plot_channel)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
105107 } ShowSpectrumContext;
106108
@@ -181,6 +183,7 @@ static const AVOption showspectrum_options[] = { · 74 unmodified lines
181183 { "stop", "stop frequency", OFFSET(stop), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT32_MAX, FLAGS },
182184 { "fps", "set video rate", OFFSET(rate_str), AV_OPT_TYPE_STRING, {.str = "auto"}, 0, 0, FLAGS },
183185 { "legend", "draw legend", OFFSET(legend), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
186+ { "drange", "set dynamic range in dBFS", OFFSET(drange), AV_OPT_TYPE_FLOAT, {.dbl = 120}, 10, 200, FLAGS },
184187 { NULL }
185188 };
186189
@@ -871,10 +874,10 @@ static int draw_legend(AVFilterContext *ctx, int samples) · 684 unmodified lines
871874 }
872875
873876 for (y = 0; ch == 0 && y < h; y += h / 10) {
874− float value = 120.f * log10f(1.f - y / (float)h);
877+ float value = s->drange * log10f(1.f - y / (float)h);
875878 char *text;
876879
877− if (value < -120)
880+ if (value < -s->drange)
878881 break;
879882 text = av_asprintf("%.0f dB", value);
880883 if (!text)
@@ -925,7 +928,7 @@ static float get_value(AVFilterContext *ctx, int ch, int y) · 44 unmodified lines
925928 a = av_clipf(powf(a, 0.20), 0, 1);
926929 break;
927930 case LOG:
928− a = 1.f + log10f(av_clipf(a, 1e-6, 1)) / 6.f; // zero = -120dBFS
931+ a = 1.f + log10f(av_clipf(a, s->dmin, 1.f)) * s->dscale;
929932 break;
930933 default:
931934 av_assert0(0);
@@ -999,6 +1002,9 @@ static int config_output(AVFilterLink *outlink) · 67 unmodified lines
9991002 int i, fft_size, h, w, ret;
10001003 float overlap;
10011004
1005+ s->dmin = expf(-s->drange * M_LN10 / 20.f);
1006+ s->dscale = -1.f / log10f(s->dmin);
1007+
10021008 switch (s->fscale) {
10031009 case F_LINEAR: s->plot_channel = plot_channel_lin; break;
10041010 case F_LOG: s->plot_channel = plot_channel_log; break;
@@ -1641,6 +1647,7 @@ static const AVOption showspectrumpic_options[] = { · 636 unmodified lines
16411647 { "rotation", "color rotation", OFFSET(rotation), AV_OPT_TYPE_FLOAT, {.dbl = 0}, -1, 1, FLAGS },
16421648 { "start", "start frequency", OFFSET(start), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT32_MAX, FLAGS },
16431649 { "stop", "stop frequency", OFFSET(stop), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT32_MAX, FLAGS },
1650+ { "drange", "set dynamic range in dBFS", OFFSET(drange), AV_OPT_TYPE_FLOAT, {.dbl = 120}, 10, 200, FLAGS },
16441651 { NULL }
16451652 };
16461653

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