lavfi/transpose: implement landscape passthrough mode

Emulate the mp=rotate passthrough mode.
This commit is contained in:
Stefano Sabatini 2012-09-01 11:14:27 +02:00
parent 3b34cbce19
commit 9de7622927
3 changed files with 47 additions and 9 deletions

View File

@ -3454,7 +3454,7 @@ It accepts a parameter representing an integer, which can assume the
values:
@table @samp
@item 0
@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
@item 1
@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
@item 2
@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
@item 3
@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.

View File

@ -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, \

View File

@ -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}},