summaryrefslogtreecommitdiffstats
path: root/libavfilter/vf_transpose.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavfilter/vf_transpose.c')
-rw-r--r--libavfilter/vf_transpose.c105
1 files changed, 83 insertions, 22 deletions
diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c
index a8ef440..dab5cc6 100644
--- a/libavfilter/vf_transpose.c
+++ b/libavfilter/vf_transpose.c
@@ -2,20 +2,20 @@
* Copyright (c) 2010 Stefano Sabatini
* Copyright (c) 2008 Vitor Sessak
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,6 +28,7 @@
#include <stdio.h>
#include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
@@ -36,7 +37,14 @@
#include "internal.h"
#include "video.h"
+typedef enum {
+ TRANSPOSE_PT_TYPE_NONE,
+ TRANSPOSE_PT_TYPE_LANDSCAPE,
+ TRANSPOSE_PT_TYPE_PORTRAIT,
+} PassthroughType;
+
typedef struct {
+ const AVClass *class;
int hsub, vsub;
int pixsteps[4];
@@ -45,22 +53,35 @@ typedef struct {
/* 2 Rotate by 90 degrees counterclockwise. */
/* 3 Rotate by 90 degrees clockwise and vflip. */
int dir;
+ PassthroughType passthrough; ///< landscape passthrough mode enabled
} TransContext;
+#define OFFSET(x) offsetof(TransContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+
+static const AVOption transpose_options[] = {
+ { "dir", "set transpose direction", OFFSET(dir), AV_OPT_TYPE_INT, {.i64=0}, 0, 7, FLAGS },
+
+ { "passthrough", "do not apply transposition if the input matches the specified geometry",
+ OFFSET(passthrough), AV_OPT_TYPE_INT, {.i64=TRANSPOSE_PT_TYPE_NONE}, 0, INT_MAX, FLAGS, "passthrough" },
+ { "none", "always apply transposition", 0, AV_OPT_TYPE_CONST, {.i64=TRANSPOSE_PT_TYPE_NONE}, INT_MIN, INT_MAX, FLAGS, "passthrough" },
+ { "portrait", "preserve portrait geometry", 0, AV_OPT_TYPE_CONST, {.i64=TRANSPOSE_PT_TYPE_PORTRAIT}, INT_MIN, INT_MAX, FLAGS, "passthrough" },
+ { "landscape", "preserve landscape geometry", 0, AV_OPT_TYPE_CONST, {.i64=TRANSPOSE_PT_TYPE_LANDSCAPE}, INT_MIN, INT_MAX, FLAGS, "passthrough" },
+
+ { NULL },
+};
+
+AVFILTER_DEFINE_CLASS(transpose);
+
static av_cold int init(AVFilterContext *ctx, const char *args)
{
TransContext *trans = ctx->priv;
- trans->dir = 0;
+ const char *shorthand[] = { "dir", "passthrough", NULL };
- if (args)
- sscanf(args, "%d", &trans->dir);
+ trans->class = &transpose_class;
+ av_opt_set_defaults(trans);
- 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;
+ return av_opt_set_from_string(trans, args, shorthand, "=", ":");
}
static int query_formats(AVFilterContext *ctx)
@@ -75,16 +96,13 @@ static int query_formats(AVFilterContext *ctx)
AV_PIX_FMT_BGR555BE, AV_PIX_FMT_BGR555LE,
AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_GRAY16LE,
AV_PIX_FMT_YUV420P16LE, AV_PIX_FMT_YUV420P16BE,
- AV_PIX_FMT_YUV422P16LE, AV_PIX_FMT_YUV422P16BE,
AV_PIX_FMT_YUV444P16LE, AV_PIX_FMT_YUV444P16BE,
AV_PIX_FMT_NV12, AV_PIX_FMT_NV21,
AV_PIX_FMT_RGB8, AV_PIX_FMT_BGR8,
AV_PIX_FMT_RGB4_BYTE, AV_PIX_FMT_BGR4_BYTE,
- AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P,
+ AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P,
- AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
- AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P,
- AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUVJ440P,
+ AV_PIX_FMT_YUV410P,
AV_PIX_FMT_YUVA420P, AV_PIX_FMT_GRAY8,
AV_PIX_FMT_NONE
};
@@ -100,6 +118,23 @@ 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) {
+ av_log(ctx, AV_LOG_WARNING,
+ "dir values greater than 3 are deprecated, use the passthrough option instead\n");
+ trans->dir &= 3;
+ trans->passthrough = TRANSPOSE_PT_TYPE_LANDSCAPE;
+ }
+
+ if ((inlink->w >= inlink->h && trans->passthrough == TRANSPOSE_PT_TYPE_LANDSCAPE) ||
+ (inlink->w <= inlink->h && trans->passthrough == TRANSPOSE_PT_TYPE_PORTRAIT)) {
+ av_log(ctx, AV_LOG_VERBOSE,
+ "w:%d h:%d -> w:%d h:%d (passthrough mode)\n",
+ inlink->w, inlink->h, inlink->w, inlink->h);
+ return 0;
+ } else {
+ trans->passthrough = TRANSPOSE_PT_TYPE_NONE;
+ }
+
trans->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
trans->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
@@ -120,11 +155,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)
@@ -132,11 +180,11 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
outlink->out_buf->pts = picref->pts;
- if (picref->video->pixel_aspect.num == 0) {
- outlink->out_buf->video->pixel_aspect = picref->video->pixel_aspect;
+ if (picref->video->sample_aspect_ratio.num == 0) {
+ outlink->out_buf->video->sample_aspect_ratio = picref->video->sample_aspect_ratio;
} else {
- outlink->out_buf->video->pixel_aspect.num = picref->video->pixel_aspect.den;
- outlink->out_buf->video->pixel_aspect.den = picref->video->pixel_aspect.num;
+ outlink->out_buf->video->sample_aspect_ratio.num = picref->video->sample_aspect_ratio.den;
+ outlink->out_buf->video->sample_aspect_ratio.den = picref->video->sample_aspect_ratio.num;
}
buf_out = avfilter_ref_buffer(outlink->out_buf, ~0);
@@ -153,6 +201,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;
@@ -208,6 +259,13 @@ static int end_frame(AVFilterLink *inlink)
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",
.description = NULL_IF_CONFIG_SMALL("Transpose input video."),
@@ -219,7 +277,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 = draw_slice,
.end_frame = end_frame,
.min_perms = AV_PERM_READ, },
{ .name = NULL}},
@@ -227,4 +287,5 @@ AVFilter avfilter_vf_transpose = {
.config_props = config_props_output,
.type = AVMEDIA_TYPE_VIDEO, },
{ .name = NULL}},
+ .priv_class = &transpose_class,
};
OpenPOWER on IntegriCloud