From patchwork Wed Sep 16 20:18:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 22447 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 588DE44A571 for ; Wed, 16 Sep 2020 23:27:24 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2EDF168B9D2; Wed, 16 Sep 2020 23:27:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7EC5668B976 for ; Wed, 16 Sep 2020 23:27:17 +0300 (EEST) Received: by mail-ed1-f45.google.com with SMTP id e22so8097753edq.6 for ; Wed, 16 Sep 2020 13:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=OytFnafv3jKRF0vUOhKOJDCSlfZJZKAk+nOdntgpwvA=; b=N8b9EY+k4xzvaoHga77FP4Mr7QqJJlzDEYrd0bz7+yWYdhy+3G2ajUSO2yKvrAgoWS AltfvNR6YW4dIxIhiXpVzGvpu9pmSJ8qHEAU4ubNjNniDL09edaBYXkxz4OZYz3s7mmz 80fjzpYTKqHptETFl92Rqb5mk8ucdjVz02JcgUTxa7JsMKn3JFlm7/syEAYTp11lhLVR Tkgi/Z1teMR4OGmNNek5V8T5MpLw/lovVjwGZ7kN09mQN5sUx5XvUHe/ziXjAwexpZ91 MbeiBp7xn6eRX1Zx5F2xxW7RficmFPzyGklbqDKPSKA1h3lR2C4TNxw8CvKaqkHhEGTB 1ToQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=OytFnafv3jKRF0vUOhKOJDCSlfZJZKAk+nOdntgpwvA=; b=n7w8wseyqUDW3Pz4EsB8LJHmw6dWUmtQwe3UfTp0xuZrClLW71jmcXgTxImhv8DGAb RGbD2bScfA84EnBO9JUGiP09Fv/8J0IMEMh9peWps0m29kcgN0GPEZAkS7NBebaO7Zwk oVZd2GEnVcSJsqU37zLGj7SM9m4FM3I+/HbSYh5WlmCEhmZISecj5WNeH+alhwrbya5g ADkRK6onvFhJukUamqvdZWiGtRVmynwU+aSpUIZcZVOqv80mzPTrfV+It1eaDeyk25eU ad0Z5ivGcfjtnwSPgWhn698fFWa9HSgBBn5Q61CC8agzO/H2cMQkriMDswJb5hAjhAt1 6wag== X-Gm-Message-State: AOAM530rz9n83mXFkT4JT+xnV5LaR/ZnkOIuXM40p2u6sMD+DCdhqIWw 1wb83ZhJguNQ2pOEJk4GoRlVT0bReEY= X-Google-Smtp-Source: ABdhPJz0X8Skoh4qYaEPN8GqYEije2BJIsTGQbywMFoA/DalyvcesBjwWpwuj4vzQ5XQkanny5qExA== X-Received: by 2002:a2e:9b8f:: with SMTP id z15mr9154445lji.92.1600287530769; Wed, 16 Sep 2020 13:18:50 -0700 (PDT) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id f144sm4782998lfd.165.2020.09.16.13.18.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Sep 2020 13:18:49 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 16 Sep 2020 23:18:48 +0300 Message-Id: <20200916201848.262474-1-jeebjp@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200915211643.259961-1-jeebjp@gmail.com> References: <20200915211643.259961-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avfilter/vf_scale: translate and verify swscale internal range flag 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This value - while it looks like the actual range of the content - is nothing but the internal value of swscale. Thus, if we have RGB content, force the value to 1. Swscale will ignore it, but at least the value of the output AVFrame will now properly be "full range" instead of "limited range", as it is right now. Additionally, after calling sws_setColorspaceDetails double-check the configured internal flag for the color range. Warn if this is different to the requested value. Finally, utilize the translated configured output value into the output AVFrame's color_range. --- libavfilter/vf_scale.c | 51 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 58eee96744..592e4a344e 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -750,11 +750,30 @@ scale: || in_range != AVCOL_RANGE_UNSPECIFIED || scale->out_range != AVCOL_RANGE_UNSPECIFIED) { int in_full, out_full, brightness, contrast, saturation; + int configured_in_full_range_flag, configured_out_full_range_flag; const int *inv_table, *table; + const AVPixFmtDescriptor *in_desc = av_pix_fmt_desc_get(in->format); + const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(out->format); + if (!in_desc || !out_desc) { + av_log(ctx, AV_LOG_ERROR, + "Failed to get one or more of the pixel format descriptors " + "for formats - in: %d (%s), out: %d (%s)!\n", + in->format, in_desc ? "OK" : "bad", + out->format, out_desc ? "OK": "bad"); + av_frame_free(&in); + av_frame_free(frame_out); + return AVERROR_INVALIDDATA; + } sws_getColorspaceDetails(scale->sws, (int **)&inv_table, &in_full, (int **)&table, &out_full, &brightness, &contrast, &saturation); + // translate the swscale internal range flags to hold true + // for RGB + in_full = in_desc->flags & AV_PIX_FMT_FLAG_RGB ? + 1 : in_full; + out_full = out_desc->flags & AV_PIX_FMT_FLAG_RGB ? + 1 : out_full; if (scale->in_color_matrix) inv_table = parse_yuv_type(scale->in_color_matrix, in->colorspace); @@ -782,7 +801,37 @@ scale: table, out_full, brightness, contrast, saturation); - out->color_range = out_full ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; + // double-check what was actually just configured, + // since swscale can silently ignore the color range + // value in sws_setColorspaceDetails. + sws_getColorspaceDetails(scale->sws, (int **)&inv_table, + &configured_in_full_range_flag, + (int **)&table, + &configured_out_full_range_flag, + &brightness, &contrast, &saturation); + + // translate the actually configured internal range flags to hold true + // for RGB as well. + configured_in_full_range_flag = in_desc->flags & AV_PIX_FMT_FLAG_RGB ? + 1 : configured_in_full_range_flag; + configured_out_full_range_flag = out_desc->flags & AV_PIX_FMT_FLAG_RGB ? + 1 : configured_out_full_range_flag; + + if (in_full != configured_in_full_range_flag || + out_full != configured_out_full_range_flag) { + av_log(ctx, AV_LOG_WARNING, + "swscale overrode set input/output range value as it " + "considered it an invalid configuration! " + "(input: requested: %s, configured: %s), " + "(output: requested: %s, configured: %s)!\n", + in_full ? "full" : "limited", + configured_in_full_range_flag ? "full" : "limited", + out_full ? "full" : "limited", + configured_out_full_range_flag ? "full" : "limited"); + } + + out->color_range = configured_out_full_range_flag ? + AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; } av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,