diff options
Diffstat (limited to 'libavfilter/vf_fieldorder.c')
-rw-r--r-- | libavfilter/vf_fieldorder.c | 97 |
1 files changed, 51 insertions, 46 deletions
diff --git a/libavfilter/vf_fieldorder.c b/libavfilter/vf_fieldorder.c index c05d081..5cc612c 100644 --- a/libavfilter/vf_fieldorder.c +++ b/libavfilter/vf_fieldorder.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2011 Mark Himsley * - * 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 */ @@ -23,9 +23,6 @@ * video field order filter, heavily influenced by vf_pad.c */ -#include <stdio.h> -#include <string.h> - #include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/opt.h" @@ -55,6 +52,7 @@ static int query_formats(AVFilterContext *ctx) while ((desc = av_pix_fmt_desc_next(desc))) { pix_fmt = av_pix_fmt_desc_get_id(desc); if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL || + desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & AV_PIX_FMT_FLAG_BITSTREAM) && desc->nb_components && !desc->log2_chroma_h && (ret = ff_add_format(&formats, pix_fmt)) < 0) { @@ -73,16 +71,8 @@ static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; FieldOrderContext *s = ctx->priv; - int plane; - - /** full an array with the number of bytes that the video - * data occupies per line for each plane of the input video */ - for (plane = 0; plane < 4; plane++) { - s->line_size[plane] = av_image_get_linesize(inlink->format, inlink->w, - plane); - } - return 0; + return av_image_fill_linesizes(s->line_size, inlink->format, inlink->w); } static int filter_frame(AVFilterLink *inlink, AVFrame *frame) @@ -90,8 +80,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) AVFilterContext *ctx = inlink->dst; FieldOrderContext *s = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; - int h, plane, line_step, line_size, line; - uint8_t *data; + int h, plane, src_line_step, dst_line_step, line_size, line; + uint8_t *dst, *src; + AVFrame *out; if (!frame->interlaced_frame || frame->top_field_first == s->dst_tff) { @@ -102,14 +93,27 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) return ff_filter_frame(outlink, frame); } + if (av_frame_is_writable(frame)) { + out = frame; + } else { + out = ff_get_video_buffer(outlink, outlink->w, outlink->h); + if (!out) { + av_frame_free(&frame); + return AVERROR(ENOMEM); + } + av_frame_copy_props(out, frame); + } + av_dlog(ctx, "picture will move %s one line\n", s->dst_tff ? "up" : "down"); h = frame->height; - for (plane = 0; plane < 4 && frame->data[plane]; plane++) { - line_step = frame->linesize[plane]; + for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) { + dst_line_step = out->linesize[plane]; + src_line_step = frame->linesize[plane]; line_size = s->line_size[plane]; - data = frame->data[plane]; + dst = out->data[plane]; + src = frame->data[plane]; if (s->dst_tff) { /** Move every line up one line, working from * the top to the bottom of the frame. @@ -118,11 +122,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) * penultimate line from that field. */ for (line = 0; line < h; line++) { if (1 + line < frame->height) { - memcpy(data, data + line_step, line_size); + memcpy(dst, src + src_line_step, line_size); } else { - memcpy(data, data - line_step - line_step, line_size); + memcpy(dst, src - 2 * src_line_step, line_size); } - data += line_step; + dst += dst_line_step; + src += src_line_step; } } else { /** Move every line down one line, working from @@ -130,45 +135,44 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) * The original bottom line is lost. * The new first line is created as a copy of the * second line from that field. */ - data += (h - 1) * line_step; + dst += (h - 1) * dst_line_step; + src += (h - 1) * src_line_step; for (line = h - 1; line >= 0 ; line--) { if (line > 0) { - memcpy(data, data - line_step, line_size); + memcpy(dst, src - src_line_step, line_size); } else { - memcpy(data, data + line_step + line_step, line_size); + memcpy(dst, src + 2 * src_line_step, line_size); } - data -= line_step; + dst -= dst_line_step; + src -= src_line_step; } } } - frame->top_field_first = s->dst_tff; + out->top_field_first = s->dst_tff; - return ff_filter_frame(outlink, frame); + if (frame != out) + av_frame_free(&frame); + return ff_filter_frame(outlink, out); } #define OFFSET(x) offsetof(FieldOrderContext, x) -#define FLAGS AV_OPT_FLAG_VIDEO_PARAM -static const AVOption options[] = { +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM + +static const AVOption fieldorder_options[] = { { "order", "output field order", OFFSET(dst_tff), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS, "order" }, - { "bff", "bottom field first", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, .unit = "order" }, - { "tff", "top field first", 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, .unit = "order" }, - { NULL }, + { "bff", "bottom field first", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, .flags=FLAGS, .unit = "order" }, + { "tff", "top field first", 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, .flags=FLAGS, .unit = "order" }, + { NULL } }; -static const AVClass fieldorder_class = { - .class_name = "fieldorder", - .item_name = av_default_item_name, - .option = options, - .version = LIBAVUTIL_VERSION_INT, -}; +AVFILTER_DEFINE_CLASS(fieldorder); static const AVFilterPad avfilter_vf_fieldorder_inputs[] = { { - .name = "default", - .type = AVMEDIA_TYPE_VIDEO, - .config_props = config_input, - .filter_frame = filter_frame, - .needs_writable = 1, + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_input, + .filter_frame = filter_frame, }, { NULL } }; @@ -189,4 +193,5 @@ AVFilter ff_vf_fieldorder = { .query_formats = query_formats, .inputs = avfilter_vf_fieldorder_inputs, .outputs = avfilter_vf_fieldorder_outputs, + .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, }; |