[FFmpeg-cvslog] vf_transpose: switch to an AVOptions-based system.

Anton Khirnov git at videolan.org
Thu Apr 11 00:38:12 CEST 2013


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Feb 25 21:21:29 2013 +0100| [0c2466dec719b933d161f5d680a57fde38aa5daa] | committer: Anton Khirnov

vf_transpose: switch to an AVOptions-based system.

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

 doc/filters.texi           |   20 ++++++++++++-----
 libavfilter/vf_transpose.c |   52 +++++++++++++++++++++++++-------------------
 2 files changed, 44 insertions(+), 28 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 9f190f9..c6a5067 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2107,11 +2107,19 @@ will create 5 copies of the input video.
 
 Transpose rows with columns in the input video and optionally flip it.
 
-It accepts a parameter representing an integer, which can assume the
-values:
+This filter accepts the following options:
+
+ at table @option
+
+ at item dir
+The direction of the transpose.
+
+ at end table
+
+The direction can assume the following values:
 
 @table @samp
- at item 0
+ at item cclock_flip
 Rotate by 90 degrees counterclockwise and vertically flip (default), that is:
 @example
 L.R     L.l
@@ -2119,7 +2127,7 @@ L.R     L.l
 l.r     R.r
 @end example
 
- at item 1
+ at item clock
 Rotate by 90 degrees clockwise, that is:
 @example
 L.R     l.L
@@ -2127,7 +2135,7 @@ L.R     l.L
 l.r     r.R
 @end example
 
- at item 2
+ at item cclock
 Rotate by 90 degrees counterclockwise, that is:
 @example
 L.R     R.r
@@ -2135,7 +2143,7 @@ L.R     R.r
 l.r     L.l
 @end example
 
- at item 3
+ at item clock_flip
 Rotate by 90 degrees clockwise and vertically flip, that is:
 @example
 L.R     r.R
diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c
index d1a77c4..dca12f5 100644
--- a/libavfilter/vf_transpose.c
+++ b/libavfilter/vf_transpose.c
@@ -31,38 +31,27 @@
 #include "libavutil/pixdesc.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
+#include "libavutil/opt.h"
 #include "avfilter.h"
 #include "formats.h"
 #include "internal.h"
 #include "video.h"
 
+enum TransposeDir {
+    TRANSPOSE_CCLOCK_FLIP,
+    TRANSPOSE_CLOCK,
+    TRANSPOSE_CCLOCK,
+    TRANSPOSE_CLOCK_FLIP,
+};
+
 typedef struct {
+    const AVClass *class;
     int hsub, vsub;
     int pixsteps[4];
 
-    /* 0    Rotate by 90 degrees counterclockwise and vflip. */
-    /* 1    Rotate by 90 degrees clockwise.                  */
-    /* 2    Rotate by 90 degrees counterclockwise.           */
-    /* 3    Rotate by 90 degrees clockwise and vflip.        */
-    int dir;
+    enum TransposeDir dir;
 } TransContext;
 
-static av_cold int init(AVFilterContext *ctx, const char *args)
-{
-    TransContext *trans = ctx->priv;
-    trans->dir = 0;
-
-    if (args)
-        sscanf(args, "%d", &trans->dir);
-
-    if (trans->dir < 0 || trans->dir > 3) {
-        av_log(ctx, AV_LOG_ERROR, "Invalid value %d not between 0 and 3.\n",
-               trans->dir);
-        return AVERROR(EINVAL);
-    }
-    return 0;
-}
-
 static int query_formats(AVFilterContext *ctx)
 {
     enum AVPixelFormat pix_fmts[] = {
@@ -198,6 +187,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     return ff_filter_frame(outlink, out);
 }
 
+#define OFFSET(x) offsetof(TransContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption options[] = {
+    { "dir", "Transpose direction", OFFSET(dir), AV_OPT_TYPE_INT, { .i64 = TRANSPOSE_CCLOCK_FLIP },
+        TRANSPOSE_CCLOCK_FLIP, TRANSPOSE_CLOCK_FLIP, FLAGS, "dir" },
+        { "cclock_flip", "counter-clockwise with vertical flip", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CCLOCK_FLIP }, .unit = "dir" },
+        { "clock",       "clockwise",                            0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CLOCK       }, .unit = "dir" },
+        { "cclock",      "counter-clockwise",                    0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CCLOCK      }, .unit = "dir" },
+        { "clock_flip",  "clockwise with vertical flip",         0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CLOCK_FLIP  }, .unit = "dir" },
+    { NULL },
+};
+
+static const AVClass transpose_class = {
+    .class_name = "transpose",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
 static const AVFilterPad avfilter_vf_transpose_inputs[] = {
     {
         .name        = "default",
@@ -220,8 +228,8 @@ AVFilter avfilter_vf_transpose = {
     .name      = "transpose",
     .description = NULL_IF_CONFIG_SMALL("Transpose input video."),
 
-    .init = init,
     .priv_size = sizeof(TransContext),
+    .priv_class = &transpose_class,
 
     .query_formats = query_formats,
 



More information about the ffmpeg-cvslog mailing list