2012-02-02 00:31:00 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 Stefano Sabatini
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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 FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* set field order
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avfilter.h"
|
2012-06-16 11:47:46 +02:00
|
|
|
#include "video.h"
|
2012-02-02 00:31:00 +01:00
|
|
|
|
2012-04-21 10:26:30 +02:00
|
|
|
enum SetFieldMode {
|
|
|
|
MODE_AUTO = -1,
|
|
|
|
MODE_BFF,
|
|
|
|
MODE_TFF,
|
|
|
|
MODE_PROG,
|
|
|
|
};
|
|
|
|
|
2012-02-02 00:31:00 +01:00
|
|
|
typedef struct {
|
2012-04-21 10:26:30 +02:00
|
|
|
enum SetFieldMode mode;
|
2012-02-02 00:31:00 +01:00
|
|
|
} SetFieldContext;
|
|
|
|
|
2012-06-26 23:27:59 +02:00
|
|
|
static av_cold int init(AVFilterContext *ctx, const char *args)
|
2012-02-02 00:31:00 +01:00
|
|
|
{
|
|
|
|
SetFieldContext *setfield = ctx->priv;
|
|
|
|
|
2012-04-21 10:26:30 +02:00
|
|
|
setfield->mode = MODE_AUTO;
|
2012-02-02 00:31:00 +01:00
|
|
|
|
|
|
|
if (args) {
|
|
|
|
char c;
|
2012-04-21 10:26:30 +02:00
|
|
|
if (sscanf(args, "%d%c", &setfield->mode, &c) != 1) {
|
|
|
|
if (!strcmp("tff", args)) setfield->mode = MODE_TFF;
|
|
|
|
else if (!strcmp("bff", args)) setfield->mode = MODE_BFF;
|
|
|
|
else if (!strcmp("prog", args)) setfield->mode = MODE_PROG;
|
|
|
|
else if (!strcmp("auto", args)) setfield->mode = MODE_AUTO;
|
2012-02-02 00:31:00 +01:00
|
|
|
else {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'\n", args);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
2012-04-20 11:51:42 +02:00
|
|
|
} else {
|
2012-04-21 10:26:30 +02:00
|
|
|
if (setfield->mode < -1 || setfield->mode > 1) {
|
2012-04-20 11:51:42 +02:00
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"Provided integer value %d must be included between -1 and +1\n",
|
2012-04-21 10:26:30 +02:00
|
|
|
setfield->mode);
|
2012-04-20 11:51:42 +02:00
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
av_log(ctx, AV_LOG_WARNING,
|
2012-04-21 10:28:37 +02:00
|
|
|
"Using -1/0/1 is deprecated, use auto/tff/bff/prog\n");
|
2012-02-02 00:31:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-22 22:57:02 +02:00
|
|
|
static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
|
2012-02-02 00:31:00 +01:00
|
|
|
{
|
|
|
|
SetFieldContext *setfield = inlink->dst->priv;
|
|
|
|
AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
|
|
|
|
|
2012-04-21 10:26:30 +02:00
|
|
|
if (setfield->mode == MODE_PROG) {
|
2012-04-20 11:51:42 +02:00
|
|
|
outpicref->video->interlaced = 0;
|
2012-04-21 10:26:30 +02:00
|
|
|
} else if (setfield->mode != MODE_AUTO) {
|
2012-02-02 00:31:00 +01:00
|
|
|
outpicref->video->interlaced = 1;
|
2012-04-21 10:26:30 +02:00
|
|
|
outpicref->video->top_field_first = setfield->mode;
|
2012-02-02 00:31:00 +01:00
|
|
|
}
|
2012-07-22 22:57:02 +02:00
|
|
|
return ff_start_frame(inlink->dst->outputs[0], outpicref);
|
2012-02-02 00:31:00 +01:00
|
|
|
}
|
|
|
|
|
2012-11-28 20:01:59 +01:00
|
|
|
static const AVFilterPad setfield_inputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.get_video_buffer = ff_null_get_video_buffer,
|
|
|
|
.start_frame = start_frame,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVFilterPad setfield_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2012-02-02 00:31:00 +01:00
|
|
|
AVFilter avfilter_vf_setfield = {
|
|
|
|
.name = "setfield",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
|
|
|
|
.init = init,
|
|
|
|
|
|
|
|
.priv_size = sizeof(SetFieldContext),
|
2012-11-28 20:01:59 +01:00
|
|
|
.inputs = setfield_inputs,
|
|
|
|
.outputs = setfield_outputs,
|
2012-02-02 00:31:00 +01:00
|
|
|
};
|