[FFmpeg-cvslog] avfilter/vf_waveform: add option to control strechness of waveform

Paul B Mahol git at videolan.org
Mon Aug 16 02:20:42 EEST 2021


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Aug 16 01:12:45 2021 +0200| [ca788d184cbf0a907ca7db4e4dad9975a91a5839] | committer: Paul B Mahol

avfilter/vf_waveform: add option to control strechness of waveform

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ca788d184cbf0a907ca7db4e4dad9975a91a5839
---

 doc/filters.texi          | 13 +++++++++++++
 libavfilter/vf_waveform.c | 27 ++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 0c399f1d35..d77bbe9369 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -22115,6 +22115,19 @@ Set background opacity.
 Set tint for output.
 Only used with lowpass filter and when display is not overlay and input
 pixel formats are not RGB.
+
+ at item fitmode, fm
+Set sample aspect ratio of video output frames.
+Can be used to configure waveform so it is not
+streched too much in one of directions.
+
+ at table @samp
+ at item none
+Set sample aspect ration to 1/1.
+ at item size
+Set sample aspect ratio to match input size of video
+ at end table
+Default is @samp{none}.
 @end table
 
 @section weave, doubleweave
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);
 }
 



More information about the ffmpeg-cvslog mailing list