From patchwork Fri Dec 8 09:46:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 6603 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp330091jah; Fri, 8 Dec 2017 01:47:16 -0800 (PST) X-Google-Smtp-Source: AGs4zMag45ZaZ9OzozKYeEJ0DbHhcaTyyuhCKSHZgBdpsbxElq1a/VrbZAv1jJOhvdPA8cL5v8us X-Received: by 10.223.184.173 with SMTP id i42mr27740849wrf.31.1512726436082; Fri, 08 Dec 2017 01:47:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512726436; cv=none; d=google.com; s=arc-20160816; b=SNZOuR2xtNOXbb8d01MrWzwXmEjcU1oClMit5F2VnA2HHFdN0s7dZW8n3BMv4hlRaq xay6uBIVzYJVY1e/a9ZImiYjwb5cE+Onz1qFuGJ2j+5IhUBc+6DgMFrQtrhk8Oogc0vJ xSulorFEXGTgI46VVT0yE1wfbg7lpaI0WwijuaDT/bZP/EdCTcZ5VMzPiZnsAmumPIDY ZK5MlpAZr/RR/CcvZEGD6NYKnlrsLQPFQL7fNfEISSoUv4nRHbeDgRsmO3wXD1GoNS+j l9YlLxLGFGmgm0ibk8J1EhCgYMfERjhb2yWz1g5HilhextMAWm0aJMtsy+S7jHcxCf+l ysDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=MzRec13SKNC48E/AXNs989pRPl1/xd+mRF7SvOCWzqQ=; b=gdyOztJzqOOjW3YbklqCaD1TjpPhxGBAGXxlPhjBFQgW7LDqYfspqMrBPpkOxNWC75 jBiSfbEvMKOp4OZUBbM07/GAbdiLtrR3o6r394bhLqFDot+iSKPIFe6c2pe702pHDBNy RtJRGAlBqden8zk5MEi8Rs8ZDKgrQDrmVB5ZNdd7dhuE+hBjqdGHw42z0yCo0w/oVH95 ahisjaScpg2UBuAhvVVvVbXt/CO8eJXTg3sfQggeVysfmIS2rRyDbIAEPAaGktKLfVT2 eNf9ZeXHRkHG1BX38LYrWTpIFge/AcmG8Pn+EQKevCDk+WMsUAC6/mGlCpuVuKy0x0ZK tkNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=iU0EAjev; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j10si866011wmi.182.2017.12.08.01.47.15; Fri, 08 Dec 2017 01:47:16 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=iU0EAjev; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 51667689C99; Fri, 8 Dec 2017 11:47:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B076D680A6C for ; Fri, 8 Dec 2017 11:47:02 +0200 (EET) Received: by mail-wm0-f66.google.com with SMTP id r78so2340948wme.5 for ; Fri, 08 Dec 2017 01:47:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=7V4PVO5SpN06rV+Y2pXRCiRPdel5qA9ycjVA6Sa9anY=; b=iU0EAjevU6bEZ6Szb4NjYLT/5JBkgjgsQE1IMiM3q/o26BYIxGJ84VU9wY174hJ3Ll BWiAS61xBja+YkCToJvaHZGKqYFp79L5ieoH1xIa6tPp2IavO7XLGPQoju0SwAqmbv7h 7byrVnsQkmHs1LWPQpFxmPrrDAOwSQ+4gXP/vrfZ/056BEB2g+qfxim54JrisS77zLNP bQhmjsdWcAYcTaAsogco0fa01pLeq13ZhgKNNKBQzynJckwXh3UfFyRrquAmhNj7kTg6 np/rEk9PHIFFdWVz6XURIeA+olzBbYX97lwI5NFrzPyhcToN5jRkyDdT/TM470NQb6X1 ifYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=7V4PVO5SpN06rV+Y2pXRCiRPdel5qA9ycjVA6Sa9anY=; b=arR+z2L9FnTjDwjskibV6geJQXiTjxAoq1D2DQ0gL3l6HA/EbFCNTV+y2C+RPSt3T1 79vceCDdwxoGqNmG95Z48qMgPrFV2E9y7vwHMiXfALOTVhNGhPgu9UcDa3Rkn+YdMupl vQ0XBOG4rxh5V3CoaMm6P9G2KC6aQXKai4QYkugTKxyK5h86FeRP/xy1bYzNbjlzetSZ Lr8+Esg/4YEVbMr8nbDm50IrG05OHPnvfdeBgQoFAroQyX42RMZ6PJdeNj2yzaqOPHgM Gh2pHxGWtPgCIgxscgIufrIESN1LCdwXNj9WbauXWWoim033B0E/gSmbNYsrT+DO38gJ ALCg== X-Gm-Message-State: AKGB3mJrbUllzt5I6SP66F3buXjWPcQ5a9gj8cwUmnnkiQqqz3yzMD7l hI3owvYaDGUVXc16/89vBdm9IA== X-Received: by 10.28.166.216 with SMTP id p207mr3120279wme.147.1512726428107; Fri, 08 Dec 2017 01:47:08 -0800 (PST) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id f132sm1162961wmf.17.2017.12.08.01.47.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Dec 2017 01:47:07 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Dec 2017 10:46:24 +0100 Message-Id: <20171208094625.5245-1-onemda@gmail.com> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH 1/2] avfilter: steps to ditch YUVJ formats X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- Now with fate passing for mjpeg. Are all these changes OK? --- fftools/ffmpeg.c | 1 + fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_filter.c | 16 +++++++++++++--- libavfilter/avfilter.c | 2 ++ libavfilter/avfilter.h | 2 ++ libavfilter/buffersink.c | 1 + libavfilter/buffersink.h | 1 + libavfilter/buffersrc.c | 13 +++++++++++++ libavfilter/buffersrc.h | 5 +++++ libavfilter/vf_scale.c | 9 +++++++++ libavfilter/video.c | 8 +++++++- 11 files changed, 56 insertions(+), 4 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 6aff3366c5..4edf3ee52f 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1864,6 +1864,7 @@ static void flush_encoders(void) ifilter->width = par->width; ifilter->height = par->height; ifilter->sample_aspect_ratio = par->sample_aspect_ratio; + ifilter->color_range = par->color_range; } } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 4e73d59082..1ad0b1eff1 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -248,6 +248,7 @@ typedef struct InputFilter { int format; int width, height; + int color_range; AVRational sample_aspect_ratio; int sample_rate; @@ -271,6 +272,7 @@ typedef struct OutputFilter { /* desired output stream properties */ int width, height; + int color_range; AVRational frame_rate; int format; int sample_rate; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 877fd670e6..d7b6c79d00 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -449,6 +449,7 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, OutputStream *ost = ofilter->ost; OutputFile *of = output_files[ost->file_index]; AVFilterContext *last_filter = out->filter_ctx; + AVDictionaryEntry *cre = NULL; int pad_idx = out->pad_idx; int ret; char name[255]; @@ -461,7 +462,9 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, if (ret < 0) return ret; - if (ofilter->width || ofilter->height) { + cre = av_dict_get(ost->encoder_opts, "color_range", NULL, 0); + + if (ofilter->width || ofilter->height || (cre && cre->value)) { char args[255]; AVFilterContext *filter; AVDictionaryEntry *e = NULL; @@ -474,6 +477,10 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value); } + if (cre && cre->value) { + av_strlcatf(args, sizeof(args), ":out_range=%s", cre->value); + } + snprintf(name, sizeof(name), "scaler_out_%d_%d", ost->file_index, ost->index); if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"), @@ -777,10 +784,11 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, av_bprint_init(&args, 0, 1); av_bprintf(&args, "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:" - "pixel_aspect=%d/%d:sws_param=flags=%d", + "pixel_aspect=%d/%d:sws_param=flags=%d:color_range=%s", ifilter->width, ifilter->height, ifilter->format, tb.num, tb.den, sar.num, sar.den, - SWS_BILINEAR + ((ist->dec_ctx->flags&AV_CODEC_FLAG_BITEXACT) ? SWS_BITEXACT:0)); + SWS_BILINEAR + ((ist->dec_ctx->flags&AV_CODEC_FLAG_BITEXACT) ? SWS_BITEXACT:0), + av_color_range_name(ist->dec_ctx->color_range)); if (fr.num && fr.den) av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den); snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index, @@ -1110,6 +1118,7 @@ int configure_filtergraph(FilterGraph *fg) ofilter->width = av_buffersink_get_w(sink); ofilter->height = av_buffersink_get_h(sink); + ofilter->color_range = av_buffersink_get_color_range(sink); ofilter->sample_rate = av_buffersink_get_sample_rate(sink); ofilter->channel_layout = av_buffersink_get_channel_layout(sink); @@ -1182,6 +1191,7 @@ int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame) ifilter->width = frame->width; ifilter->height = frame->height; ifilter->sample_aspect_ratio = frame->sample_aspect_ratio; + ifilter->color_range = frame->color_range; ifilter->sample_rate = frame->sample_rate; ifilter->channels = frame->channels; diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index b98b32bacb..4a579bb49d 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -336,6 +336,8 @@ int avfilter_config_links(AVFilterContext *filter) link->w = inlink->w; if (!link->h) link->h = inlink->h; + if (!link->color_range) + 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 47546c15e5..a5f4df74de 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -448,6 +448,8 @@ struct AVFilterLink { */ AVRational time_base; + int color_range; + /***************************************************************** * All fields below this line are not part of the public API. They * may not be used outside of libavfilter and can be changed and diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index 0f87b5439a..5f3c932d92 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(int , 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..c0acee48d6 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); +int 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..67f8bdf158 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -52,6 +52,7 @@ typedef struct BufferSourceContext { int w, h; enum AVPixelFormat pix_fmt; AVRational pixel_aspect; + int color_range; char *sws_param; AVBufferRef *hw_frames_ctx; @@ -109,6 +110,8 @@ int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *par s->h = param->height; if (param->sample_aspect_ratio.num > 0 && param->sample_aspect_ratio.den > 0) s->pixel_aspect = param->sample_aspect_ratio; + if (param->color_range > 0) + s->color_range = param->color_range; if (param->frame_rate.num > 0 && param->frame_rate.den > 0) s->frame_rate = param->frame_rate; if (param->hw_frames_ctx) { @@ -309,6 +312,15 @@ 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_INT, { .i64 = 0 }, 0, INT_MAX, V, "range" }, + { "unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, V, "range"}, + { "unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, V, "range"}, + { "limited", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, V, "range"}, + { "tv", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, V, "range"}, + { "mpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, V, "range"}, + { "full", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, V, "range"}, + { "pc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, V, "range"}, + { "jpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, V, "range"}, { NULL }, }; @@ -434,6 +446,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..1004121c4e 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, + */ + int color_range; } AVBufferSrcParameters; /** diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 2fd9c90d84..fdb94ed7eb 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -303,9 +303,15 @@ static int config_props(AVFilterLink *outlink) if (scale->in_range != AVCOL_RANGE_UNSPECIFIED) av_opt_set_int(*s, "src_range", scale->in_range == AVCOL_RANGE_JPEG, 0); + else + av_opt_set_int(*s, "src_range", + inlink->color_range == AVCOL_RANGE_JPEG, 0); if (scale->out_range != AVCOL_RANGE_UNSPECIFIED) av_opt_set_int(*s, "dst_range", scale->out_range == AVCOL_RANGE_JPEG, 0); + else + av_opt_set_int(*s, "dst_range", + outlink->color_range == AVCOL_RANGE_JPEG, 0); if (scale->opts) { AVDictionaryEntry *e = NULL; @@ -416,6 +422,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) if( in->width != link->w || in->height != link->h || in->format != link->format + || in->color_range != link->color_range || in->sample_aspect_ratio.den != link->sample_aspect_ratio.den || in->sample_aspect_ratio.num != link->sample_aspect_ratio.num) { int ret; @@ -429,6 +436,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) link->dst->inputs[0]->format = in->format; link->dst->inputs[0]->w = in->width; link->dst->inputs[0]->h = in->height; + link->dst->inputs[0]->color_range = in->color_range; link->dst->inputs[0]->sample_aspect_ratio.den = in->sample_aspect_ratio.den; link->dst->inputs[0]->sample_aspect_ratio.num = in->sample_aspect_ratio.num; @@ -578,6 +586,7 @@ static const AVOption scale_options[] = { { "in_range", "set input color range", OFFSET( in_range), AV_OPT_TYPE_INT, {.i64 = AVCOL_RANGE_UNSPECIFIED }, 0, 2, FLAGS, "range" }, { "out_range", "set output color range", OFFSET(out_range), AV_OPT_TYPE_INT, {.i64 = AVCOL_RANGE_UNSPECIFIED }, 0, 2, FLAGS, "range" }, { "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_UNSPECIFIED }, 0, 0, FLAGS, "range" }, + { "unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_UNSPECIFIED }, 0, 0, FLAGS, "range" }, { "full", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range" }, { "jpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range" }, { "mpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range" }, diff --git a/libavfilter/video.c b/libavfilter/video.c index 6f9020b9fe..8f12cb7080 100644 --- a/libavfilter/video.c +++ b/libavfilter/video.c @@ -43,6 +43,7 @@ AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h) AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h) { + AVFrame *frame = NULL; int pool_width = 0; int pool_height = 0; int pool_align = 0; @@ -86,7 +87,12 @@ AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h) } } - return ff_frame_pool_get(link->frame_pool); + frame = ff_frame_pool_get(link->frame_pool); + if (!frame) + return NULL; + frame->color_range = link->color_range; + + return frame; } AVFrame *ff_get_video_buffer(AVFilterLink *link, int w, int h)