]> git.sesse.net Git - ffmpeg/blob - libavfilter/vf_setparams.c
Merge commit '2edaafe5b93832715781851dfe2663da228a05ad'
[ffmpeg] / libavfilter / vf_setparams.c
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #include "libavutil/pixfmt.h"
20 #include "libavutil/opt.h"
21 #include "avfilter.h"
22 #include "internal.h"
23 #include "video.h"
24
25 typedef struct SetParamsContext {
26     const AVClass *class;
27     int color_range;
28 } SetParamsContext;
29
30 #define OFFSET(x) offsetof(SetParamsContext, x)
31 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
32
33 static const AVOption setrange_options[] = {
34     {"range", "select color range", OFFSET(color_range), AV_OPT_TYPE_INT, {.i64=-1},-1, AVCOL_RANGE_NB-1, FLAGS, "range"},
35     {"auto",  "keep the same color range",   0, AV_OPT_TYPE_CONST, {.i64=-1},                       0, 0, FLAGS, "range"},
36     {"unspecified",                  NULL,   0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED},  0, 0, FLAGS, "range"},
37     {"unknown",                      NULL,   0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED},  0, 0, FLAGS, "range"},
38     {"limited",                      NULL,   0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG},         0, 0, FLAGS, "range"},
39     {"tv",                           NULL,   0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG},         0, 0, FLAGS, "range"},
40     {"mpeg",                         NULL,   0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG},         0, 0, FLAGS, "range"},
41     {"full",                         NULL,   0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG},         0, 0, FLAGS, "range"},
42     {"pc",                           NULL,   0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG},         0, 0, FLAGS, "range"},
43     {"jpeg",                         NULL,   0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG},         0, 0, FLAGS, "range"},
44     {NULL}
45 };
46
47 AVFILTER_DEFINE_CLASS(setrange);
48
49 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
50 {
51     AVFilterContext *ctx = inlink->dst;
52     SetParamsContext *s = ctx->priv;
53
54     if (s->color_range >= 0)
55         frame->color_range = s->color_range;
56     return ff_filter_frame(ctx->outputs[0], frame);
57 }
58
59 static const AVFilterPad inputs[] = {
60     {
61         .name         = "default",
62         .type         = AVMEDIA_TYPE_VIDEO,
63         .filter_frame = filter_frame,
64     },
65     { NULL }
66 };
67
68 static const AVFilterPad outputs[] = {
69     {
70         .name = "default",
71         .type = AVMEDIA_TYPE_VIDEO,
72     },
73     { NULL }
74 };
75
76 AVFilter ff_vf_setrange = {
77     .name        = "setrange",
78     .description = NULL_IF_CONFIG_SMALL("Force color range for the output video frame."),
79     .priv_size   = sizeof(SetParamsContext),
80     .priv_class  = &setrange_class,
81     .inputs      = inputs,
82     .outputs     = outputs,
83 };