2011-06-25 14:06:24 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 Stefano Sabatini
|
|
|
|
* Copyright (c) 2010 Baptiste Coudurier
|
|
|
|
* Copyright (c) 2003 Michael Zucchi <notzed@ximian.com>
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with FFmpeg if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* temporal field interlace filter, ported from MPlayer/libmpcodecs
|
|
|
|
*/
|
|
|
|
|
2012-12-07 00:03:02 +03:00
|
|
|
#include "libavutil/opt.h"
|
2011-06-25 14:06:24 +03:00
|
|
|
#include "libavutil/imgutils.h"
|
2012-07-08 04:46:59 +03:00
|
|
|
#include "libavutil/avassert.h"
|
2011-06-25 14:06:24 +03:00
|
|
|
#include "avfilter.h"
|
|
|
|
#include "internal.h"
|
|
|
|
|
2012-04-29 17:45:35 +03:00
|
|
|
enum TInterlaceMode {
|
|
|
|
MODE_MERGE = 0,
|
|
|
|
MODE_DROP_EVEN,
|
|
|
|
MODE_DROP_ODD,
|
|
|
|
MODE_PAD,
|
|
|
|
MODE_INTERLEAVE_TOP,
|
|
|
|
MODE_INTERLEAVE_BOTTOM,
|
|
|
|
MODE_INTERLACEX2,
|
2012-12-07 00:03:02 +03:00
|
|
|
MODE_NB,
|
2012-04-29 17:45:35 +03:00
|
|
|
};
|
|
|
|
|
2011-06-25 14:06:24 +03:00
|
|
|
typedef struct {
|
2012-12-07 00:03:02 +03:00
|
|
|
const AVClass *class;
|
2012-04-29 17:45:35 +03:00
|
|
|
enum TInterlaceMode mode; ///< interlace mode selected
|
2012-12-30 17:02:16 +03:00
|
|
|
int flags; ///< flags affecting interlacing algorithm
|
2011-06-25 14:06:24 +03:00
|
|
|
int frame; ///< number of the output frame
|
|
|
|
int vsub; ///< chroma vertical subsampling
|
2013-03-10 03:30:30 +03:00
|
|
|
AVFrame *cur;
|
|
|
|
AVFrame *next;
|
2011-06-25 14:06:24 +03:00
|
|
|
uint8_t *black_data[4]; ///< buffer used to fill padded lines
|
|
|
|
int black_linesize[4];
|
|
|
|
} TInterlaceContext;
|
|
|
|
|
2012-12-07 00:03:02 +03:00
|
|
|
#define OFFSET(x) offsetof(TInterlaceContext, x)
|
|
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
|
2012-12-30 17:02:16 +03:00
|
|
|
#define TINTERLACE_FLAG_VLPF 01
|
2012-12-07 00:03:02 +03:00
|
|
|
|
|
|
|
static const AVOption tinterlace_options[] = {
|
|
|
|
{"mode", "select interlace mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_MERGE}, 0, MODE_NB-1, FLAGS, "mode"},
|
|
|
|
{"merge", "merge fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_MERGE}, INT_MIN, INT_MAX, FLAGS, "mode"},
|
|
|
|
{"drop_even", "drop even fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_DROP_EVEN}, INT_MIN, INT_MAX, FLAGS, "mode"},
|
|
|
|
{"drop_odd", "drop odd fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_DROP_ODD}, INT_MIN, INT_MAX, FLAGS, "mode"},
|
|
|
|
{"pad", "pad alternate lines with black", 0, AV_OPT_TYPE_CONST, {.i64=MODE_PAD}, INT_MIN, INT_MAX, FLAGS, "mode"},
|
|
|
|
{"interleave_top", "interleave top and bottom fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLEAVE_TOP}, INT_MIN, INT_MAX, FLAGS, "mode"},
|
|
|
|
{"interleave_bottom", "interleave bottom and top fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLEAVE_BOTTOM}, INT_MIN, INT_MAX, FLAGS, "mode"},
|
|
|
|
{"interlacex2", "interlace fields from two consecutive frames", 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLACEX2}, INT_MIN, INT_MAX, FLAGS, "mode"},
|
|
|
|
|
2012-12-30 17:02:16 +03:00
|
|
|
{"flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, INT_MAX, 0, "flags" },
|
|
|
|
{"low_pass_filter", "enable vertical low-pass filter", 0, AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_VLPF}, INT_MIN, INT_MAX, FLAGS, "flags" },
|
|
|
|
{"vlpf", "enable vertical low-pass filter", 0, AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_VLPF}, INT_MIN, INT_MAX, FLAGS, "flags" },
|
|
|
|
|
2012-12-07 00:03:02 +03:00
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
AVFILTER_DEFINE_CLASS(tinterlace);
|
|
|
|
|
2011-06-25 14:06:24 +03:00
|
|
|
#define FULL_SCALE_YUVJ_FORMATS \
|
2012-10-08 21:54:00 +03:00
|
|
|
AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P
|
2011-06-25 14:06:24 +03:00
|
|
|
|
2012-10-08 21:54:00 +03:00
|
|
|
static enum AVPixelFormat full_scale_yuvj_pix_fmts[] = {
|
|
|
|
FULL_SCALE_YUVJ_FORMATS, AV_PIX_FMT_NONE
|
2011-06-25 14:06:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static int query_formats(AVFilterContext *ctx)
|
|
|
|
{
|
2012-10-08 21:54:00 +03:00
|
|
|
static const enum AVPixelFormat pix_fmts[] = {
|
|
|
|
AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P,
|
|
|
|
AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUVA420P,
|
|
|
|
AV_PIX_FMT_GRAY8, FULL_SCALE_YUVJ_FORMATS,
|
|
|
|
AV_PIX_FMT_NONE
|
2011-06-25 14:06:24 +03:00
|
|
|
};
|
|
|
|
|
2012-06-16 12:47:46 +03:00
|
|
|
ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
|
2011-06-25 14:06:24 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-06 01:45:36 +03:00
|
|
|
static av_cold int init(AVFilterContext *ctx, const char *args)
|
2011-06-25 14:06:24 +03:00
|
|
|
{
|
|
|
|
TInterlaceContext *tinterlace = ctx->priv;
|
2012-12-07 00:03:02 +03:00
|
|
|
static const char *shorthand[] = { "mode", NULL };
|
2011-06-25 14:06:24 +03:00
|
|
|
|
2012-12-07 00:03:02 +03:00
|
|
|
tinterlace->class = &tinterlace_class;
|
|
|
|
av_opt_set_defaults(tinterlace);
|
|
|
|
|
|
|
|
return av_opt_set_from_string(tinterlace, args, shorthand, "=", ":");
|
2011-06-25 14:06:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold void uninit(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
TInterlaceContext *tinterlace = ctx->priv;
|
|
|
|
|
2013-03-10 03:30:30 +03:00
|
|
|
av_frame_free(&tinterlace->cur );
|
|
|
|
av_frame_free(&tinterlace->next);
|
2011-06-25 14:06:24 +03:00
|
|
|
|
2012-12-07 00:03:02 +03:00
|
|
|
av_opt_free(tinterlace);
|
2011-06-25 14:06:24 +03:00
|
|
|
av_freep(&tinterlace->black_data[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int config_out_props(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = outlink->src;
|
|
|
|
AVFilterLink *inlink = outlink->src->inputs[0];
|
2012-10-20 07:43:48 +03:00
|
|
|
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
|
2011-06-25 14:06:24 +03:00
|
|
|
TInterlaceContext *tinterlace = ctx->priv;
|
|
|
|
|
|
|
|
tinterlace->vsub = desc->log2_chroma_h;
|
|
|
|
outlink->w = inlink->w;
|
2012-04-29 17:45:35 +03:00
|
|
|
outlink->h = tinterlace->mode == MODE_MERGE || tinterlace->mode == MODE_PAD ?
|
2011-06-25 14:06:24 +03:00
|
|
|
inlink->h*2 : inlink->h;
|
|
|
|
|
2012-04-29 17:45:35 +03:00
|
|
|
if (tinterlace->mode == MODE_PAD) {
|
2011-06-25 14:06:24 +03:00
|
|
|
uint8_t black[4] = { 16, 128, 128, 16 };
|
|
|
|
int i, ret;
|
|
|
|
if (ff_fmt_is_in(outlink->format, full_scale_yuvj_pix_fmts))
|
|
|
|
black[0] = black[3] = 0;
|
|
|
|
ret = av_image_alloc(tinterlace->black_data, tinterlace->black_linesize,
|
|
|
|
outlink->w, outlink->h, outlink->format, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* fill black picture with black */
|
|
|
|
for (i = 0; i < 4 && tinterlace->black_data[i]; i++) {
|
|
|
|
int h = i == 1 || i == 2 ? outlink->h >> desc->log2_chroma_h : outlink->h;
|
|
|
|
memset(tinterlace->black_data[i], black[i],
|
|
|
|
tinterlace->black_linesize[i] * h);
|
|
|
|
}
|
|
|
|
}
|
2012-12-30 17:02:16 +03:00
|
|
|
if ((tinterlace->flags & TINTERLACE_FLAG_VLPF)
|
|
|
|
&& !(tinterlace->mode == MODE_INTERLEAVE_TOP
|
|
|
|
|| tinterlace->mode == MODE_INTERLEAVE_BOTTOM)) {
|
|
|
|
av_log(ctx, AV_LOG_WARNING, "low_pass_filter flag ignored with mode %d\n",
|
|
|
|
tinterlace->mode);
|
2013-01-06 06:12:20 +03:00
|
|
|
tinterlace->flags &= ~TINTERLACE_FLAG_VLPF;
|
2012-12-30 17:02:16 +03:00
|
|
|
}
|
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "mode:%d filter:%s h:%d -> h:%d\n",
|
|
|
|
tinterlace->mode, (tinterlace->flags & TINTERLACE_FLAG_VLPF) ? "on" : "off",
|
|
|
|
inlink->h, outlink->h);
|
2011-06-25 14:06:24 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FIELD_UPPER 0
|
|
|
|
#define FIELD_LOWER 1
|
|
|
|
#define FIELD_UPPER_AND_LOWER 2
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy picture field from src to dst.
|
|
|
|
*
|
|
|
|
* @param src_field copy from upper, lower field or both
|
2012-04-27 23:11:15 +03:00
|
|
|
* @param interleave leave a padding line between each copied line
|
2011-06-25 14:06:24 +03:00
|
|
|
* @param dst_field copy to upper or lower field,
|
|
|
|
* only meaningful when interleave is selected
|
2012-12-30 17:02:16 +03:00
|
|
|
* @param flags context flags
|
2011-06-25 14:06:24 +03:00
|
|
|
*/
|
|
|
|
static inline
|
|
|
|
void copy_picture_field(uint8_t *dst[4], int dst_linesize[4],
|
2012-09-05 11:37:12 +03:00
|
|
|
const uint8_t *src[4], int src_linesize[4],
|
2012-10-08 21:54:00 +03:00
|
|
|
enum AVPixelFormat format, int w, int src_h,
|
2012-12-30 17:02:16 +03:00
|
|
|
int src_field, int interleave, int dst_field,
|
|
|
|
int flags)
|
2011-06-25 14:06:24 +03:00
|
|
|
{
|
2012-10-20 07:43:48 +03:00
|
|
|
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);
|
2011-06-25 14:06:24 +03:00
|
|
|
int plane, vsub = desc->log2_chroma_h;
|
|
|
|
int k = src_field == FIELD_UPPER_AND_LOWER ? 1 : 2;
|
2012-12-30 18:59:52 +03:00
|
|
|
int h, i;
|
2011-06-25 14:06:24 +03:00
|
|
|
|
|
|
|
for (plane = 0; plane < desc->nb_components; plane++) {
|
|
|
|
int lines = plane == 1 || plane == 2 ? src_h >> vsub : src_h;
|
|
|
|
int linesize = av_image_get_linesize(format, w, plane);
|
|
|
|
uint8_t *dstp = dst[plane];
|
2012-09-05 11:37:12 +03:00
|
|
|
const uint8_t *srcp = src[plane];
|
2012-11-03 04:21:49 +03:00
|
|
|
|
|
|
|
if (linesize < 0)
|
|
|
|
return;
|
|
|
|
|
2011-06-25 14:06:24 +03:00
|
|
|
lines /= k;
|
|
|
|
if (src_field == FIELD_LOWER)
|
|
|
|
srcp += src_linesize[plane];
|
|
|
|
if (interleave && dst_field == FIELD_LOWER)
|
|
|
|
dstp += dst_linesize[plane];
|
2012-12-30 17:02:16 +03:00
|
|
|
if (flags & TINTERLACE_FLAG_VLPF) {
|
|
|
|
// Low-pass filtering is required when creating an interlaced destination from
|
|
|
|
// a progressive source which contains high-frequency vertical detail.
|
|
|
|
// Filtering will reduce interlace 'twitter' and Moire patterning.
|
|
|
|
int srcp_linesize = src_linesize[plane] * k;
|
|
|
|
int dstp_linesize = dst_linesize[plane] * (interleave ? 2 : 1);
|
2012-12-30 18:59:52 +03:00
|
|
|
for (h = lines; h > 0; h--) {
|
2012-12-30 17:02:16 +03:00
|
|
|
const uint8_t *srcp_above = srcp - src_linesize[plane];
|
|
|
|
const uint8_t *srcp_below = srcp + src_linesize[plane];
|
|
|
|
if (h == lines) srcp_above = srcp; // there is no line above
|
|
|
|
if (h == 1) srcp_below = srcp; // there is no line below
|
2012-12-30 18:59:52 +03:00
|
|
|
for (i = 0; i < linesize; i++) {
|
2012-12-30 17:02:16 +03:00
|
|
|
// this calculation is an integer representation of
|
|
|
|
// '0.5 * current + 0.25 * above + 0.25 + below'
|
|
|
|
// '1 +' is for rounding. */
|
|
|
|
dstp[i] = (1 + srcp[i] + srcp[i] + srcp_above[i] + srcp_below[i]) >> 2;
|
|
|
|
}
|
|
|
|
dstp += dstp_linesize;
|
|
|
|
srcp += srcp_linesize;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
av_image_copy_plane(dstp, dst_linesize[plane] * (interleave ? 2 : 1),
|
2011-06-25 14:06:24 +03:00
|
|
|
srcp, src_linesize[plane]*k, linesize, lines);
|
2012-12-30 17:02:16 +03:00
|
|
|
}
|
2011-06-25 14:06:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-10 03:30:30 +03:00
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
|
2011-06-25 14:06:24 +03:00
|
|
|
{
|
|
|
|
AVFilterContext *ctx = inlink->dst;
|
2012-12-06 16:40:36 +03:00
|
|
|
AVFilterLink *outlink = ctx->outputs[0];
|
2011-06-25 14:06:24 +03:00
|
|
|
TInterlaceContext *tinterlace = ctx->priv;
|
2013-03-10 03:30:30 +03:00
|
|
|
AVFrame *cur, *next, *out;
|
2012-12-06 16:40:36 +03:00
|
|
|
int field, tff, ret;
|
2011-06-25 14:06:24 +03:00
|
|
|
|
2013-03-10 03:30:30 +03:00
|
|
|
av_frame_free(&tinterlace->cur);
|
2011-06-25 14:06:24 +03:00
|
|
|
tinterlace->cur = tinterlace->next;
|
|
|
|
tinterlace->next = picref;
|
|
|
|
|
2012-12-06 16:40:36 +03:00
|
|
|
cur = tinterlace->cur;
|
|
|
|
next = tinterlace->next;
|
2011-06-25 14:06:24 +03:00
|
|
|
/* we need at least two frames */
|
|
|
|
if (!tinterlace->cur)
|
2012-07-22 23:57:02 +03:00
|
|
|
return 0;
|
2011-06-25 14:06:24 +03:00
|
|
|
|
|
|
|
switch (tinterlace->mode) {
|
2012-04-29 17:45:35 +03:00
|
|
|
case MODE_MERGE: /* move the odd frame into the upper field of the new image, even into
|
2011-06-25 14:06:24 +03:00
|
|
|
* the lower field, generating a double-height video at half framerate */
|
2013-03-10 03:30:30 +03:00
|
|
|
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
|
2012-12-06 16:40:36 +03:00
|
|
|
if (!out)
|
|
|
|
return AVERROR(ENOMEM);
|
2013-03-10 03:30:30 +03:00
|
|
|
av_frame_copy_props(out, cur);
|
|
|
|
out->height = outlink->h;
|
|
|
|
out->interlaced_frame = 1;
|
|
|
|
out->top_field_first = 1;
|
2011-06-25 14:06:24 +03:00
|
|
|
|
|
|
|
/* write odd frame lines into the upper field of the new frame */
|
|
|
|
copy_picture_field(out->data, out->linesize,
|
2012-09-05 11:37:12 +03:00
|
|
|
(const uint8_t **)cur->data, cur->linesize,
|
2011-06-25 14:06:24 +03:00
|
|
|
inlink->format, inlink->w, inlink->h,
|
2012-12-30 17:02:16 +03:00
|
|
|
FIELD_UPPER_AND_LOWER, 1, FIELD_UPPER, tinterlace->flags);
|
2011-06-25 14:06:24 +03:00
|
|
|
/* write even frame lines into the lower field of the new frame */
|
|
|
|
copy_picture_field(out->data, out->linesize,
|
2012-09-05 11:37:12 +03:00
|
|
|
(const uint8_t **)next->data, next->linesize,
|
2011-06-25 14:06:24 +03:00
|
|
|
inlink->format, inlink->w, inlink->h,
|
2012-12-30 17:02:16 +03:00
|
|
|
FIELD_UPPER_AND_LOWER, 1, FIELD_LOWER, tinterlace->flags);
|
2013-03-10 03:30:30 +03:00
|
|
|
av_frame_free(&tinterlace->next);
|
2011-06-25 14:06:24 +03:00
|
|
|
break;
|
|
|
|
|
2012-04-29 17:45:35 +03:00
|
|
|
case MODE_DROP_ODD: /* only output even frames, odd frames are dropped; height unchanged, half framerate */
|
|
|
|
case MODE_DROP_EVEN: /* only output odd frames, even frames are dropped; height unchanged, half framerate */
|
2013-03-10 03:30:30 +03:00
|
|
|
out = av_frame_clone(tinterlace->mode == MODE_DROP_EVEN ? cur : next);
|
|
|
|
av_frame_free(&tinterlace->next);
|
2011-06-25 14:06:24 +03:00
|
|
|
break;
|
|
|
|
|
2012-04-29 17:45:35 +03:00
|
|
|
case MODE_PAD: /* expand each frame to double height, but pad alternate
|
|
|
|
* lines with black; framerate unchanged */
|
2013-03-10 03:30:30 +03:00
|
|
|
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
|
|
|
|
av_frame_copy_props(out, cur);
|
|
|
|
out->height = outlink->h;
|
2011-06-25 14:06:24 +03:00
|
|
|
|
|
|
|
field = (1 + tinterlace->frame) & 1 ? FIELD_UPPER : FIELD_LOWER;
|
|
|
|
/* copy upper and lower fields */
|
|
|
|
copy_picture_field(out->data, out->linesize,
|
2012-09-05 11:37:12 +03:00
|
|
|
(const uint8_t **)cur->data, cur->linesize,
|
2011-06-25 14:06:24 +03:00
|
|
|
inlink->format, inlink->w, inlink->h,
|
2012-12-30 17:02:16 +03:00
|
|
|
FIELD_UPPER_AND_LOWER, 1, field, tinterlace->flags);
|
2011-06-25 14:06:24 +03:00
|
|
|
/* pad with black the other field */
|
|
|
|
copy_picture_field(out->data, out->linesize,
|
2012-09-05 11:37:12 +03:00
|
|
|
(const uint8_t **)tinterlace->black_data, tinterlace->black_linesize,
|
2011-06-25 14:06:24 +03:00
|
|
|
inlink->format, inlink->w, inlink->h,
|
2012-12-30 17:02:16 +03:00
|
|
|
FIELD_UPPER_AND_LOWER, 1, !field, tinterlace->flags);
|
2011-06-25 14:06:24 +03:00
|
|
|
break;
|
|
|
|
|
2011-12-31 16:12:01 +03:00
|
|
|
/* interleave upper/lower lines from odd frames with lower/upper lines from even frames,
|
|
|
|
* halving the frame rate and preserving image height */
|
2012-04-29 17:45:35 +03:00
|
|
|
case MODE_INTERLEAVE_TOP: /* top field first */
|
|
|
|
case MODE_INTERLEAVE_BOTTOM: /* bottom field first */
|
|
|
|
tff = tinterlace->mode == MODE_INTERLEAVE_TOP;
|
2013-03-10 03:30:30 +03:00
|
|
|
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
|
2012-12-06 16:40:36 +03:00
|
|
|
if (!out)
|
|
|
|
return AVERROR(ENOMEM);
|
2013-03-10 03:30:30 +03:00
|
|
|
av_frame_copy_props(out, cur);
|
|
|
|
out->interlaced_frame = 1;
|
|
|
|
out->top_field_first = tff;
|
2011-06-25 14:06:24 +03:00
|
|
|
|
2011-12-31 16:12:01 +03:00
|
|
|
/* copy upper/lower field from cur */
|
2011-06-25 14:06:24 +03:00
|
|
|
copy_picture_field(out->data, out->linesize,
|
2012-09-05 11:37:12 +03:00
|
|
|
(const uint8_t **)cur->data, cur->linesize,
|
2011-06-25 14:06:24 +03:00
|
|
|
inlink->format, inlink->w, inlink->h,
|
2012-12-30 17:02:16 +03:00
|
|
|
tff ? FIELD_UPPER : FIELD_LOWER, 1, tff ? FIELD_UPPER : FIELD_LOWER,
|
|
|
|
tinterlace->flags);
|
2011-12-31 16:12:01 +03:00
|
|
|
/* copy lower/upper field from next */
|
2011-06-25 14:06:24 +03:00
|
|
|
copy_picture_field(out->data, out->linesize,
|
2012-09-05 11:37:12 +03:00
|
|
|
(const uint8_t **)next->data, next->linesize,
|
2011-06-25 14:06:24 +03:00
|
|
|
inlink->format, inlink->w, inlink->h,
|
2012-12-30 17:02:16 +03:00
|
|
|
tff ? FIELD_LOWER : FIELD_UPPER, 1, tff ? FIELD_LOWER : FIELD_UPPER,
|
|
|
|
tinterlace->flags);
|
2013-03-10 03:30:30 +03:00
|
|
|
av_frame_free(&tinterlace->next);
|
2011-06-25 14:06:24 +03:00
|
|
|
break;
|
2012-04-29 17:45:35 +03:00
|
|
|
case MODE_INTERLACEX2: /* re-interlace preserving image height, double frame rate */
|
2012-04-29 16:25:57 +03:00
|
|
|
/* output current frame first */
|
2013-03-10 03:30:30 +03:00
|
|
|
out = av_frame_clone(cur);
|
2012-12-06 16:40:36 +03:00
|
|
|
if (!out)
|
|
|
|
return AVERROR(ENOMEM);
|
2013-03-10 03:30:30 +03:00
|
|
|
out->interlaced_frame = 1;
|
2012-04-29 16:25:57 +03:00
|
|
|
|
2012-12-06 16:40:36 +03:00
|
|
|
if ((ret = ff_filter_frame(outlink, out)) < 0)
|
|
|
|
return ret;
|
2012-04-29 16:25:57 +03:00
|
|
|
|
|
|
|
/* output mix of current and next frame */
|
2013-03-10 03:30:30 +03:00
|
|
|
tff = next->top_field_first;
|
|
|
|
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
|
2012-12-06 16:40:36 +03:00
|
|
|
if (!out)
|
|
|
|
return AVERROR(ENOMEM);
|
2013-03-10 03:30:30 +03:00
|
|
|
av_frame_copy_props(out, next);
|
|
|
|
out->interlaced_frame = 1;
|
2012-04-29 16:25:57 +03:00
|
|
|
|
|
|
|
/* write current frame second field lines into the second field of the new frame */
|
|
|
|
copy_picture_field(out->data, out->linesize,
|
2012-09-05 11:37:12 +03:00
|
|
|
(const uint8_t **)cur->data, cur->linesize,
|
2012-04-29 16:25:57 +03:00
|
|
|
inlink->format, inlink->w, inlink->h,
|
2012-12-30 17:02:16 +03:00
|
|
|
tff ? FIELD_LOWER : FIELD_UPPER, 1, tff ? FIELD_LOWER : FIELD_UPPER,
|
|
|
|
tinterlace->flags);
|
2012-04-29 16:25:57 +03:00
|
|
|
/* write next frame first field lines into the first field of the new frame */
|
|
|
|
copy_picture_field(out->data, out->linesize,
|
2012-09-05 11:37:12 +03:00
|
|
|
(const uint8_t **)next->data, next->linesize,
|
2012-04-29 16:25:57 +03:00
|
|
|
inlink->format, inlink->w, inlink->h,
|
2012-12-30 17:02:16 +03:00
|
|
|
tff ? FIELD_UPPER : FIELD_LOWER, 1, tff ? FIELD_UPPER : FIELD_LOWER,
|
|
|
|
tinterlace->flags);
|
2012-04-29 16:25:57 +03:00
|
|
|
break;
|
2012-12-11 01:55:21 +03:00
|
|
|
default:
|
|
|
|
av_assert0(0);
|
2011-06-25 14:06:24 +03:00
|
|
|
}
|
|
|
|
|
2012-12-06 16:40:36 +03:00
|
|
|
ret = ff_filter_frame(outlink, out);
|
2011-06-25 14:06:24 +03:00
|
|
|
tinterlace->frame++;
|
2012-07-22 23:57:02 +03:00
|
|
|
|
2012-12-06 16:40:36 +03:00
|
|
|
return ret;
|
2011-06-25 14:06:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int request_frame(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
TInterlaceContext *tinterlace = outlink->src->priv;
|
|
|
|
AVFilterLink *inlink = outlink->src->inputs[0];
|
|
|
|
|
|
|
|
do {
|
|
|
|
int ret;
|
|
|
|
|
2012-06-24 03:09:53 +03:00
|
|
|
if ((ret = ff_request_frame(inlink)) < 0)
|
2011-06-25 14:06:24 +03:00
|
|
|
return ret;
|
|
|
|
} while (!tinterlace->cur);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-28 22:01:59 +03:00
|
|
|
static const AVFilterPad tinterlace_inputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2012-12-06 16:40:36 +03:00
|
|
|
.filter_frame = filter_frame,
|
2012-11-28 22:01:59 +03:00
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVFilterPad tinterlace_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.config_props = config_out_props,
|
|
|
|
.request_frame = request_frame,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2011-06-25 14:06:24 +03:00
|
|
|
AVFilter avfilter_vf_tinterlace = {
|
|
|
|
.name = "tinterlace",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Perform temporal field interlacing."),
|
|
|
|
.priv_size = sizeof(TInterlaceContext),
|
|
|
|
.init = init,
|
|
|
|
.uninit = uninit,
|
|
|
|
.query_formats = query_formats,
|
2012-11-28 22:01:59 +03:00
|
|
|
.inputs = tinterlace_inputs,
|
|
|
|
.outputs = tinterlace_outputs,
|
2012-12-07 00:03:02 +03:00
|
|
|
.priv_class = &tinterlace_class,
|
2011-06-25 14:06:24 +03:00
|
|
|
};
|