diff options
Diffstat (limited to 'libavfilter/vf_transpose.c')
-rw-r--r-- | libavfilter/vf_transpose.c | 65 |
1 files changed, 50 insertions, 15 deletions
diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c index 8135f5b..4161050 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 */ @@ -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); } @@ -75,16 +76,13 @@ static int query_formats(AVFilterContext *ctx) PIX_FMT_BGR555BE, PIX_FMT_BGR555LE, PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE, PIX_FMT_YUV420P16LE, PIX_FMT_YUV420P16BE, - PIX_FMT_YUV422P16LE, PIX_FMT_YUV422P16BE, PIX_FMT_YUV444P16LE, PIX_FMT_YUV444P16BE, PIX_FMT_NV12, PIX_FMT_NV21, PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, - PIX_FMT_YUV444P, PIX_FMT_YUV422P, + PIX_FMT_YUV444P, PIX_FMT_YUVJ444P, PIX_FMT_YUV420P, PIX_FMT_YUVJ420P, - PIX_FMT_YUV411P, PIX_FMT_YUV410P, - PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, - PIX_FMT_YUV440P, PIX_FMT_YUVJ440P, + PIX_FMT_YUV410P, PIX_FMT_YUVA420P, PIX_FMT_GRAY8, PIX_FMT_NONE }; @@ -100,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; @@ -120,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) @@ -132,11 +155,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 +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; @@ -208,6 +234,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 +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 = draw_slice, .end_frame = end_frame, .min_perms = AV_PERM_READ, }, { .name = NULL}}, |