[FFmpeg-devel] [PATCH 2/4] avfilter: Add support for colour range as a link parameter
Philip Langdale
philipl at overt.org
Mon Feb 19 20:48:23 EET 2018
As part of achieving our YUVJ-free future, it needs to be possible
to pass the colour range property from a decoder context to an
encoder context. In the absence of filters, this is obviously
trivial, but as soon as filters are introduced, there needs to
be a way to pass and preserve the property (or modify it, as
some filters will do).
Based on existing properties of this type, this change adds a
link property and ways to set it from a buffer source and get it
from a buffer sink.
Signed-off-by: Philip Langdale <philipl at overt.org>
---
libavfilter/avfilter.c | 2 ++
libavfilter/avfilter.h | 1 +
libavfilter/buffersink.c | 1 +
libavfilter/buffersink.h | 1 +
libavfilter/buffersrc.c | 10 ++++++++--
libavfilter/buffersrc.h | 5 +++++
6 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 7553f7c36a..9b93e8177e 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -338,6 +338,8 @@ int avfilter_config_links(AVFilterContext *filter)
link->w = inlink->w;
if (!link->h)
link->h = inlink->h;
+ if (link->color_range == AVCOL_RANGE_UNSPECIFIED)
+ link->color_range = inlink->color_range;
} else if (!link->w || !link->h) {
av_log(link->src, AV_LOG_ERROR,
"Video source filters must set their output link's "
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 2d1195eeeb..49261ccef8 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -449,6 +449,7 @@ struct AVFilterLink {
int w; ///< agreed upon image width
int h; ///< agreed upon image height
AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
+ enum AVColorRange color_range; ///< agreed upon image color range
/* These parameters apply only to audio */
uint64_t channel_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h)
int sample_rate; ///< samples per second
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index 0f87b5439a..897396cac4 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -194,6 +194,7 @@ MAKE_AVFILTERLINK_ACCESSOR(AVRational , frame_rate )
MAKE_AVFILTERLINK_ACCESSOR(int , w )
MAKE_AVFILTERLINK_ACCESSOR(int , h )
MAKE_AVFILTERLINK_ACCESSOR(AVRational , sample_aspect_ratio)
+MAKE_AVFILTERLINK_ACCESSOR(enum AVColorRange, color_range )
MAKE_AVFILTERLINK_ACCESSOR(int , channels )
MAKE_AVFILTERLINK_ACCESSOR(uint64_t , channel_layout )
diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
index 21d6bb505b..d91e3fe448 100644
--- a/libavfilter/buffersink.h
+++ b/libavfilter/buffersink.h
@@ -114,6 +114,7 @@ AVRational av_buffersink_get_frame_rate (const AVFilterContext *c
int av_buffersink_get_w (const AVFilterContext *ctx);
int av_buffersink_get_h (const AVFilterContext *ctx);
AVRational av_buffersink_get_sample_aspect_ratio (const AVFilterContext *ctx);
+enum AVColorRange av_buffersink_get_color_range (const AVFilterContext *ctx);
int av_buffersink_get_channels (const AVFilterContext *ctx);
uint64_t av_buffersink_get_channel_layout (const AVFilterContext *ctx);
diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index cd56f8ca45..19239c4268 100644
--- a/libavfilter/buffersrc.c
+++ b/libavfilter/buffersrc.c
@@ -53,6 +53,7 @@ typedef struct BufferSourceContext {
enum AVPixelFormat pix_fmt;
AVRational pixel_aspect;
char *sws_param;
+ enum AVColorRange color_range;
AVBufferRef *hw_frames_ctx;
@@ -111,6 +112,8 @@ int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *par
s->pixel_aspect = param->sample_aspect_ratio;
if (param->frame_rate.num > 0 && param->frame_rate.den > 0)
s->frame_rate = param->frame_rate;
+ if (param->color_range != AVCOL_RANGE_UNSPECIFIED)
+ s->color_range = param->color_range;
if (param->hw_frames_ctx) {
av_buffer_unref(&s->hw_frames_ctx);
s->hw_frames_ctx = av_buffer_ref(param->hw_frames_ctx);
@@ -282,10 +285,11 @@ static av_cold int init_video(AVFilterContext *ctx)
if (!(c->fifo = av_fifo_alloc(sizeof(AVFrame*))))
return AVERROR(ENOMEM);
- av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d pixfmt:%s tb:%d/%d fr:%d/%d sar:%d/%d sws_param:%s\n",
+ av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d pixfmt:%s tb:%d/%d fr:%d/%d sar:%d/%d sws_param:%s\n color_range:%s\n",
c->w, c->h, av_get_pix_fmt_name(c->pix_fmt),
c->time_base.num, c->time_base.den, c->frame_rate.num, c->frame_rate.den,
- c->pixel_aspect.num, c->pixel_aspect.den, (char *)av_x_if_null(c->sws_param, ""));
+ c->pixel_aspect.num, c->pixel_aspect.den, (char *)av_x_if_null(c->sws_param, ""),
+ av_color_range_name(c->color_range));
c->warning_limit = 100;
return 0;
}
@@ -309,6 +313,7 @@ static const AVOption buffer_options[] = {
{ "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
{ "frame_rate", NULL, OFFSET(frame_rate), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V },
{ "sws_param", NULL, OFFSET(sws_param), AV_OPT_TYPE_STRING, .flags = V },
+ { "color_range", NULL, OFFSET(color_range), AV_OPT_TYPE_COLOR_RANGE, { .i64 = AVCOL_RANGE_UNSPECIFIED }, .min = AVCOL_RANGE_UNSPECIFIED, .max = INT_MAX, .flags = V },
{ NULL },
};
@@ -434,6 +439,7 @@ static int config_props(AVFilterLink *link)
link->w = c->w;
link->h = c->h;
link->sample_aspect_ratio = c->pixel_aspect;
+ link->color_range = c->color_range;
if (c->hw_frames_ctx) {
link->hw_frames_ctx = av_buffer_ref(c->hw_frames_ctx);
diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h
index 0652113f2b..0ea2e436b3 100644
--- a/libavfilter/buffersrc.h
+++ b/libavfilter/buffersrc.h
@@ -114,6 +114,11 @@ typedef struct AVBufferSrcParameters {
* Audio only, the audio channel layout
*/
uint64_t channel_layout;
+
+ /**
+ * Video only, The color range of the video.
+ */
+ enum AVColorRange color_range;
} AVBufferSrcParameters;
/**
--
2.14.1
More information about the ffmpeg-devel
mailing list