@@ -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 "
@@ -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
@@ -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 )
@@ -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);
@@ -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);
@@ -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;
/**
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@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(-)