[FFmpeg-cvslog] avfilter/avf_avectorscope: add possibility to auto zoom
Paul B Mahol
git at videolan.org
Tue Sep 5 12:46:56 EEST 2017
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Tue Sep 5 11:43:49 2017 +0200| [2c10f054c2bcd4500ef7f2c88257c5df8933ef3c] | committer: Paul B Mahol
avfilter/avf_avectorscope: add possibility to auto zoom
Signed-off-by: Paul B Mahol <onemda at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2c10f054c2bcd4500ef7f2c88257c5df8933ef3c
---
doc/filters.texi | 3 ++-
libavfilter/avf_avectorscope.c | 33 +++++++++++++++++++++++++++++++--
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 862290550d..9ca24b3c8e 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -17044,7 +17044,8 @@ Specify the red, green, blue and alpha fade. Default values are @code{15},
Allowed range is @code{[0, 255]}.
@item zoom
-Set the zoom factor. Default value is @code{1}. Allowed range is @code{[1, 10]}.
+Set the zoom factor. Default value is @code{1}. Allowed range is @code{[0, 10]}.
+Values lower than @var{1} will auto adjust zoom factor to maximal possible value.
@item draw
Set the vectorscope drawing mode.
diff --git a/libavfilter/avf_avectorscope.c b/libavfilter/avf_avectorscope.c
index 7cb5efb402..b24011bd66 100644
--- a/libavfilter/avf_avectorscope.c
+++ b/libavfilter/avf_avectorscope.c
@@ -90,7 +90,7 @@ static const AVOption avectorscope_options[] = {
{ "gf", "set green fade", OFFSET(fade[1]), AV_OPT_TYPE_INT, {.i64=10}, 0, 255, FLAGS },
{ "bf", "set blue fade", OFFSET(fade[2]), AV_OPT_TYPE_INT, {.i64=5}, 0, 255, FLAGS },
{ "af", "set alpha fade", OFFSET(fade[3]), AV_OPT_TYPE_INT, {.i64=5}, 0, 255, FLAGS },
- { "zoom", "set zoom factor", OFFSET(zoom), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 1, 10, FLAGS },
+ { "zoom", "set zoom factor", OFFSET(zoom), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 10, FLAGS },
{ "draw", "set draw mode", OFFSET(draw), AV_OPT_TYPE_INT, {.i64=DOT}, 0, DRAW_NB-1, FLAGS, "draw" },
{ "dot", "", 0, AV_OPT_TYPE_CONST, {.i64=DOT} , 0, 0, FLAGS, "draw" },
{ "line", "", 0, AV_OPT_TYPE_CONST, {.i64=LINE}, 0, 0, FLAGS, "draw" },
@@ -234,7 +234,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
const int hh = s->hh;
unsigned x, y;
unsigned prev_x = s->prev_x, prev_y = s->prev_y;
- const double zoom = s->zoom;
+ double zoom = s->zoom;
int i;
if (!s->outpicref || s->outpicref->width != outlink->w ||
@@ -254,6 +254,35 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
fade(s);
+ if (zoom < 1) {
+ float max = 0;
+
+ switch (insamples->format) {
+ case AV_SAMPLE_FMT_S16: {
+ int16_t *samples = (int16_t *)insamples->data[0];
+
+ for (i = 0; i < insamples->nb_samples * 2; i++) {
+ float sample = samples[i] / (float)INT16_MAX;
+ max = FFMAX(FFABS(sample), max);
+ }
+
+ }
+ break;
+ case AV_SAMPLE_FMT_FLT: {
+ float *samples = (float *)insamples->data[0] + i * 2;
+
+ for (i = 0; i < insamples->nb_samples; i++) {
+ max = FFMAX(FFABS(samples[i]), max);
+ }
+ }
+ break;
+ default:
+ av_assert2(0);
+ }
+
+ zoom = 1. / max;
+ }
+
for (i = 0; i < insamples->nb_samples; i++) {
int16_t *samples = (int16_t *)insamples->data[0] + i * 2;
float *samplesf = (float *)insamples->data[0] + i * 2;
More information about the ffmpeg-cvslog
mailing list