summaryrefslogtreecommitdiff
path: root/libavfilter/avf_showspectrum.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2018-10-05 14:22:07 +0200
committerPaul B Mahol <onemda@gmail.com>2018-10-05 14:23:48 +0200
commitfe447c0609cda8a0110a7b83834b87aa2bc123a4 (patch)
tree69069567cb89f4fb29c9a3d1371ac5507b5e1bf9 /libavfilter/avf_showspectrum.c
parent3e687be4faa6dba2293317ccae732bacfc49e434 (diff)
avfilter/avf_showspectrum: add zoom mode to showspectrumpic
Diffstat (limited to 'libavfilter/avf_showspectrum.c')
-rw-r--r--libavfilter/avf_showspectrum.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c
index b39c084a4b..bbe42ba7c7 100644
--- a/libavfilter/avf_showspectrum.c
+++ b/libavfilter/avf_showspectrum.c
@@ -1128,6 +1128,8 @@ static const AVOption showspectrumpic_options[] = {
{ "gain", "set scale gain", OFFSET(gain), AV_OPT_TYPE_FLOAT, {.dbl = 1}, 0, 128, FLAGS },
{ "legend", "draw legend", OFFSET(legend), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
{ "rotation", "color rotation", OFFSET(rotation), AV_OPT_TYPE_FLOAT, {.dbl = 0}, -1, 1, FLAGS },
+ { "start", "start frequency", OFFSET(start), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT32_MAX, FLAGS },
+ { "stop", "stop frequency", OFFSET(stop), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT32_MAX, FLAGS },
{ NULL }
};
@@ -1240,6 +1242,11 @@ static int showspectrumpic_request_frame(AVFilterLink *outlink)
drawtext(s->outpicref, 2, outlink->h - 10, "CREATED BY LIBAVFILTER", 0);
drawtext(s->outpicref, outlink->w - 2 - strlen(text) * 10, outlink->h - 10, text, 0);
+ if (s->stop) {
+ char *text = av_asprintf("Zoom: %d Hz - %d Hz", s->start, s->stop);
+ drawtext(s->outpicref, outlink->w - 2 - strlen(text) * 10, 3, text, 0);
+ av_freep(&text);
+ }
av_freep(&text);
@@ -1283,7 +1290,8 @@ static int showspectrumpic_request_frame(AVFilterLink *outlink)
dst[x] = 200;
}
for (y = 0; y < h; y += 40) {
- float hertz = y * (inlink->sample_rate / 2) / (float)(1 << (int)ceil(log2(h)));
+ float range = s->stop ? s->stop - s->start : inlink->sample_rate / 2;
+ float hertz = s->start + y * range / (float)(1 << (int)ceil(log2(h)));
char *units;
if (hertz == 0)
@@ -1348,7 +1356,8 @@ static int showspectrumpic_request_frame(AVFilterLink *outlink)
dst[x] = 200;
}
for (x = 0; x < w - 79; x += 80) {
- float hertz = x * (inlink->sample_rate / 2) / (float)(1 << (int)ceil(log2(w)));
+ float range = s->stop ? s->stop - s->start : inlink->sample_rate / 2;
+ float hertz = s->start + x * range / (float)(1 << (int)ceil(log2(w)));
char *units;
if (hertz == 0)