[FFmpeg-cvslog] lavfi/transpose: implement landscape passthrough mode

Stefano Sabatini git at videolan.org
Tue Sep 4 11:42:36 CEST 2012


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Sat Sep  1 11:14:27 2012 +0200| [9de7622927b1b0ec6f8045b17b3116f046f44b87] | committer: Stefano Sabatini

lavfi/transpose: implement landscape passthrough mode

Emulate the mp=rotate passthrough mode.

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

 doc/filters.texi           |   11 +++++++----
 libavfilter/version.h      |    2 +-
 libavfilter/vf_transpose.c |   43 +++++++++++++++++++++++++++++++++++++++----
 3 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 712936d..c2ebe3b 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -3454,7 +3454,7 @@ It accepts a parameter representing an integer, which can assume the
 values:
 
 @table @samp
- at item 0
+ at item 0, 4
 Rotate by 90 degrees counterclockwise and vertically flip (default), that is:
 @example
 L.R     L.l
@@ -3462,7 +3462,7 @@ L.R     L.l
 l.r     R.r
 @end example
 
- at item 1
+ at item 1, 5
 Rotate by 90 degrees clockwise, that is:
 @example
 L.R     l.L
@@ -3470,7 +3470,7 @@ L.R     l.L
 l.r     r.R
 @end example
 
- at item 2
+ at item 2, 6
 Rotate by 90 degrees counterclockwise, that is:
 @example
 L.R     R.r
@@ -3478,7 +3478,7 @@ L.R     R.r
 l.r     L.l
 @end example
 
- at item 3
+ at item 3, 7
 Rotate by 90 degrees clockwise and vertically flip, that is:
 @example
 L.R     r.R
@@ -3487,6 +3487,9 @@ l.r     l.L
 @end example
 @end table
 
+For values between 4-7 transposition is only done if the input video
+geometry is portrait and not landscape.
+
 @section unsharp
 
 Sharpen or blur the input video.
diff --git a/libavfilter/version.h b/libavfilter/version.h
index c37976a..a945c4c 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
 
 #define LIBAVFILTER_VERSION_MAJOR  3
 #define LIBAVFILTER_VERSION_MINOR  15
-#define LIBAVFILTER_VERSION_MICRO 102
+#define LIBAVFILTER_VERSION_MICRO 103
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
                                                LIBAVFILTER_VERSION_MINOR, \
diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c
index 546f149..4161050 100644
--- a/libavfilter/vf_transpose.c
+++ b/libavfilter/vf_transpose.c
@@ -45,6 +45,7 @@ typedef struct {
     /* 2    Rotate by 90 degrees counterclockwise.           */
     /* 3    Rotate by 90 degrees clockwise and vflip.        */
     int dir;
+    int passthrough; ///< landscape passthrough mode enabled
 } TransContext;
 
 static av_cold int init(AVFilterContext *ctx, const char *args)
@@ -55,8 +56,8 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     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",
+    if (trans->dir < 0 || trans->dir > 7) {
+        av_log(ctx, AV_LOG_ERROR, "Invalid value %d not between 0 and 7.\n",
                trans->dir);
         return AVERROR(EINVAL);
     }
@@ -97,6 +98,18 @@ static int config_props_output(AVFilterLink *outlink)
     AVFilterLink *inlink = ctx->inputs[0];
     const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[outlink->format];
 
+    if (trans->dir&4) {
+        trans->dir &= 3;
+        if (inlink->w >= inlink->h) {
+            trans->passthrough = 1;
+
+            av_log(ctx, AV_LOG_VERBOSE,
+                   "w:%d h:%d -> w:%d h:%d (landscape passthrough mode)\n",
+                   inlink->w, inlink->h, outlink->w, outlink->h);
+            return 0;
+        }
+    }
+
     trans->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
     trans->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
 
@@ -117,11 +130,24 @@ static int config_props_output(AVFilterLink *outlink)
     return 0;
 }
 
+static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int w, int h)
+{
+    TransContext *trans = inlink->dst->priv;
+
+    return trans->passthrough ?
+        ff_null_get_video_buffer   (inlink, perms, w, h) :
+        ff_default_get_video_buffer(inlink, perms, w, h);
+}
+
 static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
 {
+    TransContext *trans = inlink->dst->priv;
     AVFilterLink *outlink = inlink->dst->outputs[0];
     AVFilterBufferRef *buf_out;
 
+    if (trans->passthrough)
+        return ff_null_start_frame(inlink, picref);
+
     outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE,
                                            outlink->w, outlink->h);
     if (!outlink->out_buf)
@@ -150,6 +176,9 @@ static int end_frame(AVFilterLink *inlink)
     AVFilterLink *outlink = inlink->dst->outputs[0];
     int plane, ret;
 
+    if (trans->passthrough)
+        return ff_null_end_frame(inlink);
+
     for (plane = 0; outpic->data[plane]; plane++) {
         int hsub = plane == 1 || plane == 2 ? trans->hsub : 0;
         int vsub = plane == 1 || plane == 2 ? trans->vsub : 0;
@@ -205,7 +234,12 @@ static int end_frame(AVFilterLink *inlink)
     return 0;
 }
 
-static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { return 0; }
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+{
+    TransContext *trans = inlink->dst->priv;
+
+    return trans->passthrough ? ff_null_draw_slice(inlink, y, h, slice_dir) : 0;
+}
 
 AVFilter avfilter_vf_transpose = {
     .name      = "transpose",
@@ -218,8 +252,9 @@ AVFilter avfilter_vf_transpose = {
 
     .inputs    = (const AVFilterPad[]) {{ .name            = "default",
                                           .type            = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer= get_video_buffer,
                                           .start_frame     = start_frame,
-                                          .draw_slice      = null_draw_slice,
+                                          .draw_slice      = draw_slice,
                                           .end_frame       = end_frame,
                                           .min_perms       = AV_PERM_READ, },
                                         { .name = NULL}},



More information about the ffmpeg-cvslog mailing list