[FFmpeg-devel] [PATCH 3/4] avfilter: Set output link colour range where appropriate
Philip Langdale
philipl at overt.org
Mon Feb 19 20:48:24 EET 2018
Certain filters set or modify the output colour range. Today, they
do that per-frame, but now that we have a link property, they need
to set that as well.
Signed-off-by: Philip Langdale <philipl at overt.org>
---
libavfilter/avf_showcqt.c | 1 +
libavfilter/avf_showspectrum.c | 1 +
libavfilter/vf_colorspace.c | 4 ++++
libavfilter/vf_scale.c | 8 +++++++-
libavfilter/vf_setparams.c | 11 +++++++++++
libavfilter/vf_waveform.c | 1 +
libavfilter/vf_zscale.c | 21 +++++++++++++++++++--
7 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/libavfilter/avf_showcqt.c b/libavfilter/avf_showcqt.c
index 875ba48cee..ee6654358a 100644
--- a/libavfilter/avf_showcqt.c
+++ b/libavfilter/avf_showcqt.c
@@ -1363,6 +1363,7 @@ static int config_output(AVFilterLink *outlink)
outlink->h = s->height;
s->format = outlink->format;
outlink->sample_aspect_ratio = av_make_q(1, 1);
+ outlink->color_range = AVCOL_RANGE_JPEG;
outlink->frame_rate = s->rate;
outlink->time_base = av_mul_q(av_inv_q(s->rate), av_make_q(1, PTS_STEP));
av_log(ctx, AV_LOG_INFO, "video: %dx%d %s %d/%d fps, bar_h = %d, axis_h = %d, sono_h = %d.\n",
diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c
index 956f62f3ad..52fa018317 100644
--- a/libavfilter/avf_showspectrum.c
+++ b/libavfilter/avf_showspectrum.c
@@ -307,6 +307,7 @@ static int config_output(AVFilterLink *outlink)
outlink->w = s->w;
outlink->h = s->h;
outlink->sample_aspect_ratio = (AVRational){1,1};
+ outlink->color_range = AVCOL_RANGE_JPEG;
if (s->legend) {
s->start_x = log10(inlink->sample_rate) * 25;
diff --git a/libavfilter/vf_colorspace.c b/libavfilter/vf_colorspace.c
index 71ea08a20f..5455648710 100644
--- a/libavfilter/vf_colorspace.c
+++ b/libavfilter/vf_colorspace.c
@@ -1048,6 +1048,7 @@ static int config_props(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->dst;
AVFilterLink *inlink = outlink->src->inputs[0];
+ ColorSpaceContext *s = ctx->priv;
if (inlink->w % 2 || inlink->h % 2) {
av_log(ctx, AV_LOG_ERROR, "Invalid odd size (%dx%d)\n",
@@ -1060,6 +1061,9 @@ static int config_props(AVFilterLink *outlink)
outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
outlink->time_base = inlink->time_base;
+ if (s->user_rng != AVCOL_RANGE_UNSPECIFIED)
+ outlink->color_range = s->user_rng;
+
return 0;
}
diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 9f45032e85..21ae709d6b 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -342,11 +342,16 @@ static int config_props(AVFilterLink *outlink)
} else
outlink->sample_aspect_ratio = inlink0->sample_aspect_ratio;
- av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s sar:%d/%d -> w:%d h:%d fmt:%s sar:%d/%d flags:0x%0x\n",
+ if (scale->out_range != AVCOL_RANGE_UNSPECIFIED)
+ outlink->color_range = scale->out_range;
+
+ av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s sar:%d/%d range:%d -> w:%d h:%d fmt:%s sar:%d/%d range:%d flags:0x%0x\n",
inlink ->w, inlink ->h, av_get_pix_fmt_name( inlink->format),
inlink->sample_aspect_ratio.num, inlink->sample_aspect_ratio.den,
+ inlink->color_range,
outlink->w, outlink->h, av_get_pix_fmt_name(outlink->format),
outlink->sample_aspect_ratio.num, outlink->sample_aspect_ratio.den,
+ outlink->color_range,
scale->flags);
return 0;
@@ -363,6 +368,7 @@ static int config_props_ref(AVFilterLink *outlink)
outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
outlink->time_base = inlink->time_base;
outlink->frame_rate = inlink->frame_rate;
+ outlink->color_range = inlink->color_range;
return 0;
}
diff --git a/libavfilter/vf_setparams.c b/libavfilter/vf_setparams.c
index 8427f98ba8..2b47e2d20b 100644
--- a/libavfilter/vf_setparams.c
+++ b/libavfilter/vf_setparams.c
@@ -56,6 +56,16 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
return ff_filter_frame(ctx->outputs[0], frame);
}
+static int config_output(AVFilterLink *outlink)
+{
+ AVFilterContext *ctx = outlink->src;
+ SetParamsContext *s = ctx->priv;
+
+ if (s->color_range >= 0)
+ outlink->color_range = s->color_range;
+ return 0;
+}
+
static const AVFilterPad inputs[] = {
{
.name = "default",
@@ -69,6 +79,7 @@ static const AVFilterPad outputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_VIDEO,
+ .config_props = config_output,
},
{ NULL }
};
diff --git a/libavfilter/vf_waveform.c b/libavfilter/vf_waveform.c
index 02a7046f33..b610336ea2 100644
--- a/libavfilter/vf_waveform.c
+++ b/libavfilter/vf_waveform.c
@@ -2744,6 +2744,7 @@ static int config_output(AVFilterLink *outlink)
}
outlink->sample_aspect_ratio = (AVRational){1,1};
+ outlink->color_range = AVCOL_RANGE_JPEG;
return 0;
}
diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index 6e1d36cb4c..c1cd55bd36 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -299,11 +299,16 @@ static int config_props(AVFilterLink *outlink)
} else
outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
- av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s sar:%d/%d -> w:%d h:%d fmt:%s sar:%d/%d\n",
+ if (s->range > -1)
+ outlink->color_range = convert_zimg_range(s->range);
+
+ av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s sar:%d/%d range: %d-> w:%d h:%d fmt:%s sar:%d/%d range:%d\n",
inlink ->w, inlink ->h, av_get_pix_fmt_name( inlink->format),
inlink->sample_aspect_ratio.num, inlink->sample_aspect_ratio.den,
+ inlink->color_range,
outlink->w, outlink->h, av_get_pix_fmt_name(outlink->format),
- outlink->sample_aspect_ratio.num, outlink->sample_aspect_ratio.den);
+ outlink->sample_aspect_ratio.num, outlink->sample_aspect_ratio.den,
+ outlink->color_range);
return 0;
fail:
@@ -457,6 +462,18 @@ static int convert_range(enum AVColorRange color_range)
return ZIMG_RANGE_LIMITED;
}
+static int convert_zimg_range(int zimg_range)
+{
+ switch (zimg_range) {
+ case ZIMG_RANGE_LIMITED:
+ return AVCOL_RANGE_MPEG;
+ case ZIMG_RANGE_FULL:
+ return AVCOL_RANGE_JPEG;
+ default:
+ return AVCOL_RANGE_UNSPECIFIED;
+ }
+}
+
static void format_init(zimg_image_format *format, AVFrame *frame, const AVPixFmtDescriptor *desc,
int colorspace, int primaries, int transfer, int range, int location)
{
--
2.14.1
More information about the ffmpeg-devel
mailing list