avfilter/vf_setparams: allow setting chroma location

Shockingly, there isn't currently _any_ filter for overriding this.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
Niklas Haas 2024-07-04 12:52:08 +02:00 committed by Paul B Mahol
parent 4285516123
commit c83e625e0b
6 changed files with 42 additions and 12 deletions

View File

@ -21686,6 +21686,23 @@ Keep the same colorspace property (default).
@item chroma-derived-c
@item ictcp
@end table
@item chroma_location
Set the chroma sample location.
Available values are:
@table @samp
@item auto
Keep the same chroma location (default).
@item unspecified, unknown
@item left
@item center
@item topleft
@item top
@item bottomleft
@item bottom
@end table
@end table
@section sharpen_npp

View File

@ -185,7 +185,7 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
link->srcpad = &src->output_pads[srcpad];
link->dstpad = &dst->input_pads[dstpad];
link->type = src->output_pads[srcpad].type;
link->graph = src->graph;
li->l.graph = src->graph;
av_assert0(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1);
link->format = -1;
link->colorspace = AVCOL_SPC_UNSPECIFIED;
@ -231,8 +231,8 @@ static void update_link_current_pts(FilterLinkInternal *li, int64_t pts)
li->l.current_pts = pts;
li->l.current_pts_us = av_rescale_q(pts, link->time_base, AV_TIME_BASE_Q);
/* TODO use duration */
if (link->graph && li->age_index >= 0)
ff_avfilter_graph_update_heap(link->graph, li);
if (li->l.graph && li->age_index >= 0)
ff_avfilter_graph_update_heap(li->l.graph, li);
}
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)

View File

@ -595,11 +595,6 @@ struct AVFilterLink {
* Lists of supported formats / etc. supported by the output filter.
*/
AVFilterFormatsConfig outcfg;
/**
* Graph the filter belongs to.
*/
struct AVFilterGraph *graph;
};
/**

View File

@ -105,7 +105,7 @@ void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter
filter->graph = NULL;
for (j = 0; j<filter->nb_outputs; j++)
if (filter->outputs[j])
filter->outputs[j]->graph = NULL;
ff_filter_link(filter->outputs[j])->graph = NULL;
return;
}

View File

@ -42,6 +42,11 @@
typedef struct FilterLink {
AVFilterLink pub;
/**
* Graph the filter belongs to.
*/
struct AVFilterGraph *graph;
/**
* Current timestamp of the link, as defined by the most recent
* frame(s), in link time_base units.

View File

@ -41,6 +41,7 @@ typedef struct SetParamsContext {
int color_primaries;
int color_trc;
int colorspace;
int chroma_location;
} SetParamsContext;
#define OFFSET(x) offsetof(SetParamsContext, x)
@ -119,6 +120,17 @@ static const AVOption setparams_options[] = {
{"chroma-derived-c", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_CHROMA_DERIVED_CL}, 0, 0, FLAGS, .unit = "colorspace"},
{"ictcp", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_ICTCP}, 0, 0, FLAGS, .unit = "colorspace"},
{"ipt-c2", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_IPT_C2}, 0, 0, FLAGS, .unit = "colorspace"},
{"chroma_location", "select chroma sample location", OFFSET(chroma_location), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCHROMA_LOC_NB-1, FLAGS, .unit = "chroma_location"},
{"auto", "keep the same chroma location", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, FLAGS, .unit = "chroma_location"},
{"unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_UNSPECIFIED}, 0, 0, FLAGS, .unit = "chroma_location"},
{"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_UNSPECIFIED}, 0, 0, FLAGS, .unit = "chroma_location"},
{"left", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_LEFT}, 0, 0, FLAGS, .unit = "chroma_location"},
{"center", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_CENTER}, 0, 0, FLAGS, .unit = "chroma_location"},
{"topleft", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_TOPLEFT}, 0, 0, FLAGS, .unit = "chroma_location"},
{"top", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_TOP}, 0, 0, FLAGS, .unit = "chroma_location"},
{"bottomleft", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_BOTTOMLEFT}, 0, 0, FLAGS, .unit = "chroma_location"},
{"bottom", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_BOTTOM}, 0, 0, FLAGS, .unit = "chroma_location"},
{NULL}
};
@ -174,17 +186,18 @@ FF_ENABLE_DEPRECATION_WARNINGS
frame->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
}
/* set range */
/* set straightforward parameters */
if (s->color_range >= 0)
frame->color_range = s->color_range;
/* set color prim, trc, space */
if (s->color_primaries >= 0)
frame->color_primaries = s->color_primaries;
if (s->color_trc >= 0)
frame->color_trc = s->color_trc;
if (s->colorspace >= 0)
frame->colorspace = s->colorspace;
if (s->chroma_location >= 0)
frame->chroma_location = s->chroma_location;
return ff_filter_frame(ctx->outputs[0], frame);
}