From patchwork Thu Jul 29 05:24:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 29100 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5d:965a:0:0:0:0:0 with SMTP id d26csp5500194ios; Wed, 28 Jul 2021 22:26:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQf9fG8m8q/Q4fwN15vhvsejfTS1x/jHNx9zHd2hp9pWfShVv/4HDuex6XamMpldPH45Ia X-Received: by 2002:a05:6402:524b:: with SMTP id t11mr3882522edd.361.1627536378375; Wed, 28 Jul 2021 22:26:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627536378; cv=none; d=google.com; s=arc-20160816; b=QnYpj12Ecsu7oLtb7oq/tCZ2ZWasvHR1fOBsnHUtRG9k4SEL/PE4phTN7I0r1U+3XC EaA2zF1xb39jAIg0s8G8iWRrHwx9kHIMyDMNDd9I4Rm8F+C9Fo4Pq7TtNnLtQPAgRGmV H3XibYC5IEzXitTfKSNJv8+U0KAsWUYvjwkUVmXGd4ukacpbzQqP9dYFqibgsd1ZfZPB aYQi4M88oHycigAvAlHxt9C47oh0AxRKiaXYccHVYo6mT+DxvBZjWQ/7ptPYa6iEGeXn HcKYboFDIREFr7evf/FDj0kbKl4YXOfkVulEdEQ50VaMly7unTdhl4QLoJdL7bY/wSzm Htng== 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:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=ge7+XNQwhyWnRSfRFnA6hFAlpOPfx6lu9eR4bV9GX2I=; b=ddCA8EFtJ+pPCGQbfzQX6lv7MbUBDrLq7V83gg5RmM/bodOcgKFdDVh8OQgybUdlqH 6OsDe8xQ0WvGvIC395ohshDhIAwvhWvIGSnJYyzXR1LZ98hFg4OQP/taPePZuUP4Eil1 2IFmVt6b1QE1VT+kTCGA6JqFNLckfLAuukG8IbdYCCHrbKHTiFS0c5PrrgDJO8zwPWmn T4OVWTIwvO9fDy472Tk1kYFQF5KbZwc44mv3y0EYoNEBAxa0/TbPJ4BngM15OmttVXJA FKmFnPZTeqqDltVazTumMiX+Y0wpSXYf+P4xY8vpxCdcZxJjvAPkC7Lyam0cTH9brEuZ h1CQ== ARC-Authentication-Results: i=1; mx.google.com; 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=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id cx5si1279231edb.163.2021.07.28.22.26.18; Wed, 28 Jul 2021 22:26:18 -0700 (PDT) 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; 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=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3DF7168A2DE; Thu, 29 Jul 2021 08:26:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0298A689D05 for ; Thu, 29 Jul 2021 08:25:58 +0300 (EEST) X-IronPort-AV: E=McAfee;i="6200,9189,10059"; a="200023589" X-IronPort-AV: E=Sophos;i="5.84,278,1620716400"; d="scan'208";a="200023589" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2021 22:25:52 -0700 X-IronPort-AV: E=Sophos;i="5.84,278,1620716400"; d="scan'208";a="456730096" Received: from xhh-dg164.sh.intel.com ([10.239.159.167]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2021 22:25:51 -0700 From: Haihao Xiang To: ffmpeg-devel@ffmpeg.org Date: Thu, 29 Jul 2021 13:24:54 +0800 Message-Id: <20210729052509.30992-7-haihao.xiang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210729052509.30992-1-haihao.xiang@intel.com> References: <20210729052509.30992-1-haihao.xiang@intel.com> Subject: [FFmpeg-devel] [PATCH v4 06/21] lavfi/vpp_qsv: allow special values for the output dimensions X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Haihao Xiang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 601Fj9pXV+Vg Special values are: 0 = original width/height -1 = keep original aspect This is in preparation for re-using VPPContext for scale_qsv filter --- libavfilter/vf_vpp_qsv.c | 47 ++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c index c0fc0d4154..3505c9fd12 100644 --- a/libavfilter/vf_vpp_qsv.c +++ b/libavfilter/vf_vpp_qsv.c @@ -58,6 +58,11 @@ typedef struct VPPContext{ mfxExtVPPRotation rotation_conf; mfxExtVPPMirroring mirroring_conf; + /** + * New dimensions. Special values are: + * 0 = original width/height + * -1 = keep original aspect + */ int out_width; int out_height; /** @@ -121,10 +126,10 @@ static const AVOption options[] = { { "cx", "set the x crop area expression", OFFSET(cx), AV_OPT_TYPE_STRING, { .str = "(in_w-out_w)/2" }, 0, 0, FLAGS }, { "cy", "set the y crop area expression", OFFSET(cy), AV_OPT_TYPE_STRING, { .str = "(in_h-out_h)/2" }, 0, 0, FLAGS }, - { "w", "Output video width", OFFSET(ow), AV_OPT_TYPE_STRING, { .str="cw" }, 0, 255, .flags = FLAGS }, - { "width", "Output video width", OFFSET(ow), AV_OPT_TYPE_STRING, { .str="cw" }, 0, 255, .flags = FLAGS }, - { "h", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS }, - { "height", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS }, + { "w", "Output video width(0=input video width, -1=keep input video aspect)", OFFSET(ow), AV_OPT_TYPE_STRING, { .str="cw" }, 0, 255, .flags = FLAGS }, + { "width", "Output video width(0=input video width, -1=keep input video aspect)", OFFSET(ow), AV_OPT_TYPE_STRING, { .str="cw" }, 0, 255, .flags = FLAGS }, + { "h", "Output video height(0=input video height, -1=keep input video aspect)", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS }, + { "height", "Output video height(0=input video height, -1=keep input video aspect)", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS }, { "format", "Output pixel format", OFFSET(output_format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS }, { "async_depth", "Internal parallelization depth, the higher the value the higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, .flags = FLAGS }, @@ -266,6 +271,7 @@ static int config_input(AVFilterLink *inlink) AVFilterContext *ctx = inlink->dst; VPPContext *vpp = ctx->priv; int ret; + int64_t ow, oh; if (vpp->framerate.den == 0 || vpp->framerate.num == 0) vpp->framerate = inlink->frame_rate; @@ -279,11 +285,38 @@ static int config_input(AVFilterLink *inlink) return ret; } - if (vpp->out_height == 0 || vpp->out_width == 0) { - vpp->out_width = inlink->w; - vpp->out_height = inlink->h; + ow = vpp->out_width; + oh = vpp->out_height; + + /* sanity check params */ + if (ow < -1 || oh < -1) { + av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n"); + return AVERROR(EINVAL); } + if (ow == -1 && oh == -1) + vpp->out_width = vpp->out_height = 0; + + if (!(ow = vpp->out_width)) + ow = inlink->w; + + if (!(oh = vpp->out_height)) + oh = inlink->h; + + if (ow == -1) + ow = av_rescale(oh, inlink->w, inlink->h); + + if (oh == -1) + oh = av_rescale(ow, inlink->h, inlink->w); + + if (ow > INT_MAX || oh > INT_MAX || + (oh * inlink->w) > INT_MAX || + (ow * inlink->h) > INT_MAX) + av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n"); + + vpp->out_width = ow; + vpp->out_height = oh; + if (vpp->use_crop) { vpp->crop_x = FFMAX(vpp->crop_x, 0); vpp->crop_y = FFMAX(vpp->crop_y, 0);