00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "avfilter.h"
00027
00028 enum SetFieldMode {
00029 MODE_AUTO = -1,
00030 MODE_BFF,
00031 MODE_TFF,
00032 MODE_PROG,
00033 };
00034
00035 typedef struct {
00036 enum SetFieldMode mode;
00037 } SetFieldContext;
00038
00039 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
00040 {
00041 SetFieldContext *setfield = ctx->priv;
00042
00043 setfield->mode = MODE_AUTO;
00044
00045 if (args) {
00046 char c;
00047 if (sscanf(args, "%d%c", &setfield->mode, &c) != 1) {
00048 if (!strcmp("tff", args)) setfield->mode = MODE_TFF;
00049 else if (!strcmp("bff", args)) setfield->mode = MODE_BFF;
00050 else if (!strcmp("prog", args)) setfield->mode = MODE_PROG;
00051 else if (!strcmp("auto", args)) setfield->mode = MODE_AUTO;
00052 else {
00053 av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'\n", args);
00054 return AVERROR(EINVAL);
00055 }
00056 } else {
00057 if (setfield->mode < -1 || setfield->mode > 1) {
00058 av_log(ctx, AV_LOG_ERROR,
00059 "Provided integer value %d must be included between -1 and +1\n",
00060 setfield->mode);
00061 return AVERROR(EINVAL);
00062 }
00063 av_log(ctx, AV_LOG_WARNING,
00064 "Using -1/0/1 is deprecated, use auto/tff/bff/prog\n");
00065 }
00066 }
00067
00068 return 0;
00069 }
00070
00071 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
00072 {
00073 SetFieldContext *setfield = inlink->dst->priv;
00074 AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
00075
00076 if (setfield->mode == MODE_PROG) {
00077 outpicref->video->interlaced = 0;
00078 } else if (setfield->mode != MODE_AUTO) {
00079 outpicref->video->interlaced = 1;
00080 outpicref->video->top_field_first = setfield->mode;
00081 }
00082 avfilter_start_frame(inlink->dst->outputs[0], outpicref);
00083 }
00084
00085 AVFilter avfilter_vf_setfield = {
00086 .name = "setfield",
00087 .description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
00088 .init = init,
00089
00090 .priv_size = sizeof(SetFieldContext),
00091
00092 .inputs = (const AVFilterPad[]) {
00093 { .name = "default",
00094 .type = AVMEDIA_TYPE_VIDEO,
00095 .get_video_buffer = avfilter_null_get_video_buffer,
00096 .start_frame = start_frame, },
00097 { .name = NULL }
00098 },
00099 .outputs = (const AVFilterPad[]) {
00100 { .name = "default",
00101 .type = AVMEDIA_TYPE_VIDEO, },
00102 { .name = NULL }
00103 },
00104 };