From ca788d184cbf0a907ca7db4e4dad9975a91a5839 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Mon, 16 Aug 2021 01:12:45 +0200 Subject: avfilter/vf_waveform: add option to control strechness of waveform --- libavfilter/vf_waveform.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'libavfilter/vf_waveform.c') diff --git a/libavfilter/vf_waveform.c b/libavfilter/vf_waveform.c index 8aad6e9cca..f3d44a236e 100644 --- a/libavfilter/vf_waveform.c +++ b/libavfilter/vf_waveform.c @@ -36,6 +36,12 @@ typedef struct ThreadData { int offset_x; } ThreadData; +enum FitMode { + FM_NONE, + FM_SIZE, + NB_FITMODES +}; + enum FilterType { LOWPASS, FLAT, @@ -113,6 +119,7 @@ typedef struct WaveformContext { int rgb; float ftint[2]; int tint[2]; + int fitmode; int (*waveform_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); @@ -184,6 +191,10 @@ static const AVOption waveform_options[] = { { "t0", "set 1st tint", OFFSET(ftint[0]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS}, { "tint1", "set 2nd tint", OFFSET(ftint[1]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS}, { "t1", "set 2nd tint", OFFSET(ftint[1]), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, FLAGS}, + { "fitmode", "set fit mode", OFFSET(fitmode), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FITMODES-1, FLAGS, "fitmode" }, + { "fm", "set fit mode", OFFSET(fitmode), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_FITMODES-1, FLAGS, "fitmode" }, + { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_NONE}, 0, 0, FLAGS, "fitmode" }, + { "size", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_SIZE}, 0, 0, FLAGS, "fitmode" }, { NULL } }; @@ -3357,7 +3368,20 @@ static int config_output(AVFilterLink *outlink) } } - outlink->sample_aspect_ratio = (AVRational){1,1}; + switch (s->fitmode) { + case FM_NONE: + outlink->sample_aspect_ratio = (AVRational){ 1, 1 }; + break; + case FM_SIZE: + if (s->mode) + outlink->sample_aspect_ratio = (AVRational){ s->size * comp, inlink->h }; + else + outlink->sample_aspect_ratio = (AVRational){ inlink->w, s->size * comp }; + break; + } + + av_reduce(&outlink->sample_aspect_ratio.num, &outlink->sample_aspect_ratio.den, + outlink->sample_aspect_ratio.num, outlink->sample_aspect_ratio.den, INT_MAX); return 0; } @@ -3461,6 +3485,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) s->graticulef(s, out); av_frame_free(&in); + out->sample_aspect_ratio = outlink->sample_aspect_ratio; return ff_filter_frame(outlink, out); } -- cgit v1.2.3